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.
The IP command takes the following syntax format:
$ ip [ OPTIONS ] OBJECT { COMMAND | help }
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.
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
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
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
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
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
To display the routing table of your Linux system, run the command:
$ ip r
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: