There are many small commands that you can use directly from the Terminal. They can give you a lot of important information about your server. Is it working correctly? Is it configured well? Does it need any adjustment? Here we have the 5 most used Linux network commands that will make your life easier.
In the following examples of the different commands, we will use a generic domain (yourdomain.com) and IP address (188.8.131.52). You can change them with the one you want to test and see if the results are the ones that you are interested in.
The ping command is a command with a command-line interface (CLI) that you can find on every Linux distro and probably any OS in general (FreeBSD, Windows, macOS, ChromeOS, etc.). It sends packets of data using the Internet Control Message Protocol (ICMP) to a destination that could be defined by an IP address or a domain name. Then it will wait for the echo, the reply for each of those ICMP messages to return. In the end, you will get information about the time the packets reached the destination and if there were lost packets too.
The ping command is maybe the simplest command that you can use for network diagnostic. It is great for checking if a device is connected and running. If it is, it will reply to your ping command.
Examples of the ping command:
ping –n 15 yourdomain.com.
This one will send 15 packets to the target, which in this case is yourdomain.com.
This will show you how long it takes you to reach the IP address 184.108.40.206.
If you want to see more options for the ping command see the full article “What is the Ping Command?”.
Nslookup command is another universal command with a CLI interface. As the name suggests, nslookup is software to probe name servers and get different DNS records. It works for both a forward lookup and a reverse lookup too.
Examples of the Nslookup command:
nslookup -type=ns yourdomain.com
This will check for the NS record of yourdomain.com. There you can see the authoritative name servers of that domain.
After the “=” sign, we are specifying the DNS type. You can change it to A, AAAA, MX, SOA, CNAME, PTR, or another type that you are interested in.
nslookup -type=any yourdomain.com
If you want to see all publicly available DNS records for a domain, you can directly use the “any” type.
This will make a reverse lookup and see to which domain, does the IP address 220.127.116.11 belongs.
The Nslookup command provides limited information, in comparison with the Host command or the Dig command, but you can find it on Windows, macOS, and ChromeOS too. So it is worth knowing it if for some reason you have to use somebody else’s computer.
Traceroute command does exactly what you are expecting – it can trace the route of the packets of data and report the finding to you. Why would you like to know the route? Knowing the route, you can see bottlenecks in the connectivity and think about solutions to improve it. Imagine your website, which has web hosting in Europe, shows that all the American visitors are experiencing a very long route that passes through a specific slow location. You can think about a CDN with servers around that location and increase the speed significantly.
The Traceroute command is a great troubleshooting Linux command that you can easily use through the Terminal. You can use it in tandem with the Ping command. With this one, you can see the whole route, but it takes longer for the response to arrive. With the Ping, you get an almost instant answer for a single IP address or a domain.
Examples of the Traceroute command:
This will show you all the hops that the packets of data take, starting from your device to the target yourdomain.com.
This will show you all the hops that the packets of data take, starting from your device to the target 18.104.22.168. As you can see, it works both with domain names and IP addresses (both IPv4 addresses and IPv6 ones).
See how Traceroute and its Windows version Tracert work here “Traceroute command (a.k.a tracert command)”.
Nmap command is a simple tool that can map your network. A network administrator can use the Nmap command and send packets to all of the available hosts on the network. By doing so, it will see who is connected, what services are running (application names and versions) on them, their OSes, check the firewalls they have, and more.
It is a big advantage that it can be used for very large networks with many connected devices. The packets that it sends can be sent over TCP or UDP. As you prefer.
What is great about it is that it is available for many different Linux distros, but also for Windows, macOS, FreeBSD, and more. In addition, it is free and open-source! This software is not pre-installed like some of the previously mentioned, so you will need to download it from the official site.
Examples of the Nmap command:
This will show all the open services and ports of the host (the server).
You can use an IP address (both IPv4 and IPv6) and see the open ports and services of the host.
nmap 22.214.171.124 126.96.36.199 188.8.131.52.
You can scan multiple hosts by simply put their IP addresses with a space in between. Here we have 3 hosts in this example.
Use the “*” simple to indicate all of the possible combinations of hosts inside the subnet.
nmap -O 184.108.40.206
With this Linux network command, you can see the OS (Operating system) of the host 220.127.116.11.
nmap -sA 18.104.22.168
The option above will show you the firewall settings of the particular host.
nmap -sS 22.214.171.124
A “stealth” mode for the Nmap command. You could use it to stay undetected. It uses TCP SYN packets.
Nmap is a very interesting command that could be very useful, no matter if you are a network administrator or you want to see information about your server.
The dig command is probably the best software with CLI that you can use on a Linux computer. You can get all kinds of detailed information about a domain, including DNS records, name server information, connectivity from different points, and even trace the route.
It is a simple Linux command, but it has plenty of options to customize your DNS probing.
With time, the Dig command has essentially replaced both the Nslookup command and the Host command and has become the go-to for Linux and macOS network administrators.
Examples of the Dig command:
dig yourdomain.com NS
This will show you the NS records have the information about the name servers for the particular domain. You can change the last part of this query with the type of DNS record that you want to probe. Try one of the following:
dig yourdomian.com A
dig yourdomian.com AAAA
dig yourdomian.com SOA
Information about the DNS zone.
dig yourdomian.com MX
Incoming mail server.
dig yourdomian.com TXT
Different TXT records.
dig yourdomian.com CNAME
The linked canonical hostname for the specific domain.
dig -x 126.96.36.199
The Dig command, with the option “-x”, can be used to perform reverse DNS lookup by probing an IP address.
dig +trace yourdomain.com
You can use the Dig command to trace the route to the target with the option “+trace”.
You can see more information about this Linux network command here – “Linux dig command for network diagnostics”.
There are many useful Linux network commands out there. Many are built-in so it is extremely easy to start using them. They can provide a lot of information about your server, domain, and connected devices. Find out which one best suits your needs and be a pro using it!
Love “How to…” articles? In that case the next one will suit your taste: