Essential Linux Networking Commands Cheat Sheet


1. ping
Purpose: Test network connectivity to another host.
Usage: ping [destination]
Example: ping google.com
Description: Sends ICMP Echo Request packets to the target and reports if replies are received, helping verify if a host is reachable.
2. traceroute
Purpose: Trace the path packets take to a network destination.
Usage: traceroute [destination]
Example: traceroute google.com
Description: Displays each hop (router) along the route to the target and the time taken for each hop, useful for diagnosing routing issues.
3. netstat
Purpose: Display network connections, routing tables, interface statistics, and more.
Usage: netstat [options]
Common options:
-a
: Show all connections and listening ports-t
: Show TCP connections-u
: Show UDP connections-l
: Show only listening sockets
Example: netstat -tuln
Description: Lists all listening TCP and UDP ports in numeric form
4. curl
Purpose: Make HTTP requests and interact with URLs or APIs.
Usage: curl [options] [URL]
Example: curl https://example.com
Description: Retrieves content from a web server, useful for testing web services and APIs.
5. dig
Purpose: Query DNS servers for information about hostnames and IP addresses.
Usage: dig [hostname]
Example: dig google.com
Description: Provides detailed DNS query results, including IP addresses, authoritative servers, and more.
6. nslookup
Purpose: Query DNS to obtain domain name or IP address mapping.
Usage: nslookup [hostname]
Example: nslookup google.com
Description: Returns the IP address associated with a domain name, or vice versa.
7. ip
Purpose: Manage and display network interfaces, IP addresses, and routing.
Usage:
ip link show
sudo ip link set eth0 down
ip route show
Description: Shows network interfaces, manages their state, and displays routing tables. Replaces older tools like ifconfig and route.
8. mtr
Purpose: Combine ping and traceroute for real-time network diagnostics.
Usage: mtr [destination]
Example: mtr google.com
Description: Shows the route to a host and updates statistics in real time, useful for detecting packet loss and latency.
9. whois
Purpose: Query domain registration and ownership details.
Usage: whois [domain]
Example: whois example.com
Description: Retrieves domain registration information from public databases.
10. tcpdump
Purpose: Capture and analyze network packets in real time.
Usage: sudo tcpdump -i [interface] [filter]
Example: sudo tcpdump -i eth0 port 80
Description: Captures packets for analysis. Useful for troubleshooting network traffic.
11. ifplugstatus
Purpose: Check the physical link status of network interfaces.
Usage: ifplugstatus [interface]
Example: ifplugstatus eth0
Description: Verifies if an Ethernet cable is connected.
12. nmcli
Purpose: Manage NetworkManager connections and devices from the command line.
Usage:
nmcli device show
nmcli connection show
Description: Displays and manages network devices and connections.
13. nc (netcat)
Purpose: Versatile networking utility for port scanning, data transfer, and connectivity checks.
Usage: nc -v -n [destination] [port]
Example: nc -v -n 192.168.1.10 22
Description: Checks if a port is open, can transfer files, and more.
14. telnet
Purpose: Test TCP connectivity to a specific port.
Usage: telnet [destination] [port]
Example: telnet 192.168.1.10 22
Description: Connects to a remote host on a given port, useful for troubleshooting services.
15. arp
Purpose: Display and modify the ARP table.
Usage: arp -a
Description: Shows the mapping of IP addresses to MAC addresses on the local network.
16. route
Purpose: Display or modify the IP routing table.
Usage: route -n
Description: Shows the system’s routing table (mostly replaced by ip route).
Subscribe to my newsletter
Read articles from Subrat Yadav directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
