Networking
A comprehensive developer cheatsheet covering Linux networking and troubleshooting, featuring essential CLI commands, common flags, and operational workflows for connectivity testing (ping, traceroute), interface configuration (ip), DNS resolution (dig, nslookup), socket monitoring (ss), secure file transfers (ssh, scp), and packet analysis (tcpdump, nmap).
Understanding Linux Networking
OSI Model Layers (Simplified)
| Layer | Purpose | Example Protocols |
|---|---|---|
| 7: Application | User-facing services | HTTP, SSH, DNS, FTP |
| 4: Transport | End-to-end communication | TCP, UDP |
| 3: Network | Routing and addressing | IP, ICMP, ARP |
| 2: Data Link | Physical addressing | Ethernet, MAC addresses |
| 1: Physical | Cables, switches, Wi-Fi | Ethernet cables, radio waves |
Common Ports
| Port | Protocol | Service |
|---|---|---|
| 22 | TCP | SSH (Secure Shell) |
| 80 | TCP | HTTP (Web) |
| 443 | TCP | HTTPS (Secure Web) |
| 53 | TCP/UDP | DNS (Domain Name System) |
| 25 | TCP | SMTP (Email) |
| 3306 | TCP | MySQL |
| 5432 | TCP | PostgreSQL |
| 6379 | TCP | Redis |
| 27017 | TCP | MongoDB |
Network Connectivity Testing
ping — Check Host Reachability
Flags: -c N (stop after N packets), -i N (interval in seconds), -s N (packet size), -t N (TTL value), -4 (IPv4), -6 (IPv6), -f (flood - DANGEROUS)
$ ping google.com
PING google.com (142.250.185.78) 56(84) bytes of data.
64 bytes from 142.250.185.78: icmp_seq=1 ttl=117 time=12.3 ms
64 bytes from 142.250.185.78: icmp_seq=2 ttl=117 time=11.8 ms
64 bytes from 142.250.185.78: icmp_seq=3 ttl=117 time=12.1 ms
64 bytes from 142.250.185.78: icmp_seq=4 ttl=117 time=11.9 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 11.8/12.0/12.3/0.2 msChecks if a host is reachable and measures round-trip time. Press
Ctrl+Cto stop.
$ ping -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=11.2 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=11.5 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=117 time=11.3 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=117 time=11.7 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=117 time=11.1 ms
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4004ms
rtt min/avg/max/mdev = 11.1/11.36/11.7/0.22 ms
-c 5sends exactly 5 packets then stops.
$ ping -i 0.5 google.com
(Pings every 0.5 seconds instead of the default 1 second)$ ping -s 1024 google.com
(Sends 1024-byte packets instead of the default 56 bytes)traceroute — Trace Network Path
Flags: -n (no DNS, just IPs), -p (port), -I (use ICMP), -T (use TCP), -w (timeout)
$ traceroute google.com
traceroute to google.com (142.250.185.78), 30 hops max, 60 byte packets
1 router.local (192.168.1.1) 0.523 ms 0.678 ms 0.834 ms
2 10.0.0.1 (10.0.0.1) 5.234 ms 5.456 ms 5.678 ms
3 172.16.1.1 (172.16.1.1) 8.123 ms 8.345 ms 8.567 ms
4 192.168.100.1 (192.168.100.1) 10.234 ms 10.456 ms 10.678 ms
5 142.250.185.78 (142.250.185.78) 12.345 ms 12.567 ms 12.789 msTraces the network path to a destination, showing each hop.
$ traceroute -n google.com
traceroute to google.com (142.250.185.78), 30 hops max, 60 byte packets
1 192.168.1.1 0.523 ms 0.678 ms 0.834 ms
2 10.0.0.1 5.234 ms 5.456 ms 5.678 ms
3 172.16.1.1 8.123 ms 8.345 ms 8.567 ms
-nskips DNS lookups — much faster.
$ traceroute -I google.com
(Uses ICMP instead of UDP — often works better with firewalls)tracepath — Trace Path Without Root Privileges
$ tracepath google.com
1?: [LOCALHOST] pmtu 1500
1: 192.168.1.1 0.523ms
1: 192.168.1.1 0.678ms
2: 10.0.0.1 5.234ms
3: 172.16.1.1 8.123ms
4: 192.168.100.1 10.234ms
5: 142.250.185.78 12.345ms
Resume: pmtu 1500 hops 5 back 5Similar to
traceroutebut doesn't require root privileges.
mtr — My TraceRoute (Combines ping + traceroute)
Interactive Keys: r (reset), d (toggle display), q (quit)
$ mtr google.com
My traceroute [v0.95]
bob@server (0.0.0.0) 2026-01-15T10:30:15+0000
Keys: Help Display mode Restart statistics Order of fields quit
Packets Pings
Host Loss% Snt Last Avg Best Wrst StDev
1. 192.168.1.1 0.0% 10 0.5 0.6 0.4 0.9 0.1
2. 10.0.0.1 0.0% 10 5.2 5.4 4.8 6.1 0.3
3. 172.16.1.1 0.0% 10 8.1 8.3 7.9 9.0 0.2
4. 192.168.100.1 0.0% 10 10.2 10.4 10.0 11.0 0.3
5. 142.250.185.78 0.0% 10 12.3 12.5 12.0 13.0 0.3Combines
pingandtraceroutein real-time. Shows packet loss and latency per hop.
Network Configuration
ip — Modern Network Configuration
Subcommands:
| Command | Description |
|---|---|
ip a or ip addr | Show IP addresses |
ip link | Show network interfaces |
ip route | Show routing table |
ip neigh | Show ARP table |
ip -s link | Show interface statistics |
Show IP Addresses:
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe4b:5c7b/64 scope link
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
inet 10.0.0.5/24 brd 10.0.0.255 scope global wlan0
valid_lft forever preferred_lft foreverShows all IP addresses assigned to all network interfaces.
Show Specific Interface:
$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe4b:5c7b/64 scope link
valid_lft forever preferred_lft foreverBring Interface Up/Down:
$ ip link set eth0 up
(Brings eth0 online)
$ ip link set eth0 down
(Takes eth0 offline)Add IP Address:
$ ip addr add 192.168.1.200/24 dev eth0
(Adds a secondary IP address to eth0)
$ ip addr del 192.168.1.200/24 dev eth0
(Removes the IP address)Show Routing Table:
$ ip route
default via 192.168.1.1 dev eth0 proto dhcp metric 100
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100 metric 100
10.0.0.0/24 dev wlan0 proto kernel scope link src 10.0.0.5 metric 100Shows the routing table — where traffic is directed.
Add/Remove Routes:
$ ip route add 10.0.0.0/24 via 192.168.1.1 dev eth0
(Adds a static route)
$ ip route del 10.0.0.0/24
(Removes the route)
$ ip route add default via 192.168.1.1
(Adds a default gateway)Show ARP Table:
$ ip neigh
192.168.1.1 dev eth0 lladdr aa:bb:cc:dd:ee:ff REACHABLE
192.168.1.50 dev eth0 lladdr 11:22:33:44:55:66 STALE
10.0.0.1 dev wlan0 lladdr 99:88:77:66:55:44 REACHABLEShows the ARP table (IP-to-MAC address mappings).
Interface Statistics:
$ ip -s link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:4b:5c:7b brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
123456789 123456 0 0 0 1234
TX: bytes packets errors dropped carrier collsns
987654321 987654 0 0 0 0ifconfig — Legacy Network Configuration (Deprecated)
Note: ifconfig is deprecated. Use ip instead.
$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe4b:5c7b prefixlen 64 scopeid 0x20<link>
ether 08:00:27:4b:5c:7b txqueuelen 1000 (Ethernet)
RX packets 123456 bytes 123456789 (117.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 987654 bytes 987654321 (941.8 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 1234 bytes 123456 (120.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1234 bytes 123456 (120.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0DNS & Name Resolution
nslookup — Query DNS Servers
Interactive Commands: set type=MX, set type=NS, server 8.8.8.8
$ nslookup google.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: google.com
Address: 142.250.185.78
Name: google.com
Address: 142.250.185.79
Name: google.com
Address: 142.250.185.80Queries DNS for IP addresses of a domain name.
$ nslookup -type=MX gmail.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
gmail.com mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 5 gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 20 alt2.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 40 alt4.gmail-smtp-in.l.google.com.
-type=MXshows mail exchange (MX) records.
$ nslookup -type=NS google.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
google.com nameserver = ns2.google.com.
google.com nameserver = ns3.google.com.
google.com nameserver = ns4.google.com.
google.com nameserver = ns1.google.com.
-type=NSshows name server (NS) records.
$ nslookup 8.8.8.8
8.8.8.8.in-addr.arpa name = dns.google.Reverse lookup — finds domain name from IP address.
dig — Domain Information Groper (More Detailed)
Flags: +short (terse), +trace (full delegation path), +noall (suppress all), +answer (show only answer)
$ dig google.com
; <<>> DiG 9.16.1-Ubuntu <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12345
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 300 IN A 142.250.185.78
;; Query time: 12 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Jan 15 10:30:15 UTC 2026
;; MSG SIZE rcvd: 55Detailed DNS query with full response.
$ dig +short google.com
142.250.185.78
+shortgives only the IP address — great for scripting.
$ dig +trace google.com
; <<>> DiG 9.16.1-Ubuntu <<>> +trace google.com
;; global options: +cmd
. 518400 IN NS a.root-servers.net.
. 518400 IN NS b.root-servers.net.
...
google.com. 172800 IN NS ns1.google.com.
google.com. 172800 IN NS ns2.google.com.
...
google.com. 300 IN A 142.250.185.78
+traceshows the full delegation path from root servers.
$ dig -x 8.8.8.8 +short
dns.google.Reverse DNS lookup — finds domain name from IP.
$ dig ANY google.com
(Shows ALL record types for the domain)host — Simple DNS Lookup
$ host google.com
google.com has address 142.250.185.78
google.com has IPv6 address 2607:f8b0:4006:800::200e
google.com mail is handled by 20 alt2.aspmx.l.google.com.
google.com mail is handled by 30 alt3.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.Simple DNS lookup — shows A, AAAA, and MX records.
$ host -t MX gmail.com
gmail.com mail is handled by 5 gmail-smtp-in.l.google.com.
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
-tspecifies record type (A, AAAA, MX, NS, etc.)
$ host 8.8.8.8
8.8.8.8.in-addr.arpa domain name pointer dns.google.Reverse lookup from IP to domain.
resolvectl — Query and Control Systemd-Resolved
$ resolvectl status
Global
Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub
Current DNS Server: 8.8.8.8
DNS Servers: 8.8.8.8 1.1.1.1
DNSSEC NTA: 10.in-addr.arpa
16.172.in-addr.arpa
168.192.in-addr.arpa
17.172.in-addr.arpa
...
Link 2 (eth0)
Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
DefaultRoute setting: yes
LLMNR setting: yes
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
Current DNS Server: 8.8.8.8
DNS Servers: 8.8.8.8 1.1.1.1
DNS Domain: ~.Shows current DNS configuration when using systemd-resolved.
Network Connections & Sockets
ss — Socket Statistics (Modern netstat)
Flags: -t (TCP), -u (UDP), -l (listening), -p (programs), -n (numeric), -a (all), -o (timers), -4 (IPv4), -6 (IPv6)
$ ss -tulpn
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1234,fd=3))
tcp LISTEN 0 128 127.0.0.1:3306 0.0.0.0:* users:(("mysqld",pid=5678,fd=22))
tcp LISTEN 0 128 [::]:80 [::]:* users:(("nginx",pid=9012,fd=6))
tcp ESTAB 0 0 192.168.1.100:22 192.168.1.50:45678 users:(("sshd",pid=2345,fd=4))
udp UNCONN 0 0 0.0.0.0:53 0.0.0.0:* users:(("systemd-resolve",pid=3456,fd=13))Shows all listening and established connections with process names. The gold standard for network troubleshooting.
Common ss Combinations:
$ ss -tuln # Show listening TCP/UDP ports (no process names)
$ ss -tlnp # Show listening TCP ports with process names
$ ss -tulpn # Show ALL TCP/UDP with process names (most common)
$ ss -t 'state established' # Show established TCP connections
$ ss -n | grep :80 # Show connections to port 80Show TCP Connections Only:
$ ss -t
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 192.168.1.100:22 192.168.1.50:45678
ESTAB 0 0 192.168.1.100:443 192.168.1.60:56789Show UDP Connections Only:
$ ss -u
State Recv-Q Send-Q Local Address:Port Peer Address:Port
UNCONN 0 0 0.0.0.0:53 0.0.0.0:*
UNCONN 0 0 0.0.0.0:631 0.0.0.0:*Show All Sockets with Timers:
$ ss -o
tcp ESTAB 0 0 192.168.1.100:22 192.168.1.50:45678 timer:(keepalive,50min,0)netstat — Legacy Network Statistics (Deprecated)
Note: netstat is deprecated. Use ss instead.
Common Flags: -t (TCP), -u (UDP), -l (listening), -p (programs), -n (numeric), -a (all), -r (routing), -i (interfaces)
$ netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1234/sshd
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 5678/mysqld
tcp6 0 0 :::80 :::* LISTEN 9012/nginx
udp 0 0 0.0.0.0:53 0.0.0.0:* 3456/systemd-resolvearp — Address Resolution Protocol Cache
Flags: -n (numeric), -a (show all), -d (delete entry)
$ arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.1.1 ether aa:bb:cc:dd:ee:ff C eth0
192.168.1.50 ether 11:22:33:44:55:66 C eth0
192.168.1.60 ether 99:88:77:66:55:44 C eth0Shows IP-to-MAC address mappings on the local network.
File Transfers & Remote Access
ssh — Secure Shell Remote Access
Flags: -p (port), -i (identity file), -L (local port forward), -R (remote port forward), -D (SOCKS proxy), -C (compression), -v (verbose), -N (no commands)
Basic Connection:
$ ssh user@192.168.1.10
user@192.168.1.10's password:
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-91-generic x86_64)
user@server:~$Connects to a remote server via SSH.
Specify Port:
$ ssh -p 2222 user@192.168.1.10
(Connects on port 2222 instead of default 22)Use Identity File (SSH Key):
$ ssh -i ~/.ssh/private_key.pem user@192.168.1.10
(Connects using SSH key instead of password)Execute Remote Command:
$ ssh user@192.168.1.10 'ls -la /var/log'
total 1234
drwxr-xr-x 12 root root 4096 Jan 15 10:30 .
drwxr-xr-x 14 root root 4096 Jan 15 09:00 ..
-rw-r--r-- 1 root root 12345 Jan 15 10:30 syslog
-rw-r--r-- 1 root root 6789 Jan 15 10:25 auth.logRuns a single command on the remote server and returns the output.
Local Port Forwarding (Tunneling):
$ ssh -L 8080:localhost:80 user@192.168.1.10
(Forward local port 8080 to remote port 80)Access remote service as if local:
curl http://localhost:8080
Remote Port Forwarding:
$ ssh -R 8080:localhost:80 user@192.168.1.10
(Forward remote port 8080 to local port 80)SOCKS Proxy:
$ ssh -D 1080 user@192.168.1.10
(Creates a SOCKS proxy on local port 1080)scp — Secure Copy Over SSH
Flags: -P (port - uppercase), -i (identity file), -r (recursive), -C (compression), -p (preserve attributes)
$ scp file.txt user@192.168.1.10:/home/user/
file.txt 100% 1234 1.2MB/s 00:00Copies a file to a remote server.
$ scp user@192.168.1.10:/home/user/remote_file.txt .
remote_file.txt 100% 4567 2.3MB/s 00:00Downloads a file from a remote server.
$ scp -r user@192.168.1.10:/home/user/projects/ .
(Recursively copies a directory from remote to local)
$ scp -r projects/ user@192.168.1.10:/home/user/
(Recursively copies a directory from local to remote)$ scp -P 2222 -i key.pem file.txt user@192.168.1.10:/tmp/
(Copies with custom port and SSH key)rsync — Fast Incremental File Transfer
Flags: -avz (archive, verbose, compress), -e "ssh -p 2222" (remote shell), --delete (delete extraneous files), --exclude (exclude patterns), --progress (show progress), -n (dry run)
Sync Local to Remote:
$ rsync -avz /local/projects/ user@192.168.1.10:/remote/backup/
sending incremental file list
created directory /remote/backup
project1/
project1/file1.txt
project1/file2.txt
project2/
project2/data.log
sent 12.34M bytes received 456 bytes 2.47M bytes/sec
total size is 12.34M speedup is 1.00Syncs a local directory to remote — only transfers changed files.
Sync Remote to Local:
$ rsync -avz user@192.168.1.10:/remote/logs/ /local/backup/
receiving incremental file list
log1.txt
log2.txt
sent 123 bytes received 456 bytes 115.80 bytes/sec
total size is 12345 speedup is 12.34Sync with Deletion:
$ rsync -avz --delete /local/ /remote/
(Deletes files on remote that don't exist locally)Exclude Files:
$ rsync -avz --exclude="*.tmp" --exclude="*.log" /local/ /remote/
(Excludes .tmp and .log files)Dry Run (Preview):
$ rsync -avzn /local/ /remote/
sending incremental file list
./
file1.txt
file2.txt
sent 123 bytes received 456 bytes 115.80 bytes/sec
total size is 12345 speedup is 12.34 (DRY RUN)
-nperforms a dry run — shows what would be transferred without actually doing it.
curl — Client URL (Data Transfer)
Flags: -X (method), -H (headers), -d (data), -o (output), -L (follow redirects), -k (ignore SSL), -I (headers only), -v (verbose), -O (output with remote name)
Basic HTTP GET:
$ curl https://api.github.com/orgs/google
{
"login": "google",
"id": 1234,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
"url": "https://api.github.com/orgs/google",
"repos_url": "https://api.github.com/orgs/google/repos",
"events_url": "https://api.github.com/orgs/google/events",
"hooks_url": "https://api.github.com/orgs/google/hooks",
"issues_url": "https://api.github.com/orgs/google/issues",
"members_url": "https://api.github.com/orgs/google/members{/member}",
...
}Fetches data from a URL — great for API testing.
HTTP POST with Data:
$ curl -X POST -H "Content-Type: application/json" -d '{"name":"test","value":123}' https://api.example.com/endpoint
{"id":12345,"status":"success"}Follow Redirects:
$ curl -L http://bit.ly/short-url
(Follows HTTP redirects)Download File:
$ curl -o output.txt https://example.com/file.txt
$ curl -O https://example.com/file.txt
# -O uses the remote filenameGet HTTP Headers Only:
$ curl -I https://google.com
HTTP/2 200
date: Thu, 15 Jan 2026 10:30:15 GMT
content-type: text/html; charset=UTF-8
content-length: 12345
server: gwswget — Web Downloader
Flags: -O (output), -c (continue), -b (background), -q (quiet), -r (recursive), -np (no parent), --limit-rate (throttle)
$ wget https://example.com/file.zip
--2026-01-15 10:30:15-- https://example.com/file.zip
Resolving example.com (example.com)... 93.184.216.34
Connecting to example.com (example.com)|93.184.216.34|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 123456789 (118M) [application/zip]
Saving to: ‘file.zip’
file.zip 100%[==============================>] 117.7M 2.45MB/s in 48s
2026-01-15 10:31:03 (2.45 MB/s) - ‘file.zip’ saved [123456789/123456789]Downloads a file from the internet.
Download with Custom Name:
$ wget -O custom_name.zip https://example.com/file.zipResume Interrupted Download:
$ wget -c https://example.com/file.zip
(Continues a partially downloaded file)Download in Background:
$ wget -b https://example.com/big_file.zip
Continuing in background, pid 1234
Output will be written to ‘wget-log’.Limit Download Speed:
$ wget --limit-rate=100k https://example.com/big_file.zip
(Limits speed to 100 KB/s)Network Troubleshooting
nmap — Network Scanner
Flags: -sP (ping scan), -sT (TCP scan), -sU (UDP scan), -p (ports), -O (OS detection), -A (aggressive)
$ nmap -sP 192.168.1.0/24
Starting Nmap 7.80 ( https://nmap.org ) at 2026-01-15 10:30 UTC
Nmap scan report for 192.168.1.1
Host is up (0.00045s latency).
Nmap scan report for 192.168.1.100
Host is up (0.00012s latency).
Nmap scan report for 192.168.1.50
Host is up (0.00078s latency).
Nmap done: 256 IP addresses (3 hosts up) scanned in 2.34 secondsFinds all active hosts on the network.
$ nmap -p 22,80,443 192.168.1.10
Starting Nmap 7.80 ( https://nmap.org ) at 2026-01-15 10:30 UTC
Nmap scan report for 192.168.1.10
Host is up (0.00045s latency).
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp closed httpsScans specific ports on a host.
$ nmap -A 192.168.1.10
(Aggressive scan — OS detection, version detection, script scanning, traceroute)tcpdump — Packet Capture
Flags: -i (interface), -n (numeric), -c (count), -w (write to file), -r (read from file), -v (verbose)
$ sudo tcpdump -i eth0 -n -c 10
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
10:30:15.123456 IP 192.168.1.100.45678 > 8.8.8.8.53: 12345+ A? google.com. (28)
10:30:15.123567 IP 8.8.8.8.53 > 192.168.1.100.45678: 12345 1/0/0 A 142.250.185.78 (44)
10:30:15.123678 IP 192.168.1.100.22 > 192.168.1.50.45678: Flags [P.], seq 123:456, ack 789, win 1234, length 333
10 packets captured
10 packets received by filter
0 packets dropped by kernelCaptures and displays network packets in real-time. Requires root privileges.
$ sudo tcpdump -i eth0 port 80
(Captures HTTP traffic only)$ sudo tcpdump -i eth0 host 192.168.1.50
(Captures traffic to/from a specific host)$ sudo tcpdump -i eth0 -w capture.pcap
(Captures and saves to a file for later analysis)$ tcpdump -r capture.pcap -n
(Reads and displays packets from a capture file)telnet — Test TCP Connections
Flags: (None — connects directly)
$ telnet google.com 80
Trying 142.250.185.78...
Connected to google.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: google.com
HTTP/1.1 200 OK
Date: Thu, 15 Jan 2026 10:30:15 GMT
Content-Type: text/html; charset=UTF-8
...Test TCP connectivity to a host/port. Good for testing if a service is responding.
$ telnet 192.168.1.10 22
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is '^]'.
SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.1(Shows SSH server version — confirms service is running)
nc (Netcat) — The Networking Swiss Army Knife
Flags: -l (listen), -p (port), -v (verbose), -z (zero IO - port scan), -u (UDP)
Port Scanning:
$ nc -zv 192.168.1.10 22
Connection to 192.168.1.10 22 port [tcp/ssh] succeeded!
$ nc -zv 192.168.1.10 80
Connection to 192.168.1.10 80 port [tcp/http] succeeded!
$ nc -zv 192.168.1.10 443
nc: connect to 192.168.1.10 port 443 (tcp) failed: Connection refusedScans if a port is open on a remote host.
Send a Test Message:
$ echo "Hello, world" | nc 192.168.1.10 1234
(Forwards "Hello, world" to port 1234 on 192.168.1.10)Listen for a Connection:
$ nc -l -p 1234
Hello, worldListens on port 1234 and prints any data received.
Transfer a File:
$ nc -l -p 1234 < file.txt (Sender: listen and send file)
$ nc 192.168.1.10 1234 > file.txt (Receiver: connect and receive)Chat Between Hosts:
$ nc -l -p 1234 (Host A: listen)
$ nc 192.168.1.10 1234 (Host B: connect)
(Type messages in either terminal — they'll show on the other)lsof — List Open Files
Flags: -i :80 (port 80), -u user (user), +D /path (recursive), -p PID (process)
$ lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 1234 root 6u IPv4 12345 0t0 TCP *:http (LISTEN)
nginx 5678 www-data 6u IPv4 12345 0t0 TCP *:http (LISTEN)
python 9012 bob 3u IPv4 67890 0t0 TCP 192.168.1.100:http->192.168.1.50:45678 (ESTABLISHED)Shows which process is using a specific port. Great for "port already in use" errors.
$ lsof -u bob
(Lists all open files for user bob)
$ lsof +D /var/log
(Lists all open files in /var/log recursively)
$ lsof -p 1234
(Lists all open files for process 1234)Quick Reference — Most Used Commands
| Command | Description |
|---|---|
ping google.com | Check if host is reachable |
ping -c 5 8.8.8.8 | Send 5 packets to 8.8.8.8 |
traceroute google.com | Trace network path to destination |
ip a | Show all IP addresses |
ip route | Show routing table |
ss -tulpn | Show all listening ports with process names |
curl https://api.example.com | Fetch data from a URL |
wget https://example.com/file.zip | Download a file |
ssh user@host | Connect to remote server via SSH |
scp file user@host:/path/ | Copy file to remote server |
rsync -avz /local/ remote:/backup/ | Sync directories |
nslookup google.com | Query DNS for IP address |
dig +short google.com | Quick DNS lookup |
lsof -i :80 | Find process using port 80 |
nmap -sP 192.168.1.0/24 | Scan network for active hosts |
tcpdump -i eth0 -n -c 10 | Capture 10 packets on eth0 |
The Nuclear Commands — DO NOT TYPE
These commands can break your network, crash your system, or compromise security.
| Command | What it does |
|---|---|
ping -f 8.8.8.8 | Flood ping — overwhelms target (DDoS) |
ip link set eth0 down | Takes your network interface offline (if on remote server, you lose connection) |
route del default | Removes default gateway — you lose internet access |
iptables -F | Flushes ALL firewall rules (opens everything) |
echo 1 > /proc/sys/net/ipv4/ip_forward | Enables IP forwarding (turns your server into a router — can cause network loops) |
| `:(){ : | :& };:` |
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Ctrl+C | Cancel/kill the current running command |
Ctrl+D | Log out of the current terminal or exit a shell |
Ctrl+Z | Suspend the current command (put it in the background) |
Tab | Auto-complete file names and commands |
!! | Re-run the last command (e.g., sudo !!) |
Ctrl+R | Reverse search through command history |
Additional Tips
-
The Man Pages: If you forget how a command works, type
man command(e.g.,man ping). Pressqto exit the manual. -
Check What's Listening: Always use
ss -tulpn(notnetstat) — it's faster and more modern. -
When
pingFails: ICMP might be blocked by firewalls. Trytelnet google.com 80orcurlto test connectivity. -
Use SSH Keys: Always use SSH keys instead of passwords for automation and security. Generate with
ssh-keygen. -
DNS Caching: If you just changed DNS records and they're not resolving, clear the cache:
sudo systemctl restart systemd-resolvedorsudo resolvectl flush-caches. -
Packet Capture:
tcpdumprequires root. For analysis, save to.pcapand open in Wireshark for detailed inspection. -
Port Forwarding with SSH: Use
-L(local) and-R(remote) to tunnel traffic securely through SSH. Great for accessing services behind firewalls. -
Check Public IP:
curl ifconfig.meorcurl icanhazip.comto get your public IP address. -
Network Speed Test: Use
speedtest-cli(install separately) to test internet bandwidth. -
MAC Address: Find MAC address with
ip link showorarp -n.
