June 8, 2025
Common Linux Networking Commands and Their Usage

Common Linux Networking Commands and Their Usage

Networking commands are essential tools for diagnosing, managing, and troubleshooting network connectivity and configurations in computing systems. Below is an overview of some of the most commonly used networking commands, their purposes, and practical examples.

1. ip – Display or Manipulate Network Interfaces

The ip command is used for viewing and managing networking configurations like IP addresses, routing tables, and network interfaces. It’s a powerful tool for network administration on Linux systems.

# Display all network interfaces:
ip a

# Display info about specific interface 
ip a show 

# Display the routing table:
ip route show

# The ip link command without any additional subcommands and options shows all network interface link information:
ip link

# To print link status about specific interface 
ip link show wlan0

# To turn on/off an interface,

ip link <interface> up 
ip link <interface> down 

# Add a new IP address to an interface:
sudo ip addr add 192.168.1.100/24 dev eth0

# Add gateway of interface
sudo ip route add default via 192.168.1.1 dev eth0

# Set default gateway of all interfaces
sudo ip route add default via 192.168.1.1

# Delete an IP address from an interface:
sudo ip addr del 192.168.1.100/24 dev eth0

# Bridge

sudo ip link add br0 type bridge
sudo ip link set eth0 master br0
sudo ip link set wlan0 master br0
sudo ip link set br0 up
sudo ip link set br0 down
sudo ip link delete br0 type bridge

2. dig – Domain Information Groper

The dig command is used for querying DNS (Domain Name System) servers to retrieve DNS records associated with a domain. It’s particularly useful for troubleshooting DNS issues.

# Query A record (IP address) for a domain
dig example.com A

# Query CAME record (IP address) for a domain
dig example.com CNAME

# Query TXT record (IP address) for a domain
dig example.com TXT

# Query MX (Mail Exchanger) records:
dig example.com MX

# Query DNS server for specific domain details:
dig @8.8.8.8 example.com

# Lookup the IP(s) associated with a hostname (A records):
dig +short example.com

# Get a detailed answer for a given domain (A records):
dig +noall +answer example.com

# Find authoritative name servers for the zone and display SOA records:
dig +nssearch example.com

3. traceroute – Trace the Route Packets Take to a Network Host

traceroute is used to trace the path that data packets take from your system to a remote host. It helps to identify network delays or failures along the route.

# Trace the route to a domain/host:
traceroute example.com

# Disable IP address and host name mapping
traceroute -n example.com

# Specify wait time in seconds for response:
traceroute --wait=0.5 example.com

# Specify number of queries per hop:
traceroute --queries=5 example.com

# Use ICMP instead of UDP for tracerouting:
traceroute --icmp example.com

# Determine the MTU to the destination:
traceroute --mtu example.com

# Specify size in bytes of probing packet:
traceroute example.com 42

4. hostname – Show or Set the System’s Hostname

The hostname command is used to display or set the hostname of the system. The hostname is the label that identifies the machine on a network.

# Display the current hostname:
hostname

# Set a new hostname:
sudo hostname new-hostname

5. ping – Send ICMP Echo Requests to Test Connectivity

ping is one of the most widely used commands for checking network connectivity. It sends ICMP Echo Request messages to a target host and waits for a reply.

# Ping a host to check if it's reachable:
ping example.com

# Ping an IP address with specific packet size:
ping -s 1000 192.168.1.1

# Ping a host only a specific number of times:
ping -c 2 google.com

# Ping host, specifying the interval in seconds between requests (default is 1 second):
ping -i <seconds> <host>

# Ping a host with specific number of pings, timeout (`-W`) for each reply, and total time limit (`-w`) of the entire ping run:

ping -c <count> -W <seconds> -w <seconds> <host<

6. arp – Display or Manipulate the System’s ARP Table

The arp command is used to display or modify the Address Resolution Protocol (ARP) cache, which maps IP addresses to MAC addresses. It is useful for diagnosing network issues involving device identification.

# Display the ARP table:
arp -a

# Add a static ARP entry:
sudo arp -s 192.168.1.100 00:14:22:01:23:45

# Delete an ARP entry:
sudo arp -d 192.168.1.100

7. mtr – Network Diagnostic Tool (Combines Ping and Traceroute)

mtr is a network diagnostic tool that combines the functionality of ping and traceroute. It provides real-time data about the path and performance of network packets.

# Start a network trace to a domain:
mtr example.com

# Run mtr with a specific number of pings per hop:
mtr -c 5 example.com

8.whois -Query Domain Information

The whois command is used to retrieve information about domain registration, including the owner, registration date, and nameservers.

# Query WHOIS data for a domain:
whois example.com

# Get WHOIS data from a specific server:
whois -h whois.verisign-grs.com example.com

9. curl – Transfer Data From or To a Server

curl is a versatile command-line tool for transferring data to or from a server using various network protocols like HTTP, FTP, and others. It’s commonly used for testing APIs and web services.

# Fetch the HTML content of a webpage:
curl http://example.com

# Fetch the HTML content of Multiple subdomain webpages 
curl http://site.{fruit, salad, veg}.com

# Download a file from the internet:
curl -O http://example.com/file.zip

# Make a POST request to an API:
curl -X POST -d "name=John&age=30" http://example.com/api

# URLs with numeric sequence 
curl ftp://ftp.example.com/file[1-5].png

# ignore self signed / no recognized certificate error 
curl -k https://example.com

# Uploading file 
curl -T abc.txt ftp://example.com/dir

# upload with username and passowrd 
curl -u username:password -T testfile.tar ftp://myftpserver

# Download from ftp with username and password
curl -u <userName>:<password> -O ftp://test.example.com/readme.txt

# limit the bandwidth of transfer 
curl --limit-rate 100K http://example.com/samplefile.tar.gz -O

10. nslookup – Query DNS (Domain Name System) Information

nslookup (Name Server Lookup) is a command-line tool used to query DNS records of a domain. It is widely used to troubleshoot DNS-related issues and to obtain specific domain information such as IP addresses, MX records, and name servers. it is very similar to dig command but the main selling point of nslookup is its interactive mode .

# basic dns query 
nslookup example.com

# Query A record (IP address) for a domain:
nslookup -type=A example.com

# Query MX (Mail Exchange) records for a domain:
nslookup -type=MX example.com

# Query NS (Name Server) records for a domain:
nslookup -type=NS example.com

# Query TXT records for a domain:
nslookup -type=TXT example.com

# Ouery CNAME for a domain 
nslookup -type=CNAME example.com

# interactive mode
# Running nslookup without specifying a domain will bring you into interactive mode, where you can enter multiple queries without needing to type nslookup each time.

nslookup

# Once in interactive mode, you can perform multiple queries like:
> example.com
> set type=MX
> example.com

# To exit interactive mode, type exit:
exit

11. ethtool – Network Interface Controller (NIC) Configuration and Diagnostics

ethtool is a command-line utility for managing and troubleshooting network interface cards (NICs) on Linux systems. It provides detailed information about the Ethernet devices and allows users to configure various aspects of the network interfaces, such as speed, duplex mode, link status, and more.

The tool is particularly useful for network administrators and systems engineers who need to perform low-level diagnostics or configure advanced network features on a machine.

# To display detailed information about a specific network interface, such as the NIC's speed, duplex mode, and more, use the following command:
ethtool <ethernet-interface>

# Check Link Status
ethtool <ethernet-interface> | grep "Link detected"

# Change the Speed and Duplex Settings
# to set the speed to 100Mbps and full duplex mode, you can use:
ethtool -s <ethernet-interface> speed 100 duplex full

# To reset the settings to auto-negotiate the best speed and duplex mode, use:
ethtool -s <ethernet-interface> speed 0 duplex full autoneg on

# Enable or Disable Auto-Negotiation
sudo ethtool -s <ethernet-interface> autoneg on
sudo ethtool -s <ethernet-interface> autoneg off

# Check Driver and Firmware Information
# You can use ethtool to display the driver information for the NIC
ethtool -i <ethernet-interface>

# Enable or Disable Wake-on-LAN
sudo ethtool -s <ethernet-interface> wol g
sudo ethtool -s <ethernet-interface> wol d

12. bmon – Bandwidth Monitor

bmon (short for Bandwidth Monitor) is a command-line tool for monitoring the bandwidth usage of network interfaces in real-time. It is commonly used for diagnosing network performance and analyzing traffic statistics on Linux-based systems. Unlike other tools that simply display network statistics, bmon provides a real-time, graphical interface in the terminal, making it easier to visualize traffic flows and identify bottlenecks or other network issues.

# Basic Usage (Monitor All Interfaces)
bmon

# Monitor a Specific Network Interface
bmon eth0

# Monitor Bandwidth with a Specific Refresh Rate
bmon -r 2

# View Detailed Network Statistics
bmon -s

# Export Data to CSV Format
bmon -c 1 -o csv > network_stats.csv

#  Monitor Bandwidth for Multiple Interfaces
bmon eth0 wlan0

Conclusion

These networking commands provide valuable insights into network configurations, troubleshooting, and monitoring. From checking connectivity with ping to diagnosing routing issues with traceroute, each tool plays a vital role in managing network infrastructure. Understanding and utilizing these commands will empower administrators and users to troubleshoot and maintain network health efficiently.

Leave a Reply

Your email address will not be published. Required fields are marked *