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
| Command | Purpose |
|---|---|
ip addr show | Show interfaces and IP addresses |
ip link set <iface> up | Bring an interface up |
sudo ip addr add <ip>/<prefix> dev <iface> | Add an IP address (temporary) |
ip route show | Show the routing table |
sudo ip route add <network>/<prefix> via <gateway> | Add a static route (temporary) |
ip neigh show | Show the ARP / neighbour table |
nmcli device status | NetworkManager: device and connection status |
Connectivity and DNS
| Command | Purpose |
|---|---|
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> MX | Short lookup of mail servers |
host <name> | Simple DNS lookup |
cat /etc/resolv.conf | Show configured DNS servers |
Ports, sockets and traffic
| Command | Purpose |
|---|---|
ss -tulpn | Listening TCP and UDP ports with process |
ss -tn state established | Established TCP connections |
sudo tcpdump -i <iface> port 53 | Capture DNS traffic on an interface |
sudo tcpdump -i <iface> -w capture.pcap | Save 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
| Command | Purpose |
|---|---|
sudo ufw status verbose | Ubuntu: show firewall status and rules |
sudo ufw default deny incoming | Ubuntu: deny inbound by default |
sudo ufw allow 22/tcp | Ubuntu: allow SSH |
sudo ufw enable | Ubuntu: turn the firewall on |
sudo firewall-cmd --list-all | RHEL/Fedora: show active zone and rules |
sudo firewall-cmd --permanent --add-service=https | RHEL/Fedora: allow HTTPS permanently |
sudo firewall-cmd --reload | RHEL/Fedora: apply permanent rules |
sudo nft list ruleset | Show all nftables rules |
SSH and secure access
| Command | Purpose |
|---|---|
ssh <user>@<host> | Open an SSH session |
ssh-keygen -t ed25519 | Create 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 -t | Test the SSH server configuration |
sudo systemctl restart sshd | Restart the SSH service |
# /etc/ssh/sshd_config hardening lines
PermitRootLogin no
PasswordAuthentication no
MaxAuthTries 3
Users, permissions and logs
| Command | Purpose |
|---|---|
id | Current user and groups |
sudo -l | What the current user may run with sudo |
chmod 600 <file> | Owner read/write only |
chown <user>:<group> <file> | Change owner and group |
last | Recent logins |
sudo journalctl -u sshd --since today | Today’s SSH service log |
sudo tail -f /var/log/auth.log | Follow authentication log (Debian/Ubuntu) |
Real-world example: a web server nobody could reach
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.
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.