Mitigating DoS Attacks with a null (or Blackhole) Route on Linux

How to null routes work

When you define a route on a Linux/Unix system it tells the system in order to communicate with the specified IP address you will need to route your network communication to this specific place.

When you define a null route it simply tells the system to drop the network communication that is designated to the specified IP address. What this means is any TCP based network communication will not be able to be established as your server will no longer be able to send an SYN/ACK reply. Any UDP based network communication however will still be received; however your system will no longer send any response to the originating IP.

In less technical terms this means your system will receive data from the attackers but no longer respond to it.

Adding and Removing a null route

How to add a null route

In our example we are receiving unwanted SSH login attempts from

 root@server:~# netstat -na | grep :22
 tcp 0 0* LISTEN

To add the null route we will use the ip command

 root@server:~# ip route add blackhole

To verify the route is in place will will use ip route show

 root@server:~# ip route show
 default via dev eth0 metric 100

After a little while the established ssh connections will time out and all subsequent connections from the blocked ip will receive the following.

 baduser@attacker:~$ ssh
 ssh: connect to host port 22: No route to host

Removing a null route

After the attack has subsided or in case you add the wrong ip you may want to remove the blackhole route. To do so we will use theip command again.

 root@server:~# ip route del
 root@server:~# ip route show
 default via dev eth0 metric 100

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.