Block IP Address in FreeBSD

by jagbir on November 11, 2008

The simple method is to add the offensive IP in your /etc/hosts.allow file and deny any access to that:

$ ee /etc/hosts.allow  (and add following line in it)
	all: <ip address> :deny

You can also use one quick and dirty hack:

$ route add <ip address>

All ACKs to specified IP address would be headed to, means going nowhere and no TCP connections could be established this way. No UDP or ICMP packets would reach the blocked IP address. You can also block a whole subnet this way. Though, it’ll not stop the traffic from that IP.

If you have ipfw installed, you can try this also:

$ ipfw add deny from <IP Address> to any

You may also like to read:
* 5 steps to secure your Linux Server
* Ensuring secure access to production Linux Servers
* Bash script to backup essential log files in Linux
* Quickly change your ssh port from defualt 22 to something higher
* SSH port forwarding from remote to local machine
* Save root or user history to check later
* Install and configure denyhost to prevent brute force attacks

Previous post:

Next post: