- Mastering Linux Network Administration
- Jay LaCroix
- 696字
- 2021-07-09 20:56:29
Understanding the net-tools and iproute2 suites
For quite some time, net-tools has been the suite of tools used to manage network connections on Linux systems. The net-tools suite includes commands such as ifconfig
, route
, netstat
, and others (which we'll discuss shortly). The problem with net-tools is that it hasn't been updated by its developers in well over a decade, making many distributions opt to abandon it in favor of the iproute2 suite, which offers the same functionality (but with different commands to achieve the same goals). Even though net-tools are being deprecated, quite a few distributions still include it. For example, Debian includes both iproute2 and net-tools, so you can use commands from either suite. In CentOS, iproute2 is present though net-tools is not installed by default. If you would like to utilize the older net-tools, you can install it in CentOS with the following command:
# yum install net-tools
So, why would you want to install net-tools
if it's being abandoned? Many systems still have scripts that use commands from the net-tools suite, so it's not something that will disappear from the Linux community any time soon. Learning net-tools, as well as the newer iproute2, will enable you to easily adapt to any environment. This is especially the case for older data centers that are using older distributions.
Let's see these suites in action. First, to report basic information about your network connections, type the following:
/sbin/ifconfig
You should see the following output:
Here, we can see statistics from both the internal wired connection (eth0
) as well as the loopback adapter (lo
). We see HWaddr
, which is the MAC address of the network card. We also have inet addr
, which is the IP address that the card was provided by the DHCP server. In addition, we can see the subnet mask, Mask
, which is 255.255.252.0
in this case. While troubleshooting networking issues, we would use this tool to check these basic things, such as ensuring we have an IP address and we are on the appropriate subnet. In addition, we can also see the number of packets sent and received on the interface, as well as the number of errors.
With the iproute2 suite, we can find most of the same information with the following command:
ip addr show
Here's the output from a reference machine:
As you can see, the information reported is mostly the same, though the layout is a bit different. For example, one difference is that you don't see the number of packets sent and received, nor an error count (by default). In the past, the following command would show the IP addresses in use as well as sent and received packets:
ip -s addr show
Unfortunately, recent versions of the iproute2 suite don't seem to show this information anymore (despite adding the -s
switch), but we'll look at additional tools later on in this book.
The iproute2 suite features many more commands than just these, and we'll discuss them as the book continues. For now, it's important to understand the difference between the two command suites and to note that net-tools won't be available forever. In the time period in which this book was written, both are common. However, iproute2 is the name of the game going forward.
Before closing out this section, there's a really easy command in the iproute2 suite that might prove useful:
hostname
This simple command just prints the hostname of the machine on which your shell is attached. If you're using your default bash prompt, chances are you are already aware of your machine's hostname. However, the hostname command can at least help you verify that your device is reporting the hostname you think it should be; this can be useful when you're dealing with name resolution issues.