#Networking Tools on Linux
Master networking commands for troubleshooting and configuration.
#📋 Table of Contents
#Network Configuration
#ip Command (Modern)
bash
1# View all interfaces
2ip addr
3ip a
4
5# View specific interface
6ip addr show eth0
7
8# View routing table
9ip route
10ip r
11
12# Add/remove IP address
13sudo ip addr add 192.168.1.100/24 dev eth0
14sudo ip addr del 192.168.1.100/24 dev eth0
15
16# Enable/disable interface
17sudo ip link set eth0 up
18sudo ip link set eth0 down#NetworkManager
bash
1# List connections
2nmcli connection show
3
4# Show active connections
5nmcli connection show --active
6
7# Connect to WiFi
8nmcli device wifi connect "SSID" password "password"
9
10# Modify connection
11nmcli connection modify "connection" ipv4.addresses 192.168.1.100/24
12nmcli connection modify "connection" ipv4.method manual#DNS Tools
#nslookup
bash
1# Basic lookup
2nslookup google.com
3
4# Specific record type
5nslookup -type=mx google.com
6nslookup -type=ns google.com
7nslookup -type=txt google.com#dig
bash
1# Basic lookup
2dig google.com
3
4# Short answer
5dig +short google.com
6
7# Specific record
8dig google.com MX
9dig google.com NS
10dig google.com TXT
11
12# Trace DNS path
13dig +trace google.com
14
15# Reverse lookup
16dig -x 8.8.8.8#host
bash
1# Simple lookup
2host google.com
3
4# Reverse lookup
5host 8.8.8.8#Connectivity Testing
#ping
bash
1# Basic ping
2ping google.com
3
4# Limited count
5ping -c 4 google.com
6
7# Specific interval
8ping -i 0.5 google.com
9
10# Specify interface
11ping -I eth0 google.com#traceroute
bash
1# Trace route to destination
2traceroute google.com
3
4# Use ICMP
5sudo traceroute -I google.com
6
7# Use TCP
8sudo traceroute -T -p 443 google.com#nc (netcat)
bash
1# Check if port is open
2nc -zv hostname 80
3nc -zv hostname 22
4
5# Port scan
6nc -zv hostname 20-30
7
8# Send data
9echo "GET / HTTP/1.0" | nc hostname 80
10
11# Listen on port
12nc -l 8080#curl
bash
1# HTTP request
2curl https://api.example.com
3
4# Include headers
5curl -I https://api.example.com
6
7# POST request
8curl -X POST -d '{"key":"value"}' -H "Content-Type: application/json" https://api.example.com
9
10# Download file
11curl -O https://example.com/file.zip
12
13# Follow redirects
14curl -L https://example.com
15
16# Timing info
17curl -w "@curl-format.txt" -o /dev/null -s https://example.com#wget
bash
1# Download file
2wget https://example.com/file.zip
3
4# Download to specific location
5wget -O /tmp/file.zip https://example.com/file.zip
6
7# Continue partial download
8wget -c https://example.com/file.zip
9
10# Mirror website
11wget -m https://example.com#Traffic Analysis
#tcpdump
bash
1# Capture all traffic on interface
2sudo tcpdump -i eth0
3
4# Capture specific port
5sudo tcpdump -i eth0 port 80
6
7# Capture specific host
8sudo tcpdump -i eth0 host 192.168.1.100
9
10# Save to file
11sudo tcpdump -i eth0 -w capture.pcap
12
13# Read from file
14tcpdump -r capture.pcap
15
16# Human-readable output
17sudo tcpdump -i eth0 -A port 80#ss (Socket Statistics)
bash
1# All connections
2ss -a
3
4# TCP connections
5ss -t
6
7# UDP connections
8ss -u
9
10# Listening ports
11ss -l
12ss -tuln
13
14# Show process
15ss -tulnp
16
17# Specific port
18ss -tuln | grep :80#netstat (Legacy)
bash
1# All connections
2netstat -a
3
4# Listening ports
5netstat -tuln
6
7# With process info
8netstat -tulnp
9
10# Routing table
11netstat -rn#Firewall Configuration
#iptables
bash
1# List rules
2sudo iptables -L -n -v
3
4# Allow port
5sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
6
7# Block IP
8sudo iptables -A INPUT -s 192.168.1.100 -j DROP
9
10# Allow established connections
11sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
12
13# Save rules
14sudo iptables-save > /etc/iptables/rules.v4#firewalld (RHEL/CentOS)
bash
1# Check status
2sudo firewall-cmd --state
3
4# List zones
5sudo firewall-cmd --get-zones
6
7# List rules
8sudo firewall-cmd --list-all
9
10# Add port
11sudo firewall-cmd --add-port=8080/tcp --permanent
12sudo firewall-cmd --reload
13
14# Add service
15sudo firewall-cmd --add-service=http --permanent
16sudo firewall-cmd --reload#ufw (Ubuntu)
bash
1# Enable firewall
2sudo ufw enable
3
4# Allow port
5sudo ufw allow 80/tcp
6sudo ufw allow 22
7
8# Deny port
9sudo ufw deny 23
10
11# Check status
12sudo ufw status verbose
13
14# Delete rule
15sudo ufw delete allow 80/tcp#Summary
| Task | Command |
|---|---|
| View IP | ip addr |
| DNS lookup | dig domain |
| Test connectivity | ping -c 4 host |
| Check port | nc -zv host port |
| View connections | ss -tuln |
| Capture traffic | tcpdump -i eth0 |
| Firewall | ufw / firewall-cmd |
[!TIP] Pro Tip: Create aliases for common network troubleshooting commands:
bashalias ports='ss -tuln' alias myip='curl -s ifconfig.me'