What are my servers doing? ping, mtr and nmap

If you’re a network administrator or web developer of any kind, you are often going to want to know what your machines are doing.  Is your database machine connected to the network?  Is your firewall working?  Is your web server properly configured?

ping is the very first tool that we reach for.

  ping simply sends a message to another machine to see if it is responding.

$ ping google.com

When you run this, you should start seeing responses from google.com getting printed out at your command line. If you don’t get this, then your network connection is probably down. This can also be used to see if machines that you own are up and running.

$ ping mywebserver

If ping doesn’t work, and you’re sure that you are connected to the network, the next thing to do is to make sure that you have the right machine name and that your client machine can look up its IP address correctly. That’s where dig comes in.

$ dig mycoolsite.ca 

Check that this gives you the right IP address. Be aware that some DNS providers such as OpenDNS may give you back an IP address even for sites that don’t exist, but it won’t be anything useful.

mtr is like ping on steroids – it will show you all the hops that your network packets are taking between you and your target machine, and how responsive each intermediate machine is being. This is a very handy tool for analysing connectivity problems.

My server is up, but what is it doing?

nmap is a vital tool in every network administrators toolkit. It deserves an article all to itself, but here’s a quick taste:

trevor@vm2:~$ nmap localhost 

Starting Nmap 6.40 ( http://nmap.org ) at 2013-11-28 18:00 PST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000094s latency).
Not shown: 997 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
5432/tcp open  postgresql

Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds

This tells me that machine vm2 is running ssh, a webserver, and the postgresql database engine. If this machine was visible to the outside world, now would be the time when I would make sure that postgresql wasn’t accepting non-local connections.

As with all these tools, nmap can be installed via

$ sudo apt-get install nmap

Find out how to install packages, keep an eye on your Linux system and other useful tips in my technology toolkit posts: