How to block access to a server by IP address on Linux

Tuesday, July 6, 2010 posted by Till

Sometimes you might want to block connects to your server by IP address. E.g. when someone tries to attack your system. This can be done in several different ways, e.g. with iptables (firewall) rules or by setting up a reject route. Using iptables sometimes causes conflicts with installed firewalls so that I will use the route command here. The command is:

/sbin/route add -host 192.168.0.123 reject

Replace 192.168.0.123 with the IP address that you want to block and execute the command as root user on the shell.



3 Responses to “How to block access to a server by IP address on Linux”

  1. cms application says:

    hi…Thanks a lot for this one….!!!

  2. Oscar says:

    Where is the blocklist stored and/or how do I undo the blocking?

  3. Oscar says:

    Nevermind, I found out how.

    List blocked IP’s:
    route -n

    Remove blocked IP:
    route del 192.168.0.123 reject

Leave a Reply

*