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:

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:

IP_addressh_show_eth0

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

sudo ip addr del 192.168.1.43/24 dev eth0

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

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:

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:

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

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:

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:

sudo ip -s -s link ls eth0

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.

sudo ip 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.

Leave a Reply

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.