Comparison of Linux TCP/IP Network Tools: net-tools vs iproute2

(Click the public account above, to quickly follow)

Original: Dan Nanni

Translation: KayGuoWhu

Link: https://linux.cn/article-4326-1.html

Nowadays, many system administrators still configure network functions and troubleshoot network issues using command-line tools such as ifconfig, route, arp, and netstat (collectively known as net-tools). Net-tools originated from the BSD TCP/IP toolbox and later became the tool for configuring network functions in older versions of the Linux kernel. However, since 2001, the Linux community has stopped maintaining it. Some Linux distributions, such as Arch Linux and CentOS/RHEL 7, have completely abandoned net-tools and only support iproute2.

As part of the network configuration tools, the emergence of iproute2 aims to functionally replace net-tools. Net-tools accesses and modifies kernel network configurations through procfs (/proc) and ioctl system calls, while iproute2 communicates with the kernel via the netlink socket interface. Apart from performance, the user interface of iproute2 is more intuitive than that of net-tools. For example, various network resources (such as link, IP addresses, routes, and tunnels) are defined using appropriate object abstractions, allowing users to manage different objects with consistent syntax. More importantly, iproute2 is still under continuous development.

If you are still using net-tools and especially need to keep up with the latest and most important network features in the new Linux kernel, then it’s time to switch to the iproute2 camp. The reason is that using iproute2 can accomplish many tasks that net-tools cannot.

For those who want to switch to iproute2, it is necessary to understand the many comparisons between net-tools and iproute2 below.

Comparison of Linux TCP/IP Network Tools: net-tools vs iproute2

Show All Connected Network Interfaces

The following command displays a list of all available network interfaces (regardless of whether the interface is active).

Using net-tools:

$ ifconfig -a

Using iproute2:

$ ip link show

Comparison of Linux TCP/IP Network Tools: net-tools vs iproute2

Activate or Deactivate Network Interfaces

Use these commands to activate or deactivate a specified network interface.

Using net-tools:

$ sudo ifconfig eth1 up

$ sudo ifconfig eth1 down

Using iproute2:

$ sudo ip link set down eth1

$ sudo ip link set up eth1

Assign IPv4 Address to Network Interface

Use these commands to configure the IPv4 address of the network interface.

Using net-tools:

$ sudo ifconfig eth1 10.0.0.1/24

Using iproute2:

$ sudo ip addr add 10.0.0.1/24 dev eth1

It is worth noting that iproute2 allows multiple IP addresses to be assigned to the same interface, while ifconfig does not. A workaround for ifconfig is to use IP aliases.

$ sudo ip addr add 10.0.0.1/24 broadcast 10.0.0.255 dev eth1

$ sudo ip addr add 10.0.0.2/24 broadcast 10.0.0.255 dev eth1

$ sudo ip addr add 10.0.0.3/24 broadcast 10.0.0.255 dev eth1

Remove IPv4 Address from Network Interface

Regarding the removal of IP addresses, net-tools does not provide any suitable method to remove the IPv4 address of a network interface, except for assigning a full 0 address. In contrast, iproute2 can handle it completely.

Using net-tools:

$ sudo ifconfig eth1 0

Using iproute2:

$ sudo ip addr del 10.0.0.1/24 dev eth1

Show IPv4 Address of Network Interface

The following steps can be used to view the IPv4 address of a specified network interface.

Using net-tools:

$ ifconfig eth1

Using iproute2:

$ ip addr show dev eth1

Similarly, if multiple IP addresses are assigned to the interface, iproute2 will display all addresses, while net-tools can only show one IP address.

Comparison of Linux TCP/IP Network Tools: net-tools vs iproute2

Assign IPv6 Address to Network Interface

Use these commands to add IPv6 addresses to the network interface. Both net-tools and iproute2 allow users to add multiple IPv6 addresses to an interface.

Using net-tools:

$ sudo ifconfig eth1 inet6 add 2002:0db5:0:f102::1/64

$ sudo ifconfig eth1 inet6 add 2003:0db5:0:f102::1/64

Using iproute2:

$ sudo ip -6 addr add 2002:0db5:0:f102::1/64 dev eth1

$ sudo ip -6 addr add 2003:0db5:0:f102::1/64 dev eth1

Show IPv6 Address of Network Interface

The following steps can be used to display the IPv6 address of a specified network interface. Both net-tools and iproute2 can display all assigned IPv6 addresses.

Using net-tools:

$ ifconfig eth1

Using iproute2:

$ ip -6 addr show dev eth1

Comparison of Linux TCP/IP Network Tools: net-tools vs iproute2

Remove Unnecessary IPv6 Addresses from Interface

Use these commands to remove unnecessary IPv6 addresses from the interface.

Using net-tools:

$ sudo ifconfig eth1 inet6 del 2002:0db5:0:f102::1/64

Using iproute2:

$ sudo ip -6 addr del 2002:0db5:0:f102::1/64 dev eth1

Change MAC Address of Network Interface

Use the following command to change the MAC address of the network interface. Note that you need to deactivate the interface before changing the MAC address.

Using net-tools:

$ sudo ifconfig eth1 hw ether 08:00:27:75:2a:66

Using iproute2:

$ sudo ip link set dev eth1 address 08:00:27:75:2a:67

View IP Routing Table

In net-tools, there are two options to display the kernel’s IP routing table: route and netstat. In iproute2, use the command ip route.

Using net-tools:

$ route -n

$ netstat -rn

Using iproute2:

$ ip route show

Comparison of Linux TCP/IP Network Tools: net-tools vs iproute2

Add and Modify Default Route

The following commands are used to add or modify the default routing rules in the kernel’s IP routing table. Note that in net-tools, you can modify the default route by adding a new default route or deleting an old default route. In iproute2, use the ip route command instead.

Using net-tools:

$ sudo route add default gw 192.168.1.2 eth0

$ sudo route del default gw 192.168.1.1 eth0

Using iproute2:

$ sudo ip route add default via 192.168.1.2 dev eth0

$ sudo ip route replace default via 192.168.1.2 dev eth0

Add and Remove Static Routes

Use the following commands to add or remove a static route.

Using net-tools:

$ sudo route add -net 172.16.32.0/24 gw 192.168.1.1 dev eth0

$ sudo route del -net 172.16.32.0/24

Using iproute2:

$ sudo ip route add 172.16.32.0/24 via 192.168.1.1 dev eth0

$ sudo ip route del 172.16.32.0/24

View Socket Statistics

The following commands are used to view socket statistics (such as active or listening TCP/UDP sockets).

Using net-tools:

$ netstat

$ netstat -l

Using iproute2:

$ ss

$ ss -l

Comparison of Linux TCP/IP Network Tools: net-tools vs iproute2

View ARP Table

Use these commands to display the kernel’s ARP table.

Using net-tools:

$ arp -an

Using iproute2:

$ ip neigh

Add or Delete Static ARP Entries

Use the following commands to add or delete a static ARP entry in the local ARP table.

Using net-tools:

$ sudo arp -s 192.168.1.100 00:0c:29:c0:5a:ef

$ sudo arp -d 192.168.1.100

Using iproute2:

$ sudo ip neigh add 192.168.1.100 lladdr 00:0c:29:c0:5a:ef dev eth0

$ sudo ip neigh del 192.168.1.100 dev eth0

Add, Delete or View Multicast Addresses

Use the following commands to configure or view multicast addresses on the network interface.

Using net-tools:

$ sudo ipmaddr add 33:44:00:00:00:01 dev eth0

$ sudo ipmaddr del 33:44:00:00:00:01 dev eth0

$ ipmaddr show dev eth0

$ netstat -g

Using iproute2:

$ sudo ip maddr add 33:44:00:00:00:01 dev eth0

$ sudo ip maddr del 33:44:00:00:00:01 dev eth0

$ ip maddr list dev eth0

Comparison of Linux TCP/IP Network Tools: net-tools vs iproute2

Comparison of Linux TCP/IP Network Tools: net-tools vs iproute2

Leave a Comment