howtouselinux

3 useful Linux commands you need to know about networking

Table of Contents

IP command is one of the most important and frequently used commands in Linux. In this blog post, we will discuss what IP command is, and how to use it effectively.

IP command is used to display or manipulate the network interface parameters. It can be used to view network information about your network interfaces, configure them, and more.

Useful IP Commands in Linux

Here are some useful IP commands:

  • ip addr: This command will display/add/delete IP addresses in Linux
  • ip link: This command will display/add/delete network interfaces in Linux.
  • ip route: This command will display/add/delete routes in Linux.

 

Let’s take a look at these IP commands.

Check network interface info with ip link show command in Linux

The IP link show command can be used to display information about your network interfaces. This command will display all of the network interfaces on your systems. The command output will include the MAC address, MTU size, status, etc.

Here is an example of the output of this command:

For example:

root@localhost:~# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 08:00:27:a4:4c:fc brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
link/ether 44:94:fc:82:ec:6e brd ff:ff:ff:ff:ff:ff

As you can see from the output above, there are three interfaces on this system: lo, eth0, and wlan0.

  • The lo interface is the loopback interface, which is used for local communication on the system.
  • The eth0 interface is the Ethernet interface, which is used to connect to a network.
  • The wlan0 interface is the wireless interface, which is used to connect to a wireless network.

 

You can use the ip link show command to view information about any of these interfaces.

To view information about a specific interface, you can use the following syntax:

ip link show dev <interface name>

For example, to view information about the eth0 interface, you would use the following command:

root@localhost:~# ip link show dev eth0

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 08:00:27:a4:4c:fc br

Configure network interface with ip link set command in Linux

To configure your network interfaces in Linux, you can use the ip link set command. This command is used to set various parameters of a network interface. For example, you can use this command to enable or disable a network interface.

The main reason to disable a network interface is to prevent it from being used. This can be useful in a number of situations. For example, if you are troubleshooting your network issue, you may want to disable an interface to see if that fixes the problem.

Or, if you are connected to a network that you don’t want to use, you may want to disable the interface to prevent your computer from using it.

To disable a network interface, you can use the following command:

ip link set eth0 down

This command will disable the eth0 interface. If you want to enable the interface, you can use the following command:

ip link set eth0 up

You can also use the ip link set command to change the MAC address of a network interface. To do this, you can use the following command:

ip link set eth0 address 00:11:22:33:44:55

Check IP address with ip addr show command in Linux

The ip addr show command can be used to display IP information about your network addresses. This command will display all of the IP addresses on your system. Here is an example of the output of this command:

For example:

root@localhost:~# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:a4:4c:fc brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fea4:4cfc/64 scope link
valid_lft forever preferred_lft forever

3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 44:94:fc:82:ec:6e brd ff:ff:ff:ff:ff:ff

As you can see from the output above, there are three interfaces on this system: lo, eth0, and wlan0.

Change IP Address with IP addr add/del Command in Linux

The ip addr add command is used to add an IP address to a network interface. For example, if you want to add the IP address 10.0.0.1/24 to the eth0 interface, you can use the following command:

ip addr add 10.0.0.1/24 dev eth0

The ip addr del command is used to delete an IP address from a network interface. For example, if you want to delete the IP address 10.0.0.1/24 from the eth0 interface, you can use the following command:

ip addr del 10.0.0.1/24 dev eth0

The ip addr flush command is used to flush the IP addresses from a network interface. This command will delete all of the IP addresses from a network interface. For example, if you want to flush the IP addresses from the eth0 interface, you can use the following command:

ip addr flush dev eth0

Check route table with ip route show command in Linux

The ip route show command is used to display the routing table in Linux. The routing table is a list of networks and their associated next-hop router. Here is an example of the output of this command:

For example:

root@localhost:/home/user# ip route show
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15
169.254.0.0/16 dev eth0 scope link metric 1000
default via 10.0.2.2 dev eth0 proto static

As you can see from the output above, there are three routes in the routing table.

  • The first route is for the 10.0.2.0/24 network. This route says that the next-hop router for this network is 10.0.2.2 and that it can be reached via the eth0 interface.
  • The second route is for the 169.254.0.0/16 network. This route says that this network can be reached via the eth0 interface.
  • The third route is the default route. This route says that the next-hop router for all other networks is 10.0.2.2 and that it can be reached via the eth0 interface.

 

Change Route table With IP route add/del Command in Linux

The ip route add command is used to add a route to the routing table. For example, if you want to add a route for the 10.0.3.0/24 network, you can use the following command:

ip route add 10.0.3.0/24 via 10.0.2.3 dev eth0

The ip route del command is used to delete a route from the routing table. For example, if you want to delete the route for the 10.0.3.0/24 network, you can use the following command:

ip route del 10.0.3.0/24 via 10.0.2.3 dev eth0

Conclusion

In this article, we have covered the IP command in Linux. We have explained what the IP command is and how it can be used to configure network interfaces and routes. We have also provided a list of some useful IP commands.

David Cao
David Cao

Hey there! I am David, a Cloud & DevOps Enthusiast and 18 years of experience as a Linux engineer. I work with AWS, Git & GitHub, Linux, Python, Ansible, and Bash. I am a technical blogger and a Software Engineer, enjoy sharing my learning and contributing to open-source.