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 220.127.116.11, type the following command at shell:
# route add 18.104.22.168 gw 127.0.0.1 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 22.214.171.124 reject
To confirm the null routing status, use the ip command as follows:
# ip route get 126.96.36.199
RTNETLINK answers: Network is unreachable
To drop entire subnet 188.8.131.52/24, type:
# route add -net 184.108.40.206/24 gw 127.0.0.1 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 220.127.116.11/29
# ip route add blackhole from 18.104.22.168
# ip rule add blackhole to 10.18.16.1/29
# 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 22.214.171.124
# route del -host 126.96.36.199 reject
Or use NA command to delete route:
# ip route delete 188.8.131.52/26 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!