Linux Networking Commands Cheat Sheet
A quick reference for essential Linux networking commands to help troubleshoot, configure, and monitor networks efficiently. π
π Network Configuration Commands
Command | Description |
---|---|
ip a |
Show IP addresses and interfaces (use instead of ifconfig ). |
ip link show |
Display all network interfaces. |
ip route show |
Show routing table (default gateway, subnets, routes). |
ip addr show | Displays IP addresses, similar toΒ ifconfig |
ifconfig |
Display or configure network interfaces (deprecated). |
nmcli dev status |
Show NetworkManager status for all interfaces. |
Linux_Networking_Commands_Cheat_Sheet .pdf
π‘ Network Connectivity & Testing
Command | Description |
---|---|
ping -c 4 google.com |
Send 4 ICMP packets to check connectivity. |
traceroute google.com |
Show path taken by packets to destination. |
mtr google.com |
Combination of ping and traceroute (real-time). |
dig google.com |
Query DNS records for a domain. |
nslookup google.com |
Get DNS resolution for a domain. |
curl -I https://google.com |
Check website response headers. |
π Find Open Ports & Network Services
Command | Description |
---|---|
netstat -tulnp |
Show active ports and services (deprecated). |
ss -tulnp |
Show open ports and listening services (modern alternative). |
lsof -i :80 |
Find process using port 80. |
nmap -p 22 192.168.1.1 |
Scan port 22 (SSH) on a specific device. |
nmap -sn 192.168.1.0/24 |
Scan active devices on a subnet. |
πΆ Monitor Network Traffic
Command | Description |
---|---|
tcpdump -i eth0 port 80 |
Capture network packets on port 80. |
iftop -i eth0 |
Show bandwidth usage per connection. |
nload |
Display live network bandwidth usage. |
bmon |
Interactive bandwidth monitoring tool. |
ip -s link |
Show interface traffic statistics. |
π Firewall Management (iptables & firewalld)
Command | Description |
---|---|
iptables -L -n -v |
List all firewall rules. |
iptables -A INPUT -p tcp --dport 22 -j ACCEPT |
Allow SSH traffic. |
iptables -A INPUT -p tcp --dport 80 -j DROP |
Block HTTP traffic. |
firewall-cmd --list-all |
Show current firewalld settings. |
firewall-cmd --add-port=8080/tcp --permanent |
Open port 8080 permanently. |
π Network Interface Management
Command | Description |
---|---|
ip link set eth0 up |
Enable network interface. |
ip link set eth0 down |
Disable network interface. |
dhclient eth0 |
Obtain IP address via DHCP. |
ethtool eth0 |
Display Ethernet settings. |
π‘ Set Up & Manage Routes
Command | Description |
---|---|
ip route add default via 192.168.1.1 |
Set default gateway. |
route -n |
Show routing table (deprecated). |
ip route del default |
Remove default route. |
π Advanced Networking Commands
Command | Description |
---|---|
tc qdisc add dev eth0 root netem delay 100ms |
Simulate network latency. |
tc qdisc del dev eth0 root |
Remove latency settings. |
curl ifconfig.me |
Get public IP address. |
wget http://speedtest.tele2.net/1MB.zip |
Download a test file to check network speed. |
π Scan & Detect Network Issues
Command | Description |
---|---|
arp -a |
Show ARP table (MAC addresses of connected devices). |
whois google.com |
Get domain registration details. |
hostname -I |
Get local machine IP address. |
systemctl restart networking |
Restart networking service. |
These Linux networking commands will help you troubleshoot, monitor, and configure networks efficiently. π
π 1. Check Network Configuration
π Command: ip a
β Show IP addresses and interfaces
πΉ Example Output:
β Shows IP addresses, MAC addresses, and interface statuses.
π 2. Test Network Connectivity
π Command: ping
β Check if a host is reachable
πΉ Sends 4 packets to check connectivity.
πΉ If packets are lost, there might be network issues.
π 3. Check Network Routes
π Command: ip route
β Show routing table
πΉ Displays default gateway, subnet routes, and interface routes.
π Command: traceroute
β Show path to a destination
πΉ Displays all the hops a packet takes to reach its destination.
π‘ 4. Scan Open Ports and Listening Services
π Command: netstat
(Older) or ss
(Newer Alternative)
πΉ t = TCP, u = UDP, l = Listening, n = Numeric, p = Process
πΉ Example Output:
β This means SSH is listening on port 22.
π 5. Find Network Interfaces and Traffic Stats
π Command: ip -s link
β Show interface statistics
β Displays sent/received packets and errors.
π Command: ifconfig
(Deprecated)
β
Shows interface details (IP, MAC, status).
(Use ip a
instead in modern Linux systems.)
π 6. Test DNS Resolution
π Command: nslookup
β Find IP of a domain
β Shows Googleβs IP addresses from your DNS server.
π Command: dig
β Detailed DNS lookup
β Provides detailed DNS resolution info.
πΆ 7. Monitor Network Traffic
π Command: tcpdump
β Capture network packets
β
Captures HTTP traffic on eth0
interface.
π Command: iftop
β Monitor bandwidth usage
β Shows live network bandwidth usage per connection.
π οΈ 8. Manage Firewall Rules
π Command: iptables
β Configure firewall rules
β Block incoming traffic on port 80:
β Allow SSH (port 22) traffic:
β List all rules:
π 9. Scan Network for Active Devices
π Command: nmap
β Scan devices and open ports
β Helps identify online devices and security vulnerabilities.
π 10. Test and Manage Network Speed
π Command: speedtest-cli
β Check internet speed
β Shows upload/download speed.
π Command: tc
β Simulate network latency
β Add 100ms delay to all outgoing packets:
β Remove delay:
π BONUS: Advanced Linux Networking Commands
π Restart Network Services
β Restart the network service after changes.
π Find Public IP Address
β Displays your external IP address.
π‘ Find Default Gateway
β Shows your default gateway (router IP).
ifconfig replacement command is IP
-
TheΒ
ip
Β command is more powerful and flexible thanΒifconfig
, and it’s designed to work with the newer Linux networking stack. -
Alternatives toΒ
ifconfig
Β for specific tasks:- To display IP addresses:Β
ip addr show
. - To bring an interface up:Β
ip link set <interface> up
. - To bring an interface down:Β
ip link set <interface> down
.
- To display IP addresses:Β
-
Examples ofΒ
ip
Β commands:ip addr
:Β Displays IP addresses, similar toΒifconfig
.ip link
:Β Manages network interfaces (e.g., bring up/down, change MTU).ip route
:Β Manages routing tables.ip tunnel
:Β Configures IP tunnels.