Priyanshu Pandey

Linux Networking Commands

Linus Torvalds created Linux entirely from scratch. It is created as open-source software, which is inherently very strong and secure. Anyone can install Linux and modify it to create their own Linux version. These Linux versions are known as “distros” or “distributions.”

The Linux kernel’s unrivaled security and reliability, combined with its open-source nature, make it one of the most widely used software tools. Servers and software development both employ Linux. One or more Linux distributions are used by the majority of devices and embedded systems worldwide. Linux servers account for around 90% of all internet servers worldwide. Furthermore, the Linux kernel is used by approximately 80% of the world’s smartphones. So, we also use Linux for various networking operations such as configuration and troubleshooting using various Linux networking commands.

Linux Networking Commands

Various Linux networking commands are used in networking for configuration and troubleshooting purposes. Some of the popular and essential commands are:

ifconfig

It is a network interface configuration command-line interface that is also used to initialize interfaces at system boot. Once a server is operational, it can be used to assign an IP address to an interface and enable or disable the interface as needed. The IP address, hardware MAC address, and MTU (Maximum Transmission Unit) size of the active interfaces are also displayed with this tool. Thus, ifconfig is helpful for system tuning or debugging.

Syntax

ifconfig

Example

ifconfig

Output

ifconfig

ip

The ip command is one of the fundamental commands that every administrator will need on a regular basis, from configuring new systems and assigning IP addresses to troubleshoot existing ones. The ip command can display address information, alter routing, and display network devices, interfaces, and tunnels. It is the replacement of the ifconfig command.

Syntax

ip [OPTION] OBJECT {COMMAND | help}

You will get various options and objects by using the following commands.

ip help

ip Example

To display the IP addresses associated with a server interface, use the following:

ip address show

Output

IP addresses

traceroute

Traceroute is a command-line utility that allows you to trace the whole path from your local system to another network system. It prints the number of hops (router IPs) traveled to reach the destination server. After the ping command, it is a simple network troubleshooting command.

Syntax

traceroute <destination>

Note:- To install traceroute in your system, you can use the following command.

sudo apt-get install inetutils-traceroute

Example The following command will give you

traceroute scaler.com
  • Size of the packets.
  • The IP address
  • The number of hops required.
  • Hostname

Output

traceroute

Tracepath

This command in Linux is similar to the traceroute command. It is employed in the detection of network delays. It does not, however, necessitate root access. This command also traces the path to the selected destination and recognizes each hop. If your network is weak, it detects the weak point.

Syntax

tracepath <ip_address>

Example

tracepath 192.168.75.2

Output

Tracepath

ping

Ping (Packet INternet Groper) is a Linux command that is typically used to verify network connectivity between two systems (Local Area Network (LAN) or Wide Area Network (WAN). It communicates with network nodes via ICMP (Internet Control Message Protocol).

Syntax

ping <ip_address>

Example

To test the connectivity, we use

ping 192.168.75.2

Output

ping

netstat

It gives statistical data about various interfaces, such as open sockets, routing tables, and connection information.

Syntax

netstat

To install netstat, run the following command

sudo apt install net-tools

Example To get details about ports, use the following command

netstat -s

Output netstat

ss(Socket Statistics)

Socket Statistics (ss) is a robust command-line utility for investigating sockets. It dumps socket statistics and presents similar information to netstat. Furthermore, it displays more TCP and status information than other similar commands.

Syntax

  1. To display TCP/UDP or UNIX sockets, use the -t, -u, or -x options in the command. Each of them can be combined with “a” to display the connected and listening sockets.
ss -ta
ss -ua
ss -xa
  1. Combine it with “l” to see only the listening sockets of TCP/UDP or UNIX sockets.
ss -lt
ss -lu
ss -lx

Example

To get the list of all the TCP ports (sockets) open on a server.

ss -ta

Output ss

dig

The dig command in Linux stands for Domain Information Groper. In DNS lookup, this command is used to query the DNS name server. It is also used to debug DNS problems.

Syntax

dig <domain_name>

Example

dig scaler.com

Output dig

nslookup

Another command used for DNS-related searches on Linux is nslookup. It is the earlier version of dig.

Syntax

nslookup <domain_name>

Example

nslookup scaler.com

Output

nslookup

route

A Linux system’s IP routing table can be viewed or modified using the command-line tool route. It is primarily used to set up static routes via an interface to particular hosts or networks.

Syntax

route

Example

You can view the Kernel IP routing table by using the following command.

route

Output route

host

This Linux command displays the domain name and IP address for a given hostname. It is also used to retrieve DNS lookup results for DNS-related queries.

Syntax

host -t <resource_name>

Example

host scaler.com

Output host

arp

The arp command in Linux stands for Address Resolution Protocol. It is used to see and modify the kernel’s ARP table. Every system has a list of IP addresses and their related MAC addresses. The ARP Lookup table is the name given to this table. When a destination is requested to connect via IP address, your router will look in this table for the MAC address. The table will not be used if it is cached.

Syntax

arp

Example

By default arp command gives the hostname, but we can use the command given below to get IP address.

arp -n

Output arp

iwconfig

The wireless network interface is configured using the Linux iwconfig command. It is used to configure and view basic WI-FI settings such as SSID and encryption.

Syntax

iwconfig [interface]

hostname

The Linux commandhostnameis used to view and change a system’s hostname.

Syntax

hostname

Example

To set the hostname, use the following command.

sudo hostname <new_name>

Note:- This command does not set a permanent hostname. When the computer reboots, it will be reset to the name in the hostname file.

curl or wget

The curl and wget commands in Linux are used to download files from the internet via the command line interface. To get the file, use the curl command with the option “O,” whereas the wget command is used directly.

Syntax

  1. curl
curl -O <file_link>

Example

curl -O scaler.com/scalertopics/linux-commands
  1. wget
wget <file_link>

Example

curl -O scaler.com/scalertopics/linux-commands

mtr

The mtr command in Linux is a combination of ping and traceroute. It displays information about the packets sent as well as the ping time of each hop in real-time. It is also used to view network problems.

Syntax

mtr <path>

Example

mtr scaler.com

Output

mtr

whois

The whois command in Linux is used to retrieve all information about a website. You can obtain all the information about a website, including its registration and owner details.

Syntax

whois <website_name>

To install whois command, use the following command

sudo apt install whois

Example

whois scaler.com

Output whois

ifplugstatus

The ifplugstatus command in Linux determines whether a cable is connected to a network interface. On Ubuntu, this command is not directly available.

To install ifplugstatus use the following command sudo apt-get install ifplugd Syntax

ifplugstatus

Example

Run the following command

ifplusstatus

If you get “link beat detected” then everything is working fine.

iftop

It is a network analyzing utility system administrators use to view bandwidth statistics. It displays a high-level summary of the networking operations on an interface. It is an abbreviation for Interface TOP, and the top is derived from the op command in Linux. It can even be used as a diagnostic tool to determine which program is causing the network problem.

Syntax

iftop

To install iftop, use the following command.

sudo apt install iftop

Example

To display bandwidth usage, use the following command.

iftop

Output iftop

tcpdump

Among other Linux network commands, the tcpdump command is the most commonly used in network analysis. It gathers and shows network traffic as it passes via the network interface. Syntax

tcpdump -i <network_device>

Example

To specify the protocol, use the command.

tcpdump -i <network_device> tcp

To specify the port number, use the following command.

tcpdump -i <network_device> port 80

ifup

The ifup command activates a network interface, making it ready for data transport and reception.

Syntax

sudo ifup eth0

ethtool

The ethtool is Linux command software that queries and changes network interface controller parameters and device drivers.

Syntax

ethtool <network_interface>

To install ethtool, use the following command.

sudo apt install ethtool

Example

ethtool eth0

nmcli

The nmcli is a simple, scriptable Linux command for reporting network status, managing network connections, and controlling the NetworkManager.

Syntax

nmcli

Example To view all network devices, use the following command.

nmcli dev status

Output nmcli

nc

NC (NetCat), often known as the “Network Swiss Army knife,” is a versatile command that can handle practically any operation using TCP, UDP, or UNIX-domain sockets. It can open TCP connections, listen on arbitrary TCP and UDP ports, and do port scanning, among other things. It can also be used as a rudimentary TCP proxy to test network daemons, see if remote ports are reachable, and much more.

Syntax

nc

Example

nc

Output nc

nmap

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.

Syntax

nmap <host_name>

To install nmap, use the following command.

sudo apt install nmap

Example

nmap scaler.com

Output nmap

Wireshark

Wireshark is a widespread, powerful, adaptable, and simple-to-use command for real-time packet capture and analysis on a packet-switched network. System administrators and network engineers use it to monitor and examine packets for security and troubleshooting.

Syntax

wireshark

bmon

It collects networking statistics and displays them visually in a human-friendly style. It’s a trustworthy and efficient real-time bandwidth monitor and rate estimator.

Syntax

bmon

Iptables

The IP packet filtering and NAT ruleset can be configured, maintained, and inspected using the Linux command iptables. It is employed to configure and oversee the Linux firewall (Netfilter). You can list already-existing packet filter rules, add, remove, or alter packet filter rules, and list individual rule counts.

Syntax

iptables --table TABLE -A/-C/-D... CHAIN rule --jump Target

Where,

  • -A is append
  • -C is check
  • -D is delete

Firewalld

Network/firewall zones, which specify the trust level of network connections or interfaces, are supported by Firewalld’s dynamically managed firewall. Ethernet bridges, IP sets, IPv4, and IPv6 firewall configurations are all supported.

UFW firewall

On Linux distributions running Debian and Ubuntu, UFW is a well-liked and default firewall configuration tool. It is used to add, delete, alter, and reset packet filtering rules, among other things, as well as to enable or stop the system firewall.

Syntax

sudo ufw

Example

To check firewall status, use the following command

sudo ufw status

Output  UFW firewall

Conclusion

  • Linus Torvalds created Linux entirely from scratch and it is the kernel of an operating system.
  • The Linux kernel’s unrivaled security and reliability, combined with its open-source nature, make it one of the most widely used operating systems.
  • Linux servers account for around 90% of all internet servers worldwide. Furthermore, the Linux kernel is used by approximately 80% of the world’s smartphones. So, we also use Linux for various networking operations.
  • There are various Linux networking commands that network administrators use to configure and troubleshoot the network.
  • Some of the popular Linux networking commands are:
    • ping
    • ip
    • ifconfig
    • nslookup
    • mtr
    • route
    • iftop

Author