New batchZero to DevOps starts 29 Nov · limited seatsReserve your seat
Cheat sheetsLinuxLinux
FreeSheet 03 of 7

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)

LayerPurposeExample Protocols
7: ApplicationUser-facing servicesHTTP, SSH, DNS, FTP
4: TransportEnd-to-end communicationTCP, UDP
3: NetworkRouting and addressingIP, ICMP, ARP
2: Data LinkPhysical addressingEthernet, MAC addresses
1: PhysicalCables, switches, Wi-FiEthernet cables, radio waves

Common Ports

PortProtocolService
22TCPSSH (Secure Shell)
80TCPHTTP (Web)
443TCPHTTPS (Secure Web)
53TCP/UDPDNS (Domain Name System)
25TCPSMTP (Email)
3306TCPMySQL
5432TCPPostgreSQL
6379TCPRedis
27017TCPMongoDB

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)

bash
$ 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 ms

Checks if a host is reachable and measures round-trip time. Press Ctrl+C to stop.

bash
$ 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 5 sends exactly 5 packets then stops.

bash
$ ping -i 0.5 google.com
(Pings every 0.5 seconds instead of the default 1 second)
bash
$ 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)

bash
$ 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 ms

Traces the network path to a destination, showing each hop.

bash
$ 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

-n skips DNS lookups — much faster.

bash
$ traceroute -I google.com
(Uses ICMP instead of UDP — often works better with firewalls)

tracepath — Trace Path Without Root Privileges

bash
$ 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 5

Similar to traceroute but doesn't require root privileges.


mtr — My TraceRoute (Combines ping + traceroute)

Interactive Keys: r (reset), d (toggle display), q (quit)

bash
$ 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.3

Combines ping and traceroute in real-time. Shows packet loss and latency per hop.


Network Configuration

ip — Modern Network Configuration

Subcommands:

CommandDescription
ip a or ip addrShow IP addresses
ip linkShow network interfaces
ip routeShow routing table
ip neighShow ARP table
ip -s linkShow interface statistics

Show IP Addresses:

bash
$ 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 forever

Shows all IP addresses assigned to all network interfaces.

Show Specific Interface:

bash
$ 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 forever

Bring Interface Up/Down:

bash
$ ip link set eth0 up
(Brings eth0 online)

$ ip link set eth0 down
(Takes eth0 offline)

Add IP Address:

bash
$ 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:

bash
$ 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 100

Shows the routing table — where traffic is directed.

Add/Remove Routes:

bash
$ 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:

bash
$ 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 REACHABLE

Shows the ARP table (IP-to-MAC address mappings).

Interface Statistics:

bash
$ 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       0

ifconfig — Legacy Network Configuration (Deprecated)

Note: ifconfig is deprecated. Use ip instead.

bash
$ 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 0

DNS & Name Resolution

nslookup — Query DNS Servers

Interactive Commands: set type=MX, set type=NS, server 8.8.8.8

bash
$ 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.80

Queries DNS for IP addresses of a domain name.

bash
$ 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=MX shows mail exchange (MX) records.

bash
$ 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=NS shows name server (NS) records.

bash
$ 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)

bash
$ 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: 55

Detailed DNS query with full response.

bash
$ dig +short google.com
142.250.185.78

+short gives only the IP address — great for scripting.

bash
$ 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

+trace shows the full delegation path from root servers.

bash
$ dig -x 8.8.8.8 +short
dns.google.

Reverse DNS lookup — finds domain name from IP.

bash
$ dig ANY google.com
(Shows ALL record types for the domain)

host — Simple DNS Lookup

bash
$ 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.

bash
$ 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.

-t specifies record type (A, AAAA, MX, NS, etc.)

bash
$ 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

bash
$ 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)

bash
$ 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:

bash
$ 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 80

Show TCP Connections Only:

bash
$ 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:56789

Show UDP Connections Only:

bash
$ 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:

bash
$ 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)

bash
$ 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-resolve

arp — Address Resolution Protocol Cache

Flags: -n (numeric), -a (show all), -d (delete entry)

bash
$ 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                     eth0

Shows 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:

bash
$ 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:

bash
$ ssh -p 2222 user@192.168.1.10
(Connects on port 2222 instead of default 22)

Use Identity File (SSH Key):

bash
$ ssh -i ~/.ssh/private_key.pem user@192.168.1.10
(Connects using SSH key instead of password)

Execute Remote Command:

bash
$ 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.log

Runs a single command on the remote server and returns the output.

Local Port Forwarding (Tunneling):

bash
$ 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:

bash
$ ssh -R 8080:localhost:80 user@192.168.1.10
(Forward remote port 8080 to local port 80)

SOCKS Proxy:

bash
$ 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)

bash
$ scp file.txt user@192.168.1.10:/home/user/
file.txt                                      100% 1234    1.2MB/s   00:00

Copies a file to a remote server.

bash
$ scp user@192.168.1.10:/home/user/remote_file.txt .
remote_file.txt                              100% 4567    2.3MB/s   00:00

Downloads a file from a remote server.

bash
$ 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)
bash
$ 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:

bash
$ 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.00

Syncs a local directory to remote — only transfers changed files.

Sync Remote to Local:

bash
$ 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.34

Sync with Deletion:

bash
$ rsync -avz --delete /local/ /remote/
(Deletes files on remote that don't exist locally)

Exclude Files:

bash
$ rsync -avz --exclude="*.tmp" --exclude="*.log" /local/ /remote/
(Excludes .tmp and .log files)

Dry Run (Preview):

bash
$ 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)

-n performs 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:

bash
$ 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:

bash
$ curl -X POST -H "Content-Type: application/json" -d '{"name":"test","value":123}' https://api.example.com/endpoint
{"id":12345,"status":"success"}

Follow Redirects:

bash
$ curl -L http://bit.ly/short-url
(Follows HTTP redirects)

Download File:

bash
$ curl -o output.txt https://example.com/file.txt
$ curl -O https://example.com/file.txt
# -O uses the remote filename

Get HTTP Headers Only:

bash
$ 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: gws

wget — Web Downloader

Flags: -O (output), -c (continue), -b (background), -q (quiet), -r (recursive), -np (no parent), --limit-rate (throttle)

bash
$ 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:

bash
$ wget -O custom_name.zip https://example.com/file.zip

Resume Interrupted Download:

bash
$ wget -c https://example.com/file.zip
(Continues a partially downloaded file)

Download in Background:

bash
$ wget -b https://example.com/big_file.zip
Continuing in background, pid 1234
Output will be written to ‘wget-log’.

Limit Download Speed:

bash
$ 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)

bash
$ 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 seconds

Finds all active hosts on the network.

bash
$ 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 https

Scans specific ports on a host.

bash
$ 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)

bash
$ 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 kernel

Captures and displays network packets in real-time. Requires root privileges.

bash
$ sudo tcpdump -i eth0 port 80
(Captures HTTP traffic only)
bash
$ sudo tcpdump -i eth0 host 192.168.1.50
(Captures traffic to/from a specific host)
bash
$ sudo tcpdump -i eth0 -w capture.pcap
(Captures and saves to a file for later analysis)
bash
$ tcpdump -r capture.pcap -n
(Reads and displays packets from a capture file)

telnet — Test TCP Connections

Flags: (None — connects directly)

bash
$ 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.

bash
$ 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:

bash
$ 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 refused

Scans if a port is open on a remote host.

Send a Test Message:

bash
$ echo "Hello, world" | nc 192.168.1.10 1234
(Forwards "Hello, world" to port 1234 on 192.168.1.10)

Listen for a Connection:

bash
$ nc -l -p 1234
Hello, world

Listens on port 1234 and prints any data received.

Transfer a File:

bash
$ 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:

bash
$ 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)

bash
$ 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.

bash
$ 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

CommandDescription
ping google.comCheck if host is reachable
ping -c 5 8.8.8.8Send 5 packets to 8.8.8.8
traceroute google.comTrace network path to destination
ip aShow all IP addresses
ip routeShow routing table
ss -tulpnShow all listening ports with process names
curl https://api.example.comFetch data from a URL
wget https://example.com/file.zipDownload a file
ssh user@hostConnect to remote server via SSH
scp file user@host:/path/Copy file to remote server
rsync -avz /local/ remote:/backup/Sync directories
nslookup google.comQuery DNS for IP address
dig +short google.comQuick DNS lookup
lsof -i :80Find process using port 80
nmap -sP 192.168.1.0/24Scan network for active hosts
tcpdump -i eth0 -n -c 10Capture 10 packets on eth0

The Nuclear Commands — DO NOT TYPE

These commands can break your network, crash your system, or compromise security.

CommandWhat it does
ping -f 8.8.8.8Flood ping — overwhelms target (DDoS)
ip link set eth0 downTakes your network interface offline (if on remote server, you lose connection)
route del defaultRemoves default gateway — you lose internet access
iptables -FFlushes ALL firewall rules (opens everything)
echo 1 > /proc/sys/net/ipv4/ip_forwardEnables IP forwarding (turns your server into a router — can cause network loops)
`:(){ ::& };:`

Keyboard Shortcuts

ShortcutAction
Ctrl+CCancel/kill the current running command
Ctrl+DLog out of the current terminal or exit a shell
Ctrl+ZSuspend the current command (put it in the background)
TabAuto-complete file names and commands
!!Re-run the last command (e.g., sudo !!)
Ctrl+RReverse search through command history

Additional Tips

  1. The Man Pages: If you forget how a command works, type man command (e.g., man ping). Press q to exit the manual.

  2. Check What's Listening: Always use ss -tulpn (not netstat) — it's faster and more modern.

  3. When ping Fails: ICMP might be blocked by firewalls. Try telnet google.com 80 or curl to test connectivity.

  4. Use SSH Keys: Always use SSH keys instead of passwords for automation and security. Generate with ssh-keygen.

  5. DNS Caching: If you just changed DNS records and they're not resolving, clear the cache: sudo systemctl restart systemd-resolved or sudo resolvectl flush-caches.

  6. Packet Capture: tcpdump requires root. For analysis, save to .pcap and open in Wireshark for detailed inspection.

  7. Port Forwarding with SSH: Use -L (local) and -R (remote) to tunnel traffic securely through SSH. Great for accessing services behind firewalls.

  8. Check Public IP: curl ifconfig.me or curl icanhazip.com to get your public IP address.

  9. Network Speed Test: Use speedtest-cli (install separately) to test internet bandwidth.

  10. MAC Address: Find MAC address with ip link show or arp -n.


Next in LinuxPackage Managers Pro