How to null route an IP or subnet in Linux

This article was posted more than 1 year ago. Please keep in mind that the information on this page may be outdated, insecure, or just plain wrong today.

Quick tip for null routing an IP or subnet in Linux.
My method I’ve always used is:

route add -host 1.2.3.4 reject

For a subnet:

route add -net 1.2.3.0 netmask 255.255.255.0 reject

To remove the null route, you simply replace add with del.

route del -host 4.2.2.2 reject