How to disable ping to a website using Linux?
In this article we are going to create a customized network setup, to restrict accessing specific sites.
Suppose we want to access Google and don’t want to access Facebook, for this we need to create a customized network setup by configuring some routing rules for our system router. So let’s come to some terms regarding networking:
Entries of an IP Routing Table:
A routing table contains the information necessary to forward a packet along the best path toward its destination. Each packet contains information about its origin and destination. Routing Table provides the device with instructions for sending the packet to the next hop on its route across the network.
Each entry in the routing table consists of the following entries:
- Network ID: The network ID or destination corresponding to the route.
- Net Mask: It is the ID that helps to know the network name.
Below is the implementation
Let’s start and move ahead to the implementation part:
Step 1: Check the rules available in the routing table.
To check the rules present in the routing table, we use the command route -n. Here we have a rule in the very first row 0.0.0.0 that allows us to access or ping any site, so to restrict the connectivity to Facebook we will delete this rule with the command route del -net 0.0.0.0\
route del -net 0.0.0.0
Step 2: Check the network name for Google and Facebook
So now to check the network name we use the command:
Step 3: Check connectivity to the network
To check the connectivity we will ping the address which we get from the last step.
Step 4: Add a rule to connect to Google
To add a rule to connect to Google we will use the command route add -net 188.8.131.52 netmask 255.255.255.0 gw 192.168.43.1 enp0s8
Step 5: Check the connectivity to Google
We use the ping command here and check the connectivity.
Step 6: Check the connectivity to Facebook
Not connected to Facebook. Hence we achieved our setup. Just like this, we can achieve any type of customized network setup by adding specific rules in the routing table and restrict them.