Linux is everywhere and nearly all Linux distros need network connections to offer their services. Network connection failures is one of the major headaches if you are using a Linux based PC or a system. Because if your network fails, all other services will fail and you will be left with a dud system. For this reason, the administrator must have the appropriate tools and commands to analyze and troubleshoot network connectivity. Here are five most helpful Linux networking commands to ensure continuity.
1. ip
ip is known as the Swiss Army knife of Linux networking commands because of its ability to work with subcommands. It is designed to work with ip link, to manage and monitor the network link, ip addr to manage IP addresses and ip route to manage the routing table. As a Linux professional 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.
- ip2. tcpdump3. Wireshark4. ethtool5. ncat
For more advanced users, ip has advanced options setting as well. You can use 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 ipcommand 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 another very popular Linux networking command 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
Most of Linux users know Wireshark utility, which is also popular with hackers and security researchers. Wireshark is a graphical tool allows you 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
ethtool is for advanced Linux users. If you’re working with traditional physical network cards instead of interfaces in a virtual machine, you’ll like ethtool. This tool allows Linux users 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, orethtool -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. Remember, ethtool is dependent on drivers which you use so you may not always receive useful information.
5. ncat
In olden days, Linux users used Telnet to make connection to a specific port in various distros. Ncat or netcat is a replacement for this old telnet 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 andecho 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. If you use anyone of the the above utilities, you can troubleshoot your networking problems with ease. If you use a different utility to monitor your network traffic, kindly mention the same in comments for other readers.