How to null route an IP or subnet in Linux

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

Published by

Rich

Just another IT guy.

One thought on “How to null route an IP or subnet in Linux”

  1. Sweet, glad I made a note of this. Just needed to use it to emulate a failure for a specific IP so I could test a failure scenario in a bash script.

Leave a Reply

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