How do I drop or block attackers IP with null routes?

How do I drop or block attackers IP with null routes?

In this tutorial I will show you, how to block attackers IP in Linux, so how do I drop or block attackers IP with null routes?

Someone might attack your Linux based system. You can drop attacker IP using IPtables. However, you can use the route or ip command to null route unwanted traffic. A null route (also called as blackhole route) is a network route or kernel routing table entry that goes nowhere. Matching packets are dropped (ignored) rather than forwarded, acting as a kind of very limited firewall. The act of using null routes is often called blackhole filtering.

You can null route (like some time ISP do prevent your network device from sending any data to a remote system) stopping various attacks coming from a single IP (read as spammers or hackers IP) using the following syntax on a Linux based system.

Nullroute IP using route command

Suppose that bad IP is, type the following command at shell:
# route add gw lo
You can verify it with the following command:
# netstat -nr
# route -n
You can also use reject target (a hat tip to Gabriele):
# route add -host IP-ADDRESS reject
# route add -host reject

To confirm the null routing status, use the ip command as follows:
# ip route get

RTNETLINK answers: Network is unreachable

To drop entire subnet, type:
# route add -net gw lo

Null routing using ip command

While traversing the RPDB, any route lookup which matches a rule with the blackhole rule type will cause the packet to be dropped. No ICMP will be sent and no packet will be forwarded. The syntax is follows for the ip command:
# ip route add blackhole
# ip route add blackhole from
# ip rule add blackhole to
# ip route

How do I remove null routing? How do I remove blocked IP address?

Simple use the route delete command as follows:
# route delete
# route del -host reject
Or use NA command to delete route:
# ip route delete dev eth0

This is cool, as you do not have to play with iptables rules as described here.

Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!

Enjoyed this video?
How do I drop or block attackers IP with null routes?
"No Thanks. Please Close This Box!"