Linux Cheatsheet

Networking

Use this Linux reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

Network Interface Status

ip addr                     # show all interfaces and IPs (modern)
ip addr show eth0           # specific interface
ip link                     # show interfaces (link layer)
ip link set eth0 up         # bring interface up
ip link set eth0 down       # bring interface down
ifconfig                    # legacy (net-tools; may not be installed)
ifconfig eth0               # specific interface

Routing

ip route                    # show routing table
ip route show               # same
ip route add default via 192.168.1.1        # set default gateway
ip route add 10.0.0.0/8 via 192.168.1.1    # add static route
ip route del 10.0.0.0/8                     # delete route
route -n                    # legacy routing table

DNS Lookup

dig example.com             # full DNS query output
dig example.com A           # A record only
dig example.com MX          # mail records
dig @8.8.8.8 example.com   # query specific DNS server
dig +short example.com      # IP only
dig -x 1.2.3.4              # reverse DNS lookup
nslookup example.com        # interactive or single-shot
host example.com            # quick lookup
resolvectl query example.com  # via systemd-resolved
cat /etc/resolv.conf        # DNS server config

Connectivity Testing

ping example.com                    # ICMP ping (ctrl+c to stop)
ping -c 4 example.com               # 4 packets only
ping -i 0.5 example.com             # 0.5s interval
ping6 ::1                           # IPv6 ping
traceroute example.com              # trace hops (ICMP/UDP)
traceroute -T example.com           # TCP traceroute (port 80)
mtr example.com                     # live traceroute + ping stats

Port and Connection Status

ss -tuln                    # TCP+UDP listening ports (no DNS)
ss -tulnp                   # with process name/PID
ss -s                       # summary
ss -ta                      # all TCP connections
ss -tnp state established   # established TCP with PIDs
netstat -tuln               # legacy (net-tools)
netstat -anp | grep :80     # connections on port 80 (legacy)
lsof -i :80                 # process using port 80
lsof -i TCP                 # all TCP connections
fuser 80/tcp                # PID on port 80

curl — HTTP Client

curl https://example.com                            # GET
curl -o file.html https://example.com               # save to file
curl -O https://example.com/file.zip                # save with remote filename
curl -L https://example.com                         # follow redirects
curl -I https://example.com                         # headers only (HEAD)
curl -v https://example.com                         # verbose (show headers)
curl -s https://example.com                         # silent (no progress)
curl -X POST -d '{"key":"val"}' -H "Content-Type: application/json" URL
curl -u user:pass https://example.com               # basic auth
curl -H "Authorization: Bearer TOKEN" URL           # bearer token
curl --retry 3 --retry-delay 2 URL                  # auto-retry
curl -k https://self-signed.example.com             # skip TLS verification
curl --limit-rate 1M -O URL                         # bandwidth cap

wget

wget https://example.com/file.zip
wget -O output.zip URL              # custom output filename
wget -c URL                         # resume partial download
wget -q URL                         # quiet mode
wget -r -l2 --no-parent URL         # recursive, depth 2
wget --mirror --convert-links URL   # mirror site

SSH

ssh user@host                       # connect
ssh -p 2222 user@host               # custom port
ssh -i ~/.ssh/id_ed25519 user@host  # specific key
ssh -L 8080:localhost:80 user@host  # local port forward
ssh -R 9090:localhost:3000 user@host  # remote port forward
ssh -D 1080 user@host               # SOCKS proxy
ssh -N -f -L 8080:db:5432 user@host  # background tunnel, no shell
ssh -J jump@bastion user@target     # jump host / ProxyJump
scp file.txt user@host:/path/       # copy to remote
scp user@host:/file.txt ./          # copy from remote
rsync -avz src/ user@host:/dst/     # sync files
rsync -avz --delete src/ host:/dst/ # sync + delete removed files

SSH Key Management

ssh-keygen -t ed25519 -C "comment"          # generate Ed25519 key
ssh-keygen -t rsa -b 4096                   # generate RSA key
ssh-copy-id user@host                       # install public key on remote
cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys  # manual install
ssh-add ~/.ssh/id_ed25519                   # add key to agent
eval $(ssh-agent)                           # start agent

~/.ssh/config example:

Host myserver
    HostName 1.2.3.4
    User alice
    Port 2222
    IdentityFile ~/.ssh/id_ed25519
    ServerAliveInterval 60

Host bastion
    HostName bastion.example.com
    User deploy

Host prod
    HostName 10.0.0.5
    ProxyJump bastion

Firewall (nftables / iptables / ufw)

# ufw (Ubuntu front-end)
ufw status                          # show status and rules
ufw enable / disable
ufw allow 22                        # allow SSH
ufw allow 80/tcp                    # allow HTTP
ufw allow from 192.168.1.0/24      # allow subnet
ufw deny 23                         # deny telnet
ufw delete allow 80/tcp             # remove rule
ufw reset                           # reset all rules

# iptables (classic)
iptables -L -n -v --line-numbers    # list all rules
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -j DROP           # default deny
iptables-save > /etc/iptables/rules.v4

# nftables (modern replacement)
nft list ruleset
nft add rule inet filter input tcp dport 80 accept

Network Configuration Files

PathPurpose
/etc/resolv.confDNS servers
/etc/hostsstatic hostname resolution
/etc/hostnamemachine hostname
/etc/network/interfacesDebian static config (ifupdown)
/etc/netplan/*.yamlUbuntu 18+ network config
/etc/NetworkManager/NetworkManager config
/etc/sysconfig/network-scripts/RHEL/CentOS interface config
# netplan example (/etc/netplan/01-eth.yaml)
networkctl status               # systemd-networkd status
nmcli device status             # NetworkManager status
nmcli connection show           # list connections
nmcli connection up "My Conn"   # activate connection
hostnamectl set-hostname myhost # set hostname