๐Ÿ“˜How to Allow or Block IP Addresses on Your VPS or Dedicated Server

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
Scroll to Top