The key component to network troubleshooting is making sure that everything is working smoothly and that your network is functioning properly. There are quite a few commands that you can use when troubleshooting network problem.
ping Test the connectivity between two hosts
traceroute Looks for latency in the path from host to host
netstat Shows information about connections (open, closed and listening)
route Show routing information
Let’s take a look what ping and route command can do.
You can see that your machine can connect to the other (192.168.1.40). The default gateway is already added to make sure that you can connect to the Internet smoothly.
One more example, suppose you want to check that the SSH server is listening correctly on port 22. You could use netstat to check that the connection is available for your clients:
If nothing is returned, maybe your service is down. However, the result shows that the SSH service is listening correctly (*:ssh)
From these commands above, you should be able to handle any network problem, including routing issues, network interface issues, and connectivity problems.
Sometimes you may want to see the fine details about what happen behind the scenes, you can use a packet capture utility to view all the raw data being sent across the interfaces on your machine. One of the most useful utility integrated in your machine is tcpdump.
Syntax: tcpdump [options]
Options:
-i INTERFACE Specifies which interface to listen on
-r FILE Specifies a packet capture file to read
-w FILE Defines a file to write output to instead of the console
For example, if you want to monitor eth0 and write the result into pkt_capture file, just type this command:
# tcpdump -i eth0 -w pkt_capture
Have fun!