Today we will create a setup such that our system is able to ping Google but not Facebook by editing routes in routing table.
A routing table is the place where routing information is stored that contains routing entries or list of destinations. If a system tries to connect or ping to some other system with an IP address (destination IP), it first go to this routing table and if there is some rule which is allowing that destination then only network packets will be created otherwise not.
We can use route -n command to see rules or routes available in the routing table.
Let’s find out one of the IP addresses of google and Facebook, using nslookup command.
So, we have the two IP addresses. Now if we try to ping them we are able to do it as shown in the image below,
We were able to do so because of the first route there in the routing table which allow to connect with any IP in the world through the gateway or helps to connect to internet.
So we are deleting this route,
route del -net 0.0.0.0
Now if we try to ping google or facebook IP, it will directly say unreachable without creating any packets because no such route is available in the routing table.
We are adding a route now so that only google’s IP address is pingable.
route add -net 220.127.116.11 gateway 192.168.43.91 netmask 255.255.255.0 enp0s3
In other words we adding route for destination IP in range of 18.104.22.168/24 for our network card enp0s3 and the gateway IP is same as before
After this, if we now try to ping IP of google then it is pinging but the IP of Facebook is unreachable as shown below in the screenshot.
Finally, we have done this setup by editing the routes and it is working.