How to configure networking with iptables and ufw
· Category: Linux
Short answer
iptables is the low-level Linux firewall; ufw provides a simpler frontend for common rules.
Steps
- Enable ufw:
sudo ufw enable
- Allow SSH:
sudo ufw allow ssh
- Allow a port:
sudo ufw allow 8080/tcp
- Deny all incoming:
sudo ufw default deny incoming
- List rules:
sudo ufw status numbered
Tips
- Always allow SSH before enabling the firewall to avoid lockout.
iptablesrules are not persistent by default; useiptables-persistentor equivalent.ufwis available on Debian/Ubuntu;firewalldis common on RHEL/CentOS.
Common issues
- Rule ordering matters in iptables; first match wins.
- Accidental lockout: use console access or scheduled disable commands to recover.