Linux is one of the most widely used operating systems out there. The Linux Kernel is also the larges open source project. As a developer, it is more likely than not that you would have to work in one way or another with a Linux based system.
As a person who works in any IT related job, the following Linux networking commands could help you with your day to day tasks in order to analyze, maintain and troubleshoot different problems with your servers, network infrastructure, and even your domain names.
Top 15 Linux Networking tools
Here is a list of my personal top 15 Linux networking tools with examples!
ping command, might be one of the most frequently used commands by sysadmins, it uses ICMP packages to check if two machines are connected.
You could also
ping a domain name in order to find out what IP it resolves to:
traceroute command shows you the path from your current machine to your remote server/system and each hope along the way.
The output of the above command would look like this:
1 126.96.36.199 (188.8.131.52) 1.081 ms 1.064 ms 1.056 ms 2 184.108.40.206 (220.127.116.11) 1.382 ms 18.104.22.168 (22.214.171.124) 11.573 ms 126.96.36.199 (188.8.131.52) 1.054 ms 3 184.108.40.206 (220.127.116.11) 0.981 ms 18.104.22.168 (22.214.171.124) 0.995 ms 0.980 ms 4 de-cix-frankfurt.as13335.net (126.96.36.199) 2.513 ms 2.509 ms 2.501 ms 5 188.8.131.52 (184.108.40.206) 1.331 ms 1.369 ms 1.359 ms
Essentially it is similar to
ping but it shows you each step from your server to your remote host.
traceroute you will be able to tell if the connection from one machine to another is failing and where exactly the connection is lost.
mtr command, is kind of a combination between
ping, it is used to check if there is any packet lost in your network.
curl command is probably my personal favorite! You can use it to make HTTP requests.
There are many useful arguments that you could use, for example, if you add the
-IL arguments you would get the headers of your domain:
curl -IL https://devdojo.com
You can also use
curl to download files:
curl http://some.url/your_file.zip --output your_file.zip
wget command is quite similar to
curl but has fewer options
I often use it to just download a file:
dig command is a great tool for troubleshooting different DNS problems. It is used for DNS lookups, for example, if you wanted to know the A record fo your domain name you would have to run the following command:
dig a yourdomain.com
And in case you are not receiving emails, the first thing that you would check is if your MX record is correct:
dig mx yourdomain.com
whois command is used to get the information related to a domain name.
As a response, you would get useful information like when the domain was registered, the expiration date, the current nameservers, and the registrar information.
SSH stands for secure shell and runs on port 22. It is a secure way of connecting to a remote server.
In case that your SSH service is listening on a different port, you can use the
-P argument to specify a custom port.
scp and rsync
rsync commands as one, as they have quite similar functions. Both commands are used to securely copy files from one server to another over SSH.
- To copy a file from one server to another using
scpyou would need to use the following syntax:
scp yourfile.txt [email protected]_server.com:/home/your_user/
The above command would copy the
yourfile.txt from your machine to your remote server.
- To do the same thing with
rsyncyou would use the following command:
rsync -avz [email protected]:/home/user/dir/
Some of the benefits of the
rsync command are that it makes the operation a lot faster, and also if the transfer fails for whatever reason, you could restore the process.
scp command on the other side, does a linear copy, but one of the benefits over
rsync is that you could copy files with
scp from one remote system to another remote system without first downloading them to your local machine.
ifconfig command is used to inspect the current network configuration on your server. It can show you information like:
- Your IP address
- Your MAC address
- All other interfaces attached to your current machine
I'm a big fan of the
ifconfig command as I really like the output and I'm used to it, but you need to keep in mind that the
ifconfig command is now deprecated and you should be using the
ip command instead.
ip command is quite similar to the
ifconfig command and can be considered as the newer version.
Or use the following for short:
ip a command gives you information for all of the available interfaces.
Before there was
telnet was the go-to protocol for connecting from one server to another.
telnet is insecure, nobody nowadays should use
telnet for connections.
However, you might still use the
telnet client to test the connectivity from your local machine to a remote server on a specific port.
For example, if you wanted to check if port
80 on a remote server is open, you could run the following command:
telnet devdojo.com 80
nc command, or netcat is used to read from and write to network connections using TCP or UDP.
As an example, you could start listening on a port with the following command:
nc -l 1234
The above command would start listening on port
1234 and if you open a second terminal and use
telnet to connect on that port, then start typing, you will be able to see the input from your second terminal directly on your first terminal that you've started the
nc command on. You should give this a try, it's pretty cool!
nmap command is an open-source tool, used for scanning networks.
The command is used to discover other hosts on a specific network by sending packets and then analyzing the response. For example, you could use
nmap to run a port scan on a specific host and find out what ports are being used:
As a system administrator, I use the
netstat command super often! It shows you the network statistics on your machine, for example, if you wanted to see all of the connections port 80, you could just run the following command:
netstat -plant | grep 80
You could also use
netstat to see what services are running and listening on your machine as well.
netstat -plant | grep LISTEN
As much as I love the
netstat command it is now being replaced with the
ss command. It is faster and provides more information.
Learning the above commands will make your life a lot easier in case you are facing any issues with your website or server.
Of course, there are a lot more commands out there but those are my top 15, I encourage you to go out there and explore the power of Linux! It is just amazing, it can be used as a desktop, web server, and even a firewall!