Create a setup so that one can ping only to google and not to facebook

Devashish Kumar Pan
3 min readMar 14, 2021

Creating a setup so that the system can ping to only google and not to facebook can be done by using a simple networking concept called routing.

What is routing?

In packet switching networks, routing is the higher-level decision making that directs network packets from their source toward their destination through intermediate network nodes by specific packet forwarding mechanisms. Packet forwarding is the transit of network packets from one network interface to another.

Every OS has its own internal routing table. Every computer attached to a network requires some type of routing instructions for network TCP/IP packets when they leave the local host. This is usually very straight forward because most network environments are very simple and there are only two options for departing packets. All packets are sent either to a device on the local network or to some other, remote network.

The routing table provides the configuration information required decisions about where to route TCP/IP data packets. The route -n command lists the routing table.

[dk1998@master ~]$ route -n

The output of a typical routing table in Linux system is given above.

Now on to the demo to create a routing table so that the system can ping to google only and not to facebook.

First lets check if the system can ping to google and facebook and if the routing table is correct.

route -n
ping -4 www.google.com
ping -4 www.facebook.com

Using the above commands we can check if the system can ping to google and facebook and if the routing table is correct.

Do note the IP address of google server. Here, we have 172.217.163.100 .

nslookup www.google.com
nslookup www.facebook.com

Now onto the steps for the demo.

Step 1: Delete the default route to public network.

The default route in IIPv4 is designated as the zero-address 0.0. 0.0/0 in CIDR notation. The subnet mask is given as /0 specifies all networks. So, the routing rule specifies all public network through the default gateway.

Now lets see if we can ping to facebook and google.

ping -4 www.google.com
ping -4 www.facebook.com

Step 2: Now we create a new routing rule using the IP we got from the checking step, so that the system can only boot to the google server.

sudo route add -net 172.217.0.0/16 gw 192.168.43.1 wlp10s0#route add -net <host_name>/16 gw <gatewayIP> <Interface_name>

Now we check if the setup is working or not.

ping -4 www.google.com
ping -4 www.facebook.com

We can clearly see that the setup is working and we can ping to google and not to facebook.

THANK YOU FOR READING!!!!!

--

--