Essential commands for Linux network administration

by Mark Rais, senior editor reallylinux.com

In this article, Mark Rais shares a list of those essential networking commands every beginning Linux administrator needs to know. Parts of this article originally appeared in the Linux+DVD Magazine, issue 1/2008.

Every Linux administrator needs a list of networking commands essential for effective server use. This article provides a summary of the most important or frequently used commands, and offers some tips for ensuring your server runs smoothly. Please keep in mind that these tips assume you already have a configured Linux hostname and IP, with a working network card and connection.

This short but quite useful command allows you to check your network card for connectivity and review your IP address and host network information. Although I tend to use other commands more frequently, arp is useful when I want to very quickly check status on my network card.

host

The host command is something I use very regularly to check either the hostname of a specific server when I have the IP address, or the IP address when I have a specific hostname. The primary function of the host command is to enable a quick lookup of DNS server information. But don't underestimate the power of this command. The host command allows you to perform many different queries using the -t option. For instance, you can use the -t with TOC to specify that you wish to lookup a host geographical location: host -t LOC hostname (replace hostname with the fully qualified domain such as reallylinux.com)

ifconfig

The ifconfig command allows you to check and configure your server's network cards, assigning IP, DNS, and Gateway addresses. For example, to assign a specific IP address for the eth0 network card, you can use:

ifconfig eth0 10.1.1.1

(replace to 10.1.1.1 with an actual IP address)

Moreover, using the plain ifconfig command shows you the details of all the existing configured network cards and network interfaces. You can get more information about it in the reallylinux.com administrative command list. Using ifconfig is a very good way to check that your network hardware is working properly.

netstat

The netstat command offers you a simple way to review each of your network connections and open sockets. I frequently use the netstat with the head command to review the top few lines of output, which are helpful when performing web server administration. For example:

netstat | head

Also, by including the -r option, you get a very good summary of all of the network routing addresses.

ping

No basic network administration is effective without the ping command. I use it for testing server configuration and checking status. The ping command basically sends test packets to a specific server and checks if there is a response. The command is very helpful when trying to determine where a connectivity error originates.

ping 10.1.1.1

(replace the 10.1.1.1 with the specific IP address of the server you wish to check)

When you run the command, please remember to press Ctrl and C to stop the process. More details are available in our administrative command list.

Ping is a useful command and should be one of your first tests when a network failure occurs. If it works but for instance HTTP connections don't, then you know that the server network connectivity is correct, so the fault may instead be with the HTTP daemon or a problem with firewall settings. You can get more information about it in the reallylinux.com administrative command list. More importantly, if even the ping command fails to work, you know that there is a more significant server connectivity issue. It is a very fast way to check servers, even remotely.

whois

This command allows you to check the Internic database for proper hostnames. This is very handy when you are trying to trace back an IP address to a specific hostname, or the reverse. I often use it when troubleshooting connectivity between hosts and checking whether the problem is a host configuration error or an actual physical connectivity error. The most commonly used version of the command is:

whois -f 10.1.1.1

(replace the 10.1.1.1 with a specific server IP)

The -f option forces the command to skip any cache that may have stored the host state, and instead goes to the actual server to perform a lookup and verify its hostname.

Another useful variation of the command, especially for trying to identify port problems is:

whois --port=8102 10.1.1.1

This command forces a test on the specific host's port 8102. You can benefit from force checking specific ports in many ways, and I highly recommend testing ports with this technique.

Essential Tools

There are many helpful tools that you should be aware when administering a Linux server. You may wish to review some of them on our reallylinux.com help webpage. Some of these tools are readily available and free to use on the Internet. Keep in mind that for each of my suggestions below, there are many other similar tools also available and you should decide what works best for your situation.

For example, as a system admin being able to geographically locate inbound IP requests is helpful. For instance, when performing server log analysis and seeing a number of specific IP requests, it may help to determine the city and country of origin. For Linux there is a helpful tool called: GeoIP. This can be installed and used from your server. There are other free tools available on the Internet, including for example: www.iplocatethis.com.

Additionally, you should be aware of tools that can help when trying to troubleshoot network connectivity. Before I begin testing my own server connections, I often check to see if the problem is instead caused by general Internet traffic latencies. Two useful tools that can be used for free are: internethealthreport.com, and the excellent alertra.com spotcheck tool. You may also find the University of Washington monitoring tool very useful for international routing issues at: http://hubble.cs.washington.edu/. Some of these organisations also offer good monitoring services if your organization needs more detailed support for a very reasonable cost. Using these tools allows you to get a more thorough understanding of overall Internet connectivity and latency.

And remember, this list is just the start. There are many additional tips and guides that may help you as you get started on our help webpage. Hopefully a few of these commands and tools will give you the power to quickly troubleshoot problems and effectively manage your Linux servers.



Linux is a registered trademark of Linus Torvalds. Microsoft, Microsoft Windows and WindowsXP are trademarks or registered trademarks of Microsoft Corporation both in the United States and Internationally. RedHat is a registered trademark of RedHat Inc., SUN and JAVA are registered trademark of Sun Microsystems, Inc. All other trademarks or registered trademarks in this opinion piece belong to their respective owners.