IP commands in Ubuntu can be used for several purposes within a network, such as to assign, delete, set up an address, or configure parameters for network interfaces. One can say that it is an alternative to the ifconfig command of Ubuntu, but it is quite useful and commonly used nowadays because the ifconfig command has not been maintained for so long and, therefore, has been deprecated. This guide will be focused on the usage of the IP command in Ubuntu:
let’s start with the syntax of the IP command:
Before digging into this tutorial; execute the following command in your terminal to get the commands and arguments related to IP:
How to check IP addresses of all network interfaces
You can check the IP addresses of the network interfaces with the help of the command given below. For this, we will use “address” OBJECT of the IP command:
You will get the same output if you use “addr” instead of “address” in the above command.
It is to notice that the IP commands can be used with various options to get the output of the specific command in the required manner.
For instance, if you want to get the IP addresses of all network interfaces in a colorful manner, you have to use the “-c” option as shown below:
How to get only IPv4 or IPv6 addresses of network interfaces
You can get only IPv4 or IPv6 addresses by using the command stated below; you will have to use the “-4” option for IPv4 and the “-6” option for IPv6.
How to get the link layer information of network interfaces
The data link layer acts at the lowest position in the TCP/IP, and it defines the methods inside a local network link on which hosts communicate. IP command can be used to fetch the link layer information of all network interfaces or one as per your requirement. You have to use the “link” keyword as shown below:
The above command has displayed the data link layer information of all network interfaces; moreover, if you want to get for a specific interface, you have to specify the name of that interface as shown below:
Furthermore, you can get the statistics of the link layer by using the “-s” option of the IP command as shown below:
How to assign an IP address to an interface using the IP command
You can use the IP command to assign a specific ip address to the network interface; the command given below will assign IP address (192.168.10.1/10) to interface “lo” (“lo” refers to the address that the computer uses to communicate with itself ): it is noticed that the following command won’t execute until sudo permissions are not granted:
To notice the changes, you must run the command:
How to remove an IP address of a network interface using the IP command
The IP command can be utilized to remove the IP address of a network interface. Let’s say we want to remove IP address “192.168.10.1/10” of interface “lo”, you have to use the “del” keyword with IP command as shown below:
You must get the IP addresses after the above command to check that IP address has been removed or not:
How to enable or disable network interface using IP command
With the help of the IP command, one can enable or disable any of the network interfaces available:
For instance, to disable “enp0s3”, use the following command:
Or to enable the “enp0s3” network interface, execute the command stated below, and you will notice that the state of “enp0s3” has been revived again:
How to monitor Network Interfaces using IP command
One of the major benefits of the IP command is to monitor the state, routes, and addresses of the devices. Execute the following command to monitor your network; it will keep on monitoring until you break the session by getting out of the command (Ctrl+c):
The “STALE” and “REACHABLE” represent the availability of Network Interfaces; both are valid, but the “STALE” state is unreachable. However, “PROBE” lies in between reachable and unreachable states; the “PROBE” indicates that the interface would soon be reachable.
The IP command in Ubuntu is a well-known command for network handling. Starting from the introduction of IP to the detailed use of this command in Ubuntu, it can be used to perform several network-related tasks such as monitoring the network devices, adding/removing the IP address of interfaces. Earlier, the ifconfig command was being used, but due to lack of maintenance, it has been deprecated, and therefore it is replaced by an IP command. I hope this article would be beneficial for you, and if you want a more detailed guide about commands related to networking, you must visit linuxhint.