Linux ip address Command Usages and Examples

The ip command is a versatile tool for displaying, monitoring, and managing interfaces, connections, routing, and traffic. You can use it 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

To view configurations of all interfaces or a specific interface, use the following commands.

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.

ip address show command

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

The second line shows the MAC address of the interface. The next 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.

ip route show command

Viewing the link state information

To view only the link state information of all interfaces, use the following command.

ip link state

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

ip link state ens160

The following image shows the output of the above commands.

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

To set a temporary IP address on the interface, use the following command.

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.

assinging ip address by using <b>ip command</b>

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 made by the ip command will be lost. The ip command supports command line abbreviation. You don’t 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