Can I ping to Google but Not Facebook?

Published by Anubhav Singh on

Ever Imagine you can control the server connection of your system. This means you can ping Google but not to Facebook at the same time.

Ya… I am saying right you can easily do this and today I am going to discuss with you how we can actually set an environment where our system will be able to connect with Google but not with Facebook.

In this small hack, we are going to use some simple networking concepts. Don’t worry if you don’t have any knowledge about networking. We are going to discuss all with very basics.


  • An operating system
  • A stable internet connection

I am going to work on RedHat as our operating system, you can choose whatever you want.

Before jumping into the practical confirm that you have a stable connection by pinging to Google or Facebook or any other public IP.

Procedure to setup:

Step-1: Check your routing table

In RedHat OS, we have the following command to get info about our routing table.

route -n

The routing table is a data table stored in the network host(in our case it is our VM) that lists the routes to particular network destinations.

In simpler manner we can understand that routing table keep the information of path of the destination where that network provider can connect.

You will find there is a row having destination that means it can connect to anywhere in the world. Now we just have to change it with Google IP so we can connect only with Google.

Step-2: Get the IP of google

Using below command you can easily find the address of google.


Step-3: Remove destination

Once we get the IP of Google, our next step is to delete the route table info allowing all traffic to connect, i.e. We can easily remove that by using the following command.

route del -net

Now you don’t have permission to connect with the public world, you can check using

ping or ping

Step-4: Add google IP to our routing table

To add the google IP we will use following command

route add -net netmask gw

NOTE: In my case Google IP is and I place 0 at the end because if any other IP comes in the range of this can connect, due to multiple servers of Google.
◾For gw(Gateway), I looked in the detail of the routing table where we don’t have deleted our row.

Step-5: Again ping to both

Once the routing table is updated you can check using

route -n

You can now try to ping Google and Facebook again and now what you will find you will easily connect with Google but not with Facebook.

That’s it

We have completed our task.


Final Voice

In this task, we have made an environment where we can connect with Google but not with Facebook. Similarly, we can add multiple routes.

Comment down below on how the task was. Share with your friends. Stay connected with us for more amazing tasks.

Categories: Linux


Leave a Reply

Your email address will not be published. Required fields are marked *