Open In App

Linux Network Commands Cheat Sheet

Last Updated : 21 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Linux is a very popular operating system. Many people use it. Developers and network admins need to know Linux network commands well. This article will going explains most of the common Linux network commands in a very easy way and It also has a cheat sheet about these commands. The cheat sheet tells you what each command does and how you use it.

What Are Networking Commands in Linux?

Networking commands in Linux allow users to manage network connections. These commands let users set up networks, fix connection issues, and view network traffic. Users can also check network status, change settings, and control network programs with these commands. The commands use basic words that are easy for beginners to understand.

Linux Networking Commands Cheat Sheet

This list of Linux networking commands will help you work with network connections. You can use these commands to set up the networks, fix connection problems, and see the information about the network. If you are an experienced network admin or just starting to learn the Linux networking commands this command list will be a useful tool for you.

Network Configuration Commands

Command

Description

Example

hostname

Shows the Hostname of the current computer system.

hostname

Displays the hostname of the current system.

ip

Displays and allows you to configure network interfaces, routing, and tunnels.

ip addr show 

Shows the IP addresses assigned to network interfaces.

iwconfig

Shows and lets you set up wireless network interfaces.

iwconfig wlan0 essid "WiFiName"

Connects the wlan0 interface to the WiFi network named "WiFiName".

netplan

Sets up network interfaces using YAML configuration files.

netplan apply

Applies network settings from the YAML files.

ifconfig

Shows and configures the network interfaces on the current system.

ifconfig eth0

Displays information about the eth0 interface.

ifquery

Checks the current setup and settings of network interfaces.

ifquery --list

Lists all network interfaces and their settings.

nmcli

Reports the network status, manages and configures the network connections and controls the NetworkManager tool.

nmcli dev wifi list

Lists available WiFi networks.

netplan

This Defines the network interfaces, IP addresses, gateways, DNS servers, and the other network related settings in the YAML config file.

(Example covered in description)

ifup

This will Activates a network interface that is currently inactive or down.

ifup eth0

Activates the eth0 network interface.

ifdown

Deactivates a network interface that is currently active or up.

ifdown wlan0

Deactivates the wlan0 wireless interface.

dhcclient

Automatically gets an IP address and other network configuration details from a DHCP server.

dhclient eth0

Requests an IP address for the eth0 interface from a DHCP server.

Network Connectivity Commands

Command

Description

Example

arp

Maps IP addresses to MAC addresses on a local network and manages the ARP cache.

arp

Shows the current ARP cache entries.

arp -a

Prints the ARP table entries.

(Example covered in description)

arp -a -d

Removes all entries from the ARP table.

arp -d 192.168.1.100

Deletes the ARP entry for IP 192.168.1.100.

arp -s

Adds a new entry to the ARP table.

arp -s 192.168.1.10 00:11:22:33:44:55

Adds a static ARP entry for IP 192.168.1.10 and MAC 00:11:22:33:44:55.

netstat

Shows active network connections, routing information, and other network statistics.

netstat -antp

Lists all active network connections and the processes using them.

netstat -r

Prints the kernel's routing table.

(Example covered in description)

ping

Tests network connectivity between a host/client and server by sending data packets and measuring the response time.

ping 8.8.8.8

Tests connectivity to the Google DNS server at 8.8.8.8.

route

Configures the kernel's routing table entries.

route add default gw 192.168.1.1

Sets the default gateway to 192.168.1.1.

route flush

Removes all routes from the routing table.

(Example covered in description)

traceroute

Displays the path and hops that packets take to reach a remote server.

traceroute www.example.com

Traces the route taken to reach www.example.com.

telnet

Establishes the connection to the remote server or system through a TCP/IP network using the Telnet protocol.

telnet 192.168.1.10 22

Connects to the SSH server on 192.168.1.10 via Telnet.

w

This will Shows the information about users currently logged into the system.

(Example covered in description)

mail

Sends and receives email messages via the command line interface.

mail -s "Hello" [email protected]

Sends an email with subject "Hello" to [email protected].

ngrep

Displays and filters network packet data based on a given regular expression pattern.

ngrep -W byline "^GET"

Captures and prints HTTP GET requests.

iw

Displays and configures wireless network interface settings.

iw dev wlan0 scan

Scans for available wireless networks on the wlan0 interface.

DNS and Name Resolution Commands

Command

Description

Example

nslookup

Performs DNS lookups to resolve hostnames, IP addresses, mappings, or any specific DNS record.

nslookup example.com 

Resolves the IP address for example.com

host

Performs DNS lookups to resolve hostnames or IP addresses.

host google.com 

Resolves the IP address for google.com

dig

Performs DNS lookups to query information about DNS name servers.

dig @8.8.8.8 example.org 

Queries Google's DNS server for information about example.org

Network Information Commands

Command

Description

Example

finger

Displays user login information on a remote system.

finger [email protected] 

Shows login information for user on example.com

whois

Retrieves information about domain ownership from various WHOIS servers.

whois example.org 

Shows ownership details for example.org

Network Testing and Monitoring Commands

Command

Description

Example

hping

Assembles and analyzes TCP/IP packets, sends packets to a remote host, and examines the responses.

hping3 -S -p 80 example.com 

Sends SYN packets to port 80 on example.com

mtr

Combines functionalities of traceroute and ping commands, continuously sends packets and shows the ping time for each hop.

mtr google.com 

Traces the route to google.com and shows ping times

nc / netcat / ncat

Allows reading and writing data across network connections.

nc -l -p 8080 

Listens on port 8080 for incoming connections

smokeping

Measures network latency and packet loss between two hosts, performs checks at set intervals.

smokeping example.com 

Monitors latency and packet loss to example.com

socat

Facilitates data transfer between two bidirectional byte streams.

socat TCP4-LISTEN:8080,fork EXEC:/bin/bash 

Opens a remote shell on port 8080

speedometer

Displays bandwidth usage in real-time.

speedometer eth0 

Shows bandwidth usage on eth0 interface

speedtest-cli

Measures network performance by conducting a speed test.

speedtest-cli 

Runs a speed test to measure download/upload speeds

ss

Shows active network connections, socket statistics, and other network-related information.

ss -tulpn 

Lists all listening TCP/UDP sockets with process information

tracepath

Traces the route packets take, discovering the MTU along the path.

tracepath example.net 

Traces the path to example.net, showing MTU

Network Analysis and Monitoring Commands

Command

Description

Example

tcpdump

Captures and inspects network traffic in real-time for analysis.

tcpdump -i eth0 port 80 

Captures traffic on eth0 interface for port 80

nmap

Discovers active hosts and services on a network, useful for security audits.

nmap -sV example.com 

Scans example.com for open ports and services

bmon

Displays real-time bandwidth consumption for individual network interfaces.

bmon 

Shows bandwidth usage per interface

bwm-ng

Monitors the current bandwidth utilization across multiple network interfaces.

bwm-ng 

Displays bandwidth usage for all interfaces

iftop

Shows real-time bandwidth usage broken down by individual connections.

lsof -i 

Lists all open network connections

iperf

Measures the network performance and throughput between two systems.

iperf -c example.com 

Tests network performance to example.com

iptraf-ng

Monitors and displays network traffic flows in real-time.

iptraf-ng 

Shows real-time network traffic statistics

nethogs

Tracks network traffic and bandwidth usage per process or application.

nethogs 

Displays bandwidth usage per process/application

vmstat

Keeps historical records of network traffic statistics for selected interfaces, displaying hourly, daily, and monthly summaries.

vnstat -i eth0 

Shows traffic statistics for eth0 interface

Remote Access Commands

Command

Description

Example

ssh

Establishes a secure encrypted shell session with a remote system over the SSH protocol.

ssh [email protected] 

Opens an SSH session to example.com as user

scp

This will Securely copies files between the local and remote systems using the SSH protocol.

scp file.txt [email protected]:/path/to/dir 

Copies file.txt to example.com

sftp

This will Securely transfers files between the hosts using the SFTP (SSH File Transfer Protocol).

sftp [email protected] 

Opens an SFTP session to example.com as user

Security Commands

Command

Description

Example

iptables

The firewall utility that manages the packet filtering and the Network Address Translation (NAT) rules.

iptables -L 

Lists all current iptables rules

snort

An intrusion detection system that analyzes the network traffic for the suspicious activities.

snort -dev 

Runs Snort in packet logging mode

wireshark

Captures and analyzes network traffic data in a formatted text output.

wireshark 

Starts Wireshark for packet capturing and analysis

ufw

Manages the system's firewall, allowing you to add, delete, modify, or reset packet filtering rules.

ufw allow 22/tcp 

Allows incoming connections on port 22/TCP

Utility Commands

Command

Description

Example

curl

Transfers data to or from a server over various protocols.

curl https://example.com 

Fetches the website example.com

aria2

Supports multiple protocols for downloading files from the internet.

aria2c https://example.com/file.zip 

Downloads file.zip from example.com

ethtool

Modifies and queries settings of network interfaces, such as speed and other parameters.

ethtool -s eth0 speed 1000 

Sets eth0 interface speed to 1000Mbps

wget

A command-line utility for downloading files from the web.

wget https://example.com/file.zip 

Downloads file.zip from example.com

Conclusion

In summary, this shows important Linux commands for working with networks. These commands help you see and fix network problems. The commands let you check network traffic, bandwidth usage, security issues, and more. Beginners may gonna find this network commands list very helpful for learning the Linux networking basics.


Next Article
Article Tags :

Similar Reads