Linux IP Command Tips and Tricks

Linux IP Command Tips and Tricks

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.

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:

IP_addressh_show_eth0

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

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

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

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 should see the following output:

IP_show_route

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:

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.

You should see the following output:

IP_show_network

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:

You should see the following output:

IP_show_network_eth0

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.

You should see the following output:

IP_show_neighbour

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.

2 comments

  1. I found the article very useful for setting up both eth and wlan devices with a new IP addresss. However
    I do have a few question about its operation. First of all the article says that “we can assign Static IP Address”
    However for both the eth & wlan devices the new IP address is NOT static and will change in a few hours.
    Also what does the “/24” placed at the end of the IP address do.

    Thanks
    G. S. Hoffman

  2. Sorry but forgot to check off the box “Notify me of follow-up comments by email” when I submitted my question.

Comments are closed.

Sponsored Stories