Block IP Addresses With IPtables & APF

by Tweak on September 5, 2009
in Security, Servers

Have a user that keeps hammering your FTP or trying to login over and over and over again that you just want to ban and never see again? We’ll show a quick and dirty method to ban an IP address from the server.

We commonly receive questions like:
“I would like to ban that ip address to prevent the access to the server.
how can i ban that Ip address from the server?”

Simple !

Login to the server as root.

  1. If you are running iptables, you can enter:
    iptables -A INPUT -s IP_ADDRESS -j DROP
    Ex: Block IP 68.72.72.25
    iptables -A INPUT -s 68.72.72.25 -j DROP
  2. If you have APF firewall installed
    apf -d IP_ADDRESS
    Ex: Block IP 68.72.72.25
    apf -d 68.72.72.25
  3. When you reboot this IP ban will be removed, meaning the IP will no longer be banned anymore.
    If you have APF you can get around this by opening the deny hosts file.
    nano /etc/apf/deny_hosts.rules

    Scroll to the bottom and paste in the IP address.
    Ctrl+X then Y to save the changes and exit.

  4. Restart APF
    /etc/apf/apf -r

Share and Enjoy:
  • Add to favorites
  • Twitter
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Digg
  • del.icio.us
  • MySpace
  • Live
  • Yahoo! Buzz
  • PDF
  • email

Comments

One Response to “Block IP Addresses With IPtables & APF”

Post a Comment