The 5 most used Linux network commands with examples

21.09.2021 3,094 10

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 (123.123.123.123). You can change them with the one you want to test and see if the results are the ones that you are interested in. 

Ping command

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.

ping 123.123.123.123

This will show you how long it takes you to reach the IP address 123.123.123.123. 

If you want to see more options for the ping command see the full article “What is the Ping Command?”.

Nslookup 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. 

nslookup 123.123.123.123

This will make a reverse lookup and see to which domain, does the IP address 123.123.123.123 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. 

You can see more examples of the Nslookup command here “Nslookup command and 10 easy examples”

Traceroute command 

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:

traceroute yourdomain.com

This will show you all the hops that the packets of data take, starting from your device to the target yourdomain.com.

traceroute 123.123.123.123

This will show you all the hops that the packets of data take, starting from your device to the target 123.123.123.123. 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

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:

nmap yourdomian.com

This will show all the open services and ports of the host (the server).

nmap 123.123.123.123

You can use an IP address (both IPv4 and IPv6) and see the open ports and services of the host.

nmap 123.123.123.123 111.111.111.111 222.222.222.222.

You can scan multiple hosts by simply put their IP addresses with a space in between. Here we have 3 hosts in this example.

Nmap 123.123.123.*

Use the “*” simple to indicate all of the possible combinations of hosts inside the subnet.

nmap -O 123.123.123.123

With this Linux network command, you can see the OS (Operating system) of the host 123.123.123.123.

nmap -sA 123.123.123.123

The option above will show you the firewall settings of the particular host.

nmap -sS 123.123.123.123

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.

Dig command

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 

IPv4 addresses.

dig yourdomian.com AAAA

IPv6 addresses.

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 123.123.123.123

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”.

Conclusion

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:

10 replies on “The 5 most used Linux network commands with examples”

pod ks lumina

… [Trackback]

[…] Find More on that Topic: blog.neterra.cloud/en/the-5-most-used-linux-network-commands-with-examples/ […]

พัดลมหลังคา

… [Trackback]

[…] Info to that Topic: blog.neterra.cloud/en/the-5-most-used-linux-network-commands-with-examples/ […]

ติดเน็ตบ้าน เอไอเอส

… [Trackback]

[…] Read More to that Topic: blog.neterra.cloud/en/the-5-most-used-linux-network-commands-with-examples/ […]

สีทนไฟ

… [Trackback]

[…] Read More Information here on that Topic: blog.neterra.cloud/en/the-5-most-used-linux-network-commands-with-examples/ […]

80 mg di ossicodone

… [Trackback]

[…] Read More on on that Topic: blog.neterra.cloud/en/the-5-most-used-linux-network-commands-with-examples/ […]

Bauc14

… [Trackback]

[…] Read More to that Topic: blog.neterra.cloud/en/the-5-most-used-linux-network-commands-with-examples/ […]

คลินิกกายภาพบำบัด

… [Trackback]

[…] Find More here on that Topic: blog.neterra.cloud/en/the-5-most-used-linux-network-commands-with-examples/ […]

เฟสไก่

… [Trackback]

[…] There you can find 7807 additional Information on that Topic: blog.neterra.cloud/en/the-5-most-used-linux-network-commands-with-examples/ […]

Karen

… [Trackback]

[…] Find More on that Topic: blog.neterra.cloud/en/the-5-most-used-linux-network-commands-with-examples/ […]

sci/sci news/news sci/ science diyala

… [Trackback]

[…] Read More here on that Topic: blog.neterra.cloud/en/the-5-most-used-linux-network-commands-with-examples/ […]

Leave a Reply

Your email address will not be published.