Free tech learning for everyone, from basics to pro

Network FundamentalsNetworking SecurityBeginner

Linux networking and security commands

In short: A quick reference of the Linux commands network and security engineers use most, grouped by task. Commands only.

Commands only. Replace values in angle brackets such as <ip> with your own. Only run commands on systems you own or are authorised to manage.

Interfaces, addresses and routes

CommandPurpose
ip addr showShow interfaces and IP addresses
ip link set <iface> upBring an interface up
sudo ip addr add <ip>/<prefix> dev <iface>Add an IP address (temporary)
ip route showShow the routing table
sudo ip route add <network>/<prefix> via <gateway>Add a static route (temporary)
ip neigh showShow the ARP / neighbour table
nmcli device statusNetworkManager: device and connection status

Connectivity and DNS

CommandPurpose
ping -c 4 <ip>Send four ICMP echo requests
traceroute <ip>Show each hop to a destination
mtr <ip>Live combined ping and traceroute
dig <name>Detailed DNS lookup
dig +short <name> MXShort lookup of mail servers
host <name>Simple DNS lookup
cat /etc/resolv.confShow configured DNS servers

Ports, sockets and traffic

CommandPurpose
ss -tulpnListening TCP and UDP ports with process
ss -tn state establishedEstablished TCP connections
sudo tcpdump -i <iface> port 53Capture DNS traffic on an interface
sudo tcpdump -i <iface> -w capture.pcapSave a capture for Wireshark
nmap -sV <ip>Scan your own host for open ports and service versions
curl -I https://<host>Fetch only the HTTP response headers

Host firewall

CommandPurpose
sudo ufw status verboseUbuntu: show firewall status and rules
sudo ufw default deny incomingUbuntu: deny inbound by default
sudo ufw allow 22/tcpUbuntu: allow SSH
sudo ufw enableUbuntu: turn the firewall on
sudo firewall-cmd --list-allRHEL/Fedora: show active zone and rules
sudo firewall-cmd --permanent --add-service=httpsRHEL/Fedora: allow HTTPS permanently
sudo firewall-cmd --reloadRHEL/Fedora: apply permanent rules
sudo nft list rulesetShow all nftables rules

SSH and secure access

CommandPurpose
ssh <user>@<host>Open an SSH session
ssh-keygen -t ed25519Create an SSH key pair
ssh-copy-id <user>@<host>Install your public key on a server
scp <file> <user>@<host>:<path>Copy a file over SSH
sudo sshd -tTest the SSH server configuration
sudo systemctl restart sshdRestart the SSH service
# /etc/ssh/sshd_config hardening lines
PermitRootLogin no
PasswordAuthentication no
MaxAuthTries 3

Users, permissions and logs

CommandPurpose
idCurrent user and groups
sudo -lWhat the current user may run with sudo
chmod 600 <file>Owner read/write only
chown <user>:<group> <file>Change owner and group
lastRecent logins
sudo journalctl -u sshd --since todayToday’s SSH service log
sudo tail -f /var/log/auth.logFollow authentication log (Debian/Ubuntu)

Real-world example: a web server nobody could reach

A Linux troubleshooting orderip addrinterface andaddressip routedefault routepingreachabilitydigDNS answersss -tulpnlisteningservices
Figure 1. A practical order for Linux network checks: interface, routes, reachability, DNS, then the service itself.

A small web design agency moved its staging website to a new Linux virtual machine, and clients reported that the site timed out. The administrator logged in over the console and checked step by step. ip addr and ip route showed the right address and default route, and ping to the gateway worked. dig confirmed the site name pointed at the new server. ss -tulpn showed the web server listening on port 443, so the service was running.

That left the host firewall. Listing the rules showed only SSH was allowed inbound; the new machine had been built from a hardened template. Adding a rule for HTTPS fixed the problem in seconds. The administrator then updated the build checklist so the next server would not repeat the mistake.

Key takeaways

  • ip addr, ip route and ip neigh replace ifconfig, route and arp.
  • ss -tulpn shows listening ports and the process behind them.
  • Use ufw or firewall-cmd to keep a default-deny host firewall.
  • Use SSH keys, disable root and password logins.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.