Linux ip address Command Usages and Examples

The ip command is a versatile tool for displaying, monitoring, and managing interfaces, connections, routing, and traffic. It can be used to manage and monitor many aspects of networking.

For the RHCSA/RHCE exam, you need to know how to use this command to perform the following tasks.

  • To view the IP configuration of an interface or all interfaces
  • To check routing information
  • To check the link state of all interfaces or a specific interface
  • To assign the temporary IP configuration to an interface
  • To temporarily change the link state of an interface

Viewing configurations

Use the following commands to view configurations of all interfaces or a specific interface.

ip addr show
ip addr show [interface]

This first command displays the current configuration of all interfaces. The second command displays the current configuration of the specified interface. For example, the following command displays the configuration of the ens160 interface.

ip addr show ens160

The following image shows the output of the above commands.

The ip address show command

The first line shows the interface's link state. The state UP shows the interface is up and operational, while the state Down shows it is down. When troubleshooting a connectivity-related issue, checking the interface's link state should be your first step. An interface can connect to the network only if its link state is UP.

The second line shows the MAC address of the interface. The following lines show the IPv4 and IPv6 configurations.

Viewing routing information

To view the IP address of the default gateway router, you can use the following command.

ip route show

This command displays the default gateway IP address. The default gateway connects the host to the remote network.

The following image shows the output of this command.

The ip route show command

Viewing the link state information

Use the following command to view only the link state information of all interfaces.

ip link state

Specify the name of a particular interface to view its link state information. For example, the following command shows the link state information of interface ens160.

ip link state ens160

The following image shows the output of the above commands.

The ip link show command

Changing the link state information

The following command sets the link state of an interface to up.

ip link set dev [interface name] up

The following command sets the link state of an interface to down.

ip link set dev [interface name] down

The following image shows how to use the above commands to change the link state of the ens160 interface.

Changing link state information

Adding a temporary IP address

Use the following command to set a temporary IP address on the interface.

ip addr add [ip_address/subnet_mask] dev [interface_name]

The above command sets the new IP address in addition to the current IP address. It does not remove or replace the current IP address. The following command sets the IP address 10.0.0.1/8 to the ens160 interface.

ip addr 10.0.0.1/8 dev ens160

The following image shows the output of the above command.

Assigning IP address by using the ip command

Conclusion

The ip command makes changes only in the running configuration. It does not save the changes. When you reboot the system or log out from the current session, all changes the ip command makes will be lost. The ip command supports command line abbreviation. You do not need to type the complete option. For example, you can abbreviate the ip addr show command as ip a s.

ComputerNetworkingNotes Linux Tutorials Linux ip address Command Usages and Examples

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com