How to Block a Specific IP Address using Routing Table in CentOS 8

The Linux routing table can block the incoming connection to prevent the Denial of Service (DoS) and save resource utilization. The Linux routing tables can used to block such IP addresses or whole sub net with reject route and null route.

This article describes How to Block a Specific IP Address using Routing Table in CentOS 8.

Block a Specific IP Address: Run the following command to block a Specific IP Address:

[[email protected] ~]# route add -host 192.168.43.15 reject

Verify the Changes: Run the following command to verify the changes:

[[email protected] ~]# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

0.0.0.0         192.168.43.1    0.0.0.0         UG    100    0        0 enp0s3

192.168.43.0    0.0.0.0         255.255.255.0   U     100    0        0 enp0s3

192.168.43.15                  255.255.255.255 !H    0              0 –

Remove Blocked IP Address: Run the following command to allow access for blocked IP Address:

[[email protected] ~]# route del -host 192.168.43.15 reject

Verify the Changes: Run the following command to verify the changes:

[[email protected] ~]# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

0.0.0.0         192.168.43.1    0.0.0.0         UG    100    0        0 enp0s3

192.168.43.0    0.0.0.0         255.255.255.0   U     100    0        0 enp0s3

Done!!! Specific IP addresses can be blocked or unblocked using route command. Change IP address according to the environment.

Leave a Reply