The Linux IP command is very similar to ifconfig, but it is more powerful. You can perform several network administration tasks using the IP command. Also, ifconfig is one of the deprecated commands that has not been maintained for many years even though it is still available on most Linux distributions. The IP command line utility comes with the iproute2 suite utility, and most Linux distributions will come with the iproute2 tools pre-installed.

In this post we review how we can assign Static IP Address, Static Route, Default Gateway and Assigning IP Address on demand using IP command.

Set Up and Delete an IP Address

You can set an IP address for interface eth0 using the following command:

After you have set the IP address, you can confirm whether the changes have taken effect and get the depth information of your network interfaces like IP Address and MAC Address information using the following command:

You should see the following output:

You can delete an IP address by just replacing add with del flag.

Enable and Disable Network Interface

You can enable the network interface eth0 with the following command:

To disable the network interface eth0, run the following command:

Show Routing Table

You can use the route object of the IP command to see the route packets will take in your network as set in your routing table. Run the following command to check the routing table information of the system.

You can also add a default gateway to your system. Default gateway is used when you have more than one NIC (Network Interface Controller) in the system.

You can do this by running the following command:

Note: 192.168.1.1 is the default gateway.

You can also delete default gateway using the following command:

Show Network Statistics

The IP command can also be used to show the statistics of the various network interfaces. To do this you can use the -s flag.

If you need to get information about a particular network interface, add the option ls followed by the name of the network interface (eth0). This can be very useful, especially when troubleshooting errors in network connectivity.

To do this, run the following command:

ARP Entries

ARP, also known as Address Resolution Protocol, is used to translate an IP address to its corresponding physical address, commonly known as MAC address. Using the IP command you can view the MAC address of the devices connected in your LAN by using the option neighbour.

Conclusion

The IP command is a very useful tool for every network administrator and all Linux users. It is even more useful when you are writing scripts. Let us know if this article is useful for you.

Our latest tutorials delivered straight to your inbox