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 -j DROP
iptables -A OUTPUT -d -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 gw lo

or reject 😉

route add -host reject

Also we can drop entire subnet

route add -net gw lo

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

route del gw lo


route del -net gw lo


route del -host reject

Leave a Reply

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