×


Linux IP Command with Examples - An overview ?

The IP command is a Linux networking command that provides information about network interfaces and also performs network configuration. For instance, you can manually assign an IP address, view all network interfaces, manage the routing table, enable or disable a network interface, and so on.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux Commands queries.

In this context, we shall look into different use cases of the Linux IP command using some practical examples.



IP Command Syntax

The IP command takes the following syntax format:

$ ip [ OPTIONS ] OBJECT { COMMAND | help }


How to display information about network interfaces with the IP command ?

The IP command can be used to display the system's network interface. You can use the command below to display information about all the system's network interfaces including the IP address, mac address, link status ( whether up or down ), and MTU ( Maximum Transmission Unit ):

$ ip addr

OR

$ ip a

Note that the ip command provide detailed information about the attached network interface.


How to display IPv4 and IPv6 addresses only using the IP command ?

You can choose to list either IPv4 or IPv6 addresses as shown. To display all the IPv4 addresses of network interfaces, execute the command:

$ ip -4 a

To list IPv6 addresses of all the interfaces, execute:

$ ip -6 a


How to display information about a specific network interface using the IP command ?

To display information about an interface, use the syntax:

$ ip a show dev interface_name

For instance, to gather information on the enp0s3 interface only, run the command:

$ ip a show dev enp0s3

OR

$ ip a list enp0s3


How to Assign an IP address to an interface using the IP command ?

You can assign an IP address to an interface. To implement this, use the command syntax:

$ ip a add {ip_addr/mask} dev {interface}

For example, to assign the enp0s3 interface an IP of 192.168.2.120 with 255.255.255.0 subnet mask, execute the command:

$ sudo ip a add 192.168.2.120/255.255.255.0 dev enp0s3

Or you can use the /24 CIDR notation for the subnet mask as follows

$ sudo ip a add 192.168.2.120/24 dev enp0s3


How to delete an IP address from a network interface using the IP command ?

To delete the IP address assigned to the interface, run the command:

$ sudo ip a del 192.168.2.120/255.255.255.0 dev enp0s3

You can then verify the changes as follows:

$ ip a show dev enp0s3


How to Bring an interface UP or DOWN using the IP command ?

To modify the state of a network interface, by enabling or disabling it, run the command syntax:

$ sudo ip link set dev DEVICE_NAME {up|down}

To bring down the enp0s3 interface, run:

$ sudo ip link set dev enp0s3 down

To bring it up, execute:

$ sudo ip link set dev enp0s3 up


How to Display Routing table using the IP command ?

To display the routing table of your Linux system, run the command:

$ ip r


[Need help in Installing Open Source Software on Debian Linux System ? We can help you. ]


Conclusion

This article covers the practical use cases of the Linux IP command. IP stands for Internet Protocol. IP command is used to show or manipulate routing, devices, and tunnels. It is similar to ifconfig command but it is much more powerful with more functions and facilities attached to it. It can perform several other tasks like configuring and modifying the default and static routing, setting up tunnel over IP, listing IP addresses and property information, modifying the status of the interface, assigning, deleting and setting up IP addresses and routes.


Linux system commands:

  • arp — Manipulate the system ARP cache.
  • ifconfig — View or modify the configuration of network interfaces.
  • netstat — Print information about network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
  • route — Display and manipulate the IP routing table.
  • tcpdump — Capture raw network traffic.