Linux IP Command Tips and Tricks

Spread the love

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:

sudo ip addr add 192.168.1.43/24 dev eth0

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:

sudo ip addr show eth0

You should see the following output:

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

sudo ip addr del 192.168.1.43/24 dev eth0

Enable and Disable Network Interface

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

sudo ip link set eth0 up

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

sudo ip link set eth0 down

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.

sudo ip route show

You should see the following output:

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:

sudo ip route add default via 192.168.1.1

Note: 192.168.1.1 is the default gateway.

You can also delete default gateway using the following command:

sudo ip route del default via 192.168.1.1

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.

sudo  ip -s link

You should see the following output:

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:

sudo ip -s -s link ls eth0

You should see the following output:

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.

sudo ip neighbour

You should see the following output:

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.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe


Hitesh Jethva

Over 5 years of experience as IT system administrator for IT company in India. My skills include a deep knowledge of Rehat/Centos, Ubuntu nginx and Apache, Mysql, Subversion, Linux, Ubuntu, web hosting, web server, squied proxy, NFS, FTP, DNS, Samba, ldap, Openvpn, Haproxy, Amazon web services, WHMCS, Openstack Cloud, Postfix Mail Server, Security etc.

Comments (2)