How to Block Outgoing Connections using iptables

By | July 19, 2008

Sometimes you should prevent outgoing connections from your server. The best way to do it is to use Linux system options, especially ipchains and iptables. I will show you how to do it using iptables, as this is the shortest way I know.

In order to block outgoing connections from your server to one IP issue the following command using command line:

iptables -A OUTPUT -d <IP Here> -j DROP

You can add whole subnets using this command. For example, if you need to block a subnet, the command will look like:

iptables -A OUTPUT -d 192.168.0.0/16 -j DROP

This will block all IPs from 192.168.x.x.

You might want to use the same method with incoming connec6tions. All you need to know is the IP range you need to block. You should just change OUTPUT to INPUT in the command above.