IP (Internet Protocol) acts as a unique identifier address over the network. This unique identifier helps to send information among different devices on the network. Internet services also work based on IP and differentiate between several devices such as routers, computers, etc. IP addresses consist of four separated integer strings, the range of each string may vary from 0 to 255 (0.0.0.0 to 255.255.255.255).

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:

Syntax:

ip [ OPTIONS ] OBJECT { COMMAND | help }

Before digging into this tutorial; execute the following command in your terminal to get the commands and arguments related to IP:

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-6.png" data-lazy- height="443" src="data:image/svg xml,” width=”829″>

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:

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-7.png" data-lazy- height="376" src="data:image/svg xml,” width=”759″>

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:

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-8.png" data-lazy- height="314" src="data:image/svg xml,” width=”758″>

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.

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-9.png" data-lazy- height="273" src="data:image/svg xml,” width=”762″>

Or:

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-10.png" data-lazy- height="196" src="data:image/svg xml,” width=”762″>

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:

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-11.png" data-lazy- height="160" src="data:image/svg xml,” width=”759″>

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:

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-12.png" data-lazy- height="118" src="data:image/svg xml,” width=”749″>

Furthermore, you can get the statistics of the link layer by using the “-s” option of the IP command as shown below:

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-13.png" data-lazy- height="298" src="data:image/svg xml,” width=”748″>

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:

$ sudo ip address add 192.168.10.1/10 dev lo

To notice the changes, you must run the command:

Or:

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-14.png" data-lazy- height="365" src="data:image/svg xml,” width=”748″>

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:

$ sudo ip addr del 192.168.10.1/10 dev lo

You must get the IP addresses after the above command to check that IP address has been removed or not:

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-15.png" data-lazy- height="318" src="data:image/svg xml,” width=”750″>

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:

$ sudo ip link set enp0s3 down

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-16.png" data-lazy- height="263" src="data:image/svg xml,” width=”747″>

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:

$ sudo ip link set enp0s3 up

<img alt="Text Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/text-description-automatically-generated-17.png" data-lazy- height="322" src="data:image/svg xml,” width=”746″>

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):

<img alt="A picture containing text, screenshot Description automatically generated" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/a-picture-containing-text-screenshot-description.png" data-lazy- height="141" src="data:image/svg xml,” width=”747″>

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.

Conclusion

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.