Block an IP address with null routes or with iptables on a Linux.

You can drop as IP address using the iptables command:

iptables -A INPUT -s 192.168.1.100 -j DROP
iptables -A OUTPUT -d 192.168.1.100 -j DROP

However, you can use route or ip command to a null route unwanted traffic. A null route is a network route or kernel routing table entry that goes nowhere.

route add 192.168.1.100 gw 127.0.0.1 lo

or reject 😉

route add -host 192.168.1.100 reject

Also we can drop entire subnet 192.168.1.0/24

route add -net 192.168.1.0/24 gw 127.0.0.1 lo

To delete an IP address or entire subnet from a null route use the following command:

route del 192.168.1.100 gw 127.0.0.1 lo

or

route del -net 192.168.1.0/24 gw 127.0.0.1 lo

or

route del -host 192.168.1.99 reject

Leave a Reply

Your email address will not be published. Required fields are marked *

*