15 Best Linux Networking Commands and Scripts You Should Know

Both servers and software development use Linux. Today, Linux distributions are used by the vast majority of electronics and embedded systems.

Worldwide, Linux servers make up about 90% of all internet servers. Additionally, the Linux kernel is used by around 80% of all smartphones.

Today, every system in the world is linked via a network. Information exchange across systems requires network connectivity.

Computer networking refers to communication over the internet as well as within a network. A network can be as tiny and basic as one in a home or as intricate as one in a space station.

Network configuration and troubleshooting are both parts of networking. We are learning about Linux networking commands in this article.

TL;DR

Linux Networking Commands Description
aria2 aria2 is a command line tool for downloading files in Linux. It is a lightweight alternative to wget and curl.
ifconfig Displays information about currently active network interface and is used to configure kernel-resident network interfaces.
traceroute This command is used to determine the route taken by packets to reach a specified host.
ping Measures the round-trip time for messages sent from the originating host to a destination computer that are echoed back to the source.
curl Helps in transferring data from or to a server without user interaction.
netstat It can be used to view information about active network connections, routing tables, port listening and a variety of other networking-related information.
nmap Nmap is a network exploration and security auditing tool. It can be used to identify hosts and services on a network, as well as security issues.
dig dig command can be used to query DNS information. With dig, you can find out a host's IP address, MX record, and other DNS information.
bmon The bmon command in Linux is a network monitoring tool that can be used to check the status of your network connection. It can be used to monitor bandwidth usage, packet loss, and other network statistics.
dhclient The dhclient command is a network configuration utility that allows you to configure your system to use a dynamic IP address.
host This command allows users to query DNS records and perform other network-related functions.
iperf This command is used to measure the throughput of a network or the performance of a network device.
ncat ncat command is used for a variety of purposes, from port scanning to file transfers.
ss It is a CLI command that shows the network statistics

Here’s how it is done:

  1. aria2
  2. ifconfig
  3. traceroute
  4. tracepath
  5. ping
  6. curl
  7. netstat
  8. nmap
  9. dig
  10. bmon
  11. dhclient
  12. host
  13. iperf
  14. ncat
  15. ss

#1 aria2

A lightweight command-line download tool with support for several protocols and sources is called aria2. It supports BitTorrent, FTP, HTTP/HTTPS, Metalink, and SFTP. Through integrated JSON-RPC and XML-RPC interfaces, aria2 can be controlled.

Aaria2 aims to use your entire available download bandwidth and can download a file from various sources and protocols. Aaria2 uses little memory and CPU time. Physical memory use ranges from 4 MiB (regular HTTP/FTP downloads) to 9 MiB (BitTorrent downloads) when disk caching is off.

The Metalink Download Description Format (also known as Metalink v4), Metalink version 3, and Metalink/HTTP are all supported by aria2. With Metalink, you can verify files, integrate HTTP, FTP, SFTP, and BitTorrent, and choose from a variety of languages, locations, OS, and other configuration options.

The aria2 process can be managed using the RPC interface. JSON-RPC (through HTTP and WebSocket) and XML-RPC are the interfaces that are supported. Aria2 is quite simple to use.

Installing aria2 on Debian/Ubuntu/Linux Mint:

$ sudo apt-get install aria2

Usage:

aria2c https://download.atatus.com/datasheets/Atatus-Datasheet.pdf

#2 ifconfig

The command-line tool ifconfig is used to configure network interfaces and to initialize interfaces at boot up. It is among the most basic commands employed in network inspection.

Once a server is operational, it can provide an interface with an IP address and enable or disable the interface whenever necessary. The route and network interface are both displayed using it as well.

The active interfaces' IP address, hardware MAC address, and MTU (Maximum Transmission Unit) size are also displayed with this tool. Thus, ifconfig is helpful for system tuning or debugging.

You can easily install ifconfig as a component of the net-tools package if you still choose to utilize it as part of your daily sysadmin tasks.

apt install net-tools

Use the -a flag to list every currently active interface, whether up or down.

$ ifconfig -s

The -s flag can be used to obtain information that is shorter and more to the point. Ifconfig is equipped with additional options to handle more difficult tasks.

ifconfig Linux command
ifconfig Linux command

The -a flag will provide comprehensive details on network devices, configuration, and current settings if you call it without any options.

#3 traceroute

One of the most helpful networking commands is Linux traceroute. It is applied to network troubleshooting. It determines the route to your objective after detecting the delay.

Every device in the path is named and given a unique identification. It follows the path that leads there. It identifies the source of network latency and reports it.

You can find out the path that packets took to get to the host by using the traceroute command. Additionally, it can be quite helpful when examining the transit of data packets and the hops taken by packets.

Your system might not have a traceroute installed by default. If you use a Debian-derived operating system, such as Ubuntu, installation is as simple as typing the following command:

sudo apt install traceroute

Usage:

traceroute google.com
Traceroute
Traceroute

#4 tracepath

Like the traceroute command, Linux tracepath is similar. It's employed to find network delays. However, root privileges are not necessary. It comes pre-installed with Ubuntu.

It locates each hop along the route and tracks it to the desired destination. It recognizes the location of the network's weakest point if your network has one.

While tracing the path to the network host, the tracepath command is used to determine MTU (Maximum Transmission Unit). Although it is pretty similar to what we previously discussed, it does require sudo access and lacks factual features like traceroute.

Installing traceroute on Debian/Ubuntu/Linux Mint:

apt-get install iputils-tracepath

Usage:

tracepath www.google.com

#5 ping

The ping (Packet Internet Groper) command, which is frequently used to check the connectivity between the host and the server, can be regarded as one of the most crucial commands while troubleshooting your network.

It is employed to measure the average response. If a host can be pinged but does not respond, either the host is not reachable owing to a network issue, or the host's firewall is blocking the request.

One of the most used network troubleshooting commands for Linux is ping. In essence, it verifies the network connectivity of two nodes.

The ping command sends the ICMP echo request to verify network connectivity. Until it is stopped, it continues to operate.

The Ping command is typically available by default in Linux-based systems. On Debian- and Ubuntu-based operating systems, you can install it if it isn't already installed by running the command:

sudo apt-get install iputils-ping -y

Usage:

ping www.google.com
Ping Linux command
Ping Linux command

#6 curl

The curl (Client URL) command supports several different protocols, including HTTP, FTP, IMAP, and many others, and is mostly used to transport data over networks.

This tool is preferred in automation since it can be used for endpoint testing, debugging, and error reporting and was created to operate without any human input.

To transport data, curl is used in scripts or command lines. Curl is also the Internet transfer engine for thousands of software applications in over ten billion installations, as well as in cars, television sets, routers, printers, audio equipment, mobile phones, tablets, set-top boxes, and media players.

Almost every person who uses the Internet every day uses curl.

If you're using a Debian derivative, you can simply execute the following command to install the curl utility because it doesn't come pre-installed:

sudo apt install curl

Learn Useful cURL Commands.

Usage:

curl https://www.atatus.com/blog/19-useful-curl-commands-that-you-should-know/
curl Linux command
curl Linux command

#7 netstat

A command-line program called netstat provides essential data on the Linux networking subsystem, including network connections, routing tables, interface statistics, and much more. It is helpful for performance analysis and network troubleshooting.

It serves as a key network service debugging tool as well, allowing users to see which applications are listening on which ports.

On a Linux device, the netstat command is used to inspect all open sockets and network connections. It offers statistics data on many interfaces, such as open sockets, routing tables, and connection details.

Net-tools is the name of the package that includes netstat. There is no need to install the netstat tool because it is pre-installed on modern systems.

Running the netstat command, however, is likely to result in an error on older computers. Run the command, as a result, to install netstat on Linux distributions.

sudo apt install net-tools [On Debian/Ubuntu]

Usage:

netstat -nr
netstat Linux command
netstat Linux command

#8 nmap

For Linux system/network administrators, Nmap (Network Mapper) is a strong and incredibly flexible tool. It can be used to learn more about a single host or to investigate a whole network.

Nmap is also used for network audits, network security scans, port discovery on distant computers, and much more.

Nmap is a tool for investigating and evaluating network security. It is frequently used by hackers and security enthusiasts because it enables you to obtain real-time information about the network, extensive information about the IP addresses linked to your network, port scanning, and much more.

Use the following command to install the nmap utility on Ubuntu-based distributions:

$ sudo apt install nmap

Usage:

nmap www.atatus.com
nmap Linux command
nmap Linux command

#9 dig

Domain Information Groper, or dig, is a Linux command which is used to contact the DNS name server during a DNS lookup. It is also employed to resolve DNS-related problems.

For a better understanding of the DNS topography, it is primarily used to verify DNS mappings, MX Records, host addresses, and all other DNS records.

It is a more recent iteration of nslookup. It conducts a DNS Lookup and shows the result provided by name servers. MX records, other DNS records, and DNS mappings are all likewise verified using it.

Dig supports Internationalized domain name (IDN) queries and uses the Linux system's default DNS resolver.

The following command should be used to install the dig utility on Ubuntu-based distributions:

sudo apt install dnsutils

Usage:

dig atatus.com
dig Linux command
dig Linux command

#10 bmon

bmon is a powerful network monitoring and debugging tool for Unix-like systems that run from the command line. It collects networking-related statistics and shows them graphically in a user-friendly manner. It serves as a trustworthy and efficient rate estimator and real-time bandwidth monitor.

This Linux network monitoring tool's configurable text output can be used to create complex scripts. The nicest feature of this tool is the graphical output, which can even be HTML.

Bmon is included in the default repositories of major Linux distributions, including Ubuntu, therefore installation is very straightforward.

sudo apt install bmon

Usage:

bmon
bmon Linux command
bmon Linux command

#11 dhclient

The Dynamic Host Configuration Protocol (BOOTP), or if these protocols fail, statically assigning an address, can be used to configure one or more network interfaces using the Internet Systems Consortium DHCP Client, or dhclient.

A host can communicate with a central server that manages a list of IP addresses that can be assigned to one or more subnets via the DHCP protocol. A DHCP client may request an address from this pool and use it momentarily for network communication.

The DHCP protocol also offers a way for a client to find out crucial information about the network to which it is connected, like the location of a name server and default router.

$ sudo dhclient eth0

The IP address that is assigned dynamically to the Ethernet interface eth0 will be renewed by the above command.

#12 host

A straightforward tool for running DNS lookups is called the host. It is typically used to translate between names and IP addresses.

When no options or arguments are provided, the host publishes a brief description of the options and arguments it has on the command line.

The domain name that has to be looked up names. If it is a colon-delimited IPv6 address or a dotted-decimal IPv4 address, the host will by default run a reverse lookup for that address.

The name or IP address of the name server that the host should use in place of the server or servers listed in /etc/resolv.conf is indicated by the optional argument server.

Simply add the domain name to the host command to discover the domain's IP address. We will show how:

host google.com

#13 iperf

The tool iperf is used to actively measure the highest achievable bandwidth on IP networks. It supports tuning a wide range of timing, protocol, and buffer-related parameters. It reports the measured throughput/bitrate, loss, and other metrics for each test.

This rework of an initial version created at NLANR/DAST is frequently referred to as iperf3. To create a smaller, simpler code base and a library version of the functionality that can be used in other programs, iperf3 is a brand-new implementation that was created from the ground up.

Additionally, iperf3 offers several capabilities that were absent from the original iperf but are present in other tools like nuttcp and netperf. One of these is a zero-copy mode, and another is an optional JSON output.

This tool is available in Ubuntu's default repository and can be installed with the following command:

sudo apt install iperf

Usage:

iperf -s -u

#14 ncat

ncat is a robust networking tool that allows command-line data reading and writing across networks. As a significantly better reimplementation of the ancient Netcat, Ncat was created for the nmap Project.

It is made to be a dependable back-end utility that rapidly provides network connectivity to other applications and users. It communicates using both TCP and UDP. Ncat offers the customer an almost infinite number of possible uses in addition to supporting IPv4 and IPv6.

The ability to chain Ncats together, the ability to reroute both TCP and UDP ports to other websites, SSL support, and proxy connections via SOCKS4 or HTTP (CONNECT method) proxies (with optional proxy authentication as well) are just a few of the many capabilities offered by ncat.

Since ncat command is a part of nmap command, you can install it in CentOS or RHEL as mentioned below:

yum install nmap

Installing ncat Command on Ubuntu:

sudo apt install ncat

#15 ss

Image Source

The ss command in Linux is used in place of the netstat command. It is thought to be a far quicker and more detailed command than netstat.

ss can respond more quickly since it gathers all of its data from the kernel userspace.

Syntax:

ss

This command provides details on all connections made using TCP, UDP, and UNIX sockets.

To display TCP/UDP or UNIX sockets in the command, use the corresponding options -t, -u, or -x. Each of them can be combined with "a" to display the listening and connected sockets.

Install ss using:

sudo yum install iproute

Finally!!!

The success of Linux today is primarily due to its powerful networking capabilities. Linux offers every kind of networking tool you may ever need.

However, a lot of people may find it challenging to select the best tool due to the abundance of Linux network commands. For any networking activity, there is at least one tool available.

We hope we were able to give you the crucial information you required.


Monitor Your Entire Application with Atatus

Atatus is a Full Stack Observability Platform that lets you review problems as if they happened in your application. Instead of guessing why errors happen or asking users for screenshots and log dumps, Atatus lets you replay the session to quickly understand what went wrong.

We offer Application Performance Monitoring, Real User Monitoring, Server Monitoring, Logs Monitoring, Synthetic Monitoring, Uptime Monitoring, and API Analytics. It works perfectly with any application, regardless of framework, and has plugins.

Atatus can be beneficial to your business, which provides a comprehensive view of your application, including how it works, where performance bottlenecks exist, which users are most impacted, and which errors break your code for your frontend, backend, and infrastructure.

If you are not yet an Atatus customer, you can sign up for a 14-day free trial.

Atatus

#1 Solution for Logs, Traces & Metrics

tick-logo APM

tick-logo Kubernetes

tick-logo Logs

tick-logo Synthetics

tick-logo RUM

tick-logo Serverless

tick-logo Security

tick-logo More

Janani
Janani works for Atatus as a Content Writer. She's devoted to assisting customers in getting the most out of application performance management (APM) tools.
India