Terminal Tuts

Top 20 Linux Networking Commands

Top 20 Linux Networking Commands

Networking is an essential part of an operating system. Most of the computers in the world connect through a network. This network can be a small and straightforward home-based or as complex as a cloud computing data center. The networking task includes configurations, traffic monitoring, and troubleshooting.

Linux Networking Commands

In this article, we will show 20 useful Linux networking commands that would help you configure or troubleshoot network-related problems.

1. ifconfig

ifconfig (interface configurator) is one of the most basic and commonly used commands for finding network details. It is also used to configure network interface parameters.

We can use this command to get the IP address, MAC address, and MTU of available networks.

$ ifconfig

Example:

ifconfig basic command

In our example, we see the IP address information of 2 networks, ethernet, and local network.

To get details of a specific network, we will use the 'ifconfig' command with additional parameters. For example, to only show information that is related to Ethernet Network.

$ ifconfig etho

This command can also be used to set configurations like IP addresses or gateway to an interface.

Syntax:

$ ifconfig eth0 
netmask

You can replace

with the desired IP address and Gateway address.

2. ip

ip command is the latest version of ifconfig. It is more powerful than ifconfig command as it can perform several other tasks like configuring default or static routing, showing IP addresses and its properties, setting up IP addresses, and routes for network interfaces.

Syntax:

$ ip 

Where

Example:

ip command example

Link is used to show all network devices that are currently available.

Example:

Route shows entries in your system routing table. You can also get details of a specific network interface as well.

Syntax:

ip address show 

Where can be a network interface available in your system.

3. traceroute

traceroute command is commonly used to troubleshoot the network. It finds out the delay and pathway to your destination. It determines and reports where is network latency comes from.

It is not installed by default on some Linux Distros, so you can install it using the following command.

sudo apt-get install inetutils-traceroute

Syntax:

traceroute 

Where is the host IP you want to troubleshoot, and its a mandatory parameter for this command.

Example:

traceroute command example

The above output shows the specified hostname, size of network packets, maximum hops required, and IP address.

4. tracepath

tracepath is just like a 'traceroute' command to detect network delay but does not need root privileges. It is pre-installed on Ubuntu. It points out the exact place where your network is lagging. It also recognizes each hop in the route to the destination.

Syntax:

tracepath 

Where is the host IP you want to troubleshoot, and its a mandatory parameter for this command.

Example:

tracepath command example

5. ping

ping (Packet INternet Groper) is another most commonly used network command to check connectivity between two network nodes. It is used to measure the average response. If we can send a ping to any host and if it did not give any response, we can assume that either host is not reachable due to any network issue or its firewall is blocking the request.

Syntax:

ping 

Example:

ping command example

Ping command will keep executing until it is interrupted. You can limit the number of packets being sent using the '- c' parameter in the command.

Syntax:

$ ping -c  

Where is the packets limits you want to specify for the response.

Tip: The response rate of the ping command will be affected by your network connection and the host's physical location.

6. netstat

netstat command used to review each network connection and open sockets on the Linux device.  It provides connections, open sockets, routing tables information.

$ netstat

Example:

netstat command example

This command can be used with additional parameters as well.

Syntax:

$ netstat 

Where

  • -p shows all programs with open sockets
  • -s gets all details about ports
  • -r get details of the routing table

7. nslookup

nslookup (Name Server Lookup) command used to query DNS to get a domain name, IP address mapping, or DNS records.

Syntax:

nslookup 

Where is the DNS you want to analyze.

Example:

nslookup command example

8. dig

dig (Domain Information Groper) is another command used to investigate DNS. It is an updated version of nslookup. It performs a DNS Lookup query and displays the response returned from name servers. It is also used to verify DNS mappings, MX records, and other DNS records.

Syntax:

dig 

Where is the DNS you want to analyze.

Example:

dig command example

This command, by defaults, shows only A-type DNS records; you can use additional options to get other types of DNS records.

Syntax:

$ dig  

Where

  • MX for all MX type of DNS records
  • NS for all NS type of DNS records
  • ANY for all type of DNS records

9. route

route command is used to shows or modifies the system's routing table. Using this command, you can troubleshoot the network issue caused by a wrong entry in the system routing table. Setting a routing table is very important to make the router work correctly.

Syntax:

route

Example:

route command example

Using this command, we can modify the routing table as well.

Syntax:

route [-p] command dest [mask subnet] gateway [-if interface]
  • -p is used to make entry persistent; otherwise, the entry will be deleted on the next reboot. It is used only for adding a new entry.
  • command can be 'add', 'change' or 'del'.
  • mask subnet:  It is a subnet mask. By default, it is 255.255.255.255 if not provided in the command.
  • gateway: The IP address of the gateway via packets will be sent.
  • -if interface: it is the network interface for which you want to set up entry. It can be ethernet, WLAN, or local network.

10. Host

host command is used to display domain name for an IP address or IP address for a domain name. It can also be used to query DNS.

Syntax:

host   host 

Example:

host command example

11. arp

arp (Address Resolution Protocol) is used to manipulate kernel's ARP table. Using this command, you can view, add, update, or remove entries in the kernel's ARP table.

Syntax:

arp

Example:

arp command example

By default, the arp command shows the hostname, but if you want to see the IP address instead.

Syntax:

arp -n

You can also delete the entry from the ARP table using the command:

Syntax:

arp -d 

Here

is the IP address of the entry you want to remove from the ARP table.

12. iwconfig

iwconfig command is used to configure the WLAN interface. It can view or set up basic wireless network interface properties like SSID and encryption type.

Syntax:

iwconfig

It has many options that can be used to change the network name, enable/disable the network, set frequency, etc.

13. curl

curl is a utility used to transfer data to and from a server without user interaction. It can communicate using HTTP, HTTPS, FTP, SFTP, and SCP protocols. It can be used to upload or download data using any of the above protocols. You can transfer data allowing resume, setup bandwidth limit and user authentication, and so many other stuff with curl. It is installed by default in most of the Linux systems.

Syntax:

curl fosslinux.com

This command will show the content of the home page of fosslinux.com in the terminal. By default, curl uses an HTTP protocol for communication. You can also download a file using curl using the following command.

curl -O https://cdn.jsdelivr.net/npm/vue/dist/vue.js

The above command will download the file with its original name.

Example:

curl download file example

14. wget

wget is also a pre-installed package. It is used to download files using HTTP, HTTPS, FTP Protocols. It provides the ability to download multiple files, resume downloads, download in the background, etc.

Syntax:

wget 

Here is the path of file or directory to be download, and

$ wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz

Example:

wget file download example

In our example, the command first resolves the IP address and then starts downloading files showing filename, speed, and progress in the terminal. You can disable output using the -q parameter with the command.

15. telnet

telnet command uses the Telnet protocol to communicate with the destination host. You must need to specify the host with port (mostly 443 port).

Syntax:

telnet  

Example:

telnet command

16. whois

whois command is used to get all the information about a website. You can get all registration and ownership details using it.  You need to install the whois package before using it.

sudo apt install whois

Syntax:

whois 

Example:

whois command example

17. ifplugstatus

ifplugstatus command is used to check if the network cable is connected to the network interface. To use the command, you first need to install it on Ubuntu.

sudo apt-get install ifplugd

Syntax:

ifplugstatus

Example:

ifplugstatus command example

18. nload

nload command is used to monitor your network bandwidth. It can show the total amount of data usage and min/max bandwidth usage. You need to install the nload package to run it.

sudo apt-get install nload

Using it without any parameter will show you bandwidth usage of all network interfaces.

Syntax:

nload

Example:

nload command example

19. w

w command is used to get a list of currently logged in users on a system. It also provides valuable information like host, login time, idle time, JCPU.

Syntax:

w

Example:

w command example

20. mail

mail command is used to send email from the terminal. You can send email to multiple recipients. You should install the mailutil package to use the command.

sudo apt-get install mailutils

Syntax:

mail -s   <<< 

Example:

mail -s "Test Subject" [email protected] <<< 'This is a test email'

Conclusion

Those were the most useful network commands in Linux that are commonly used by the system and network administrators to investigate network related issues. I hope you have enjoyed learning these Linux networking commands. Do you have an exciting command that you want to share with our readers? Go for it in the comments below.

How to Install and Play Doom on Linux
Introduction to Doom The Doom Series originated in the 90s after the release of the original Doom. It was an instant hit and from that time onwards th...
Vulkan for Linux Users
With each new generation of graphics cards, we see game developers push the limits of graphical fidelity and come one step closer to photorealism. But...
OpenTTD vs Simutrans
Creating your own transport simulation can be fun, relaxing and extremely enticing. That's why you need to make sure that you try out as many games as...