Environment:
Linux-based VPS or Dedicated Server
Access Required: SSH (root or sudo access)
Tools Covered: iptables
, CSF, UFW, and firewalld
๐ข Allow an IP Address
๐น Using iptables
iptables -A INPUT -s IP-ADDRESS -j ACCEPT
๐น Using CSF (ConfigServer Security & Firewall)
csf -a IP-ADDRESS
๐น Using UFW (Uncomplicated Firewall)
ufw allow from IP-ADDRESS
๐น Using firewalld
firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='IP-ADDRESS' accept"
firewall-cmd --reload
โ
Replace IP-ADDRESS
with the actual IP you want to allow (e.g., 192.168.1.100
)
๐ด Block an IP Address
๐น Using iptables
iptables -A INPUT -s IP-ADDRESS -j DROP
๐น Using CSF
csf -d IP-ADDRESS
๐น Using UFW
ufw deny from IP-ADDRESS
๐น Using firewalld
firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='IP-ADDRESS' drop"
firewall-cmd --reload
โ
Replace IP-ADDRESS
with the actual IP you want to block.
๐ Final Steps and Notes
- iptables: Save rules to make them persist after reboot:
service iptables save
Or on Debian-based systems:netfilter-persistent save
- CSF: Reload the firewall after changes:
csf -r
- UFW: Enable UFW if itโs not already running:
ufw enable
- firewalld: Always reload after adding/removing rules:
firewall-cmd --reload