Andrea Danti - Fotolia

Tip

Six helpful Linux networking commands to monitor connectivity

There are plenty of useful Linux tools to help in the event of a network connection failure. Here are six of the top commands to stay ahead when trouble occurs.

Nearly all Linux instances need network connections to offer their services. If the network connection fails, the services will fail, and users will face disrupted continuity. For this reason, the administrator must have the appropriate tools and commands to analyze and troubleshoot network connectivity.

Here are six helpful Linux networking commands to ensure continuity.

1. ip

The Swiss Army knife of Linux networking commands, ip, is designed to work with subcommands, such as ip link, to manage and monitor the network link, ip addr to manage IP addresses and ip route to manage the routing table. You can use ip link show, ip addr show or ip route show to see the current link state, and address configuration, such as router configuration. To go beyond that, use ip addr add dev eth0 10.0.0.10/24 to temporarily assign an IP address to the eth0 network interface.

The ip command offers more advanced options, as well. For example, ip link set promisc on temporarily sets a network interface to promiscuous mode, allowing it to capture all packets sent on the network -- not just packets addressed to its own media access control address. The ip command and its subcommands work well for troubleshooting connection issues, but everything done with this command will disappear after rebooting your machine.

2. tcpdump

Tcpdump is a Linux networking command that allows data center administrators to analyze network activity. This packet sniffing command captures traffic that goes through a specific network interface. If you run it without any arguments, such as in tcpdump -i eth0, the command will reveal large amounts of packets passing by. Another common option is to use -w, as in tcpdump -i eth0 -w packets.pcap, which writes the result to a file that admins can analyze later using the Wireshark utility.

3. Wireshark

Wireshark is a graphical tool that admins can use to analyze and sniff network packets. While tcpdump dumps network traffic on the stdout, admins can use Wireshark to click through network communication streams within a convenient graphical interface. This versatile tool can perform a live packet capture, but also can read in a capture file that was created with another tool, such as tcpdump.

4. ethtool

If you're working with traditional physical network cards instead of interfaces in a virtual machine, you'll like ethtool. This tool allows admins to monitor and set different properties of the network card. For example, use ethtool -i eth0 to find hardware-related information about your eth0 interface, or ethtool -S eth0 to get usage statistics on packets received and sent through that interface. The command ethtool -p eth0 will cause the LED on the back of the network card to blink, which is a useful notification to swap cables on eth3, for example. But before doing so, verify that you're working on eth3 instead of another network interface.

While using ethtool, keep in mind that you might not always receive useful information, since the driver determines what you see.

5. ncat

Traditionally, administrators used Telnet to make a connection to a specific port, verifying the availability of a service on that specific port. Ncat -- known previously as netcat -- is the modern replacement of that archaic utility.

Admins, for example, can use ncat somehost 80 to establish a connection on port 80 to a host named somehost, but ncat has more advanced capabilities, as well, such as establishing a connection between two hosts. Use ncat -l 4444 to have ncat listen on one host, and use ncat hostname 4444 to make a connection to that port from another host. By itself, that isn't very useful, but using that connection in a pipe creates more options. For example, use ncat -l 4444 > somefile on one host and echo hello | ncat hostname 4444 on the other host, which will send the output of the command over the network to write it in a file on the other host.

6. dhclient

If you use a Dynamic Host Configuration Protocol server to hand out IP addresses on your network, then every node should be able to connect after starting up. However, if the DHCP server was not available while your client was booting, you'll receive a useless address in the 169.254 range, and it won't automatically try to get a new IP address. To avoid this problem, use dhclient to immediately request a new IP address. For example, a Linux networking command like dhclient eth0 will immediately renew the IP address of the primary Ethernet device.

Some Linux networking commands have changed drastically, but some, such as ifconfig, have not. The tool has become obsolete and no longer shows relevant information. To troubleshoot network connectivity issues, instead consider the six commands above.

Next Steps

Use cURL and Wget to download network files from CLI

How to interact with network APIs using cURL, Postman tools

5 basic network commands for Linux and Windows

Dig Deeper on Data center ops, monitoring and management

SearchWindowsServer
Cloud Computing
Storage
Sustainability
and ESG
Close