How to Setup to Ping Google but not able to Ping Facebook from the same System

Let’s create the above-mentioned setup and I will walk you through step by step.

Note: This setup is done perfectly with Linux-based operating systems, so before performing this operation make sure you are using Linux operating systems like Ubuntu, Linux-mint, etc.

Before we begin, you have to understand some basic concepts of networking.

What is ping?

A ping is a signal sent to a host(or another computer) that requests a response.

It serves two primary purposes:

1) to check if the host is available and

2) to measure how long the response takes.

A ping request can be performed using a ping command, which is a standard command in most command-line interfaces. Several network utilities provide a ping feature, which allows you to ping a server by simply entering the IP address or domain name.

pinging google means checking whether we able to connect with google server or not

For example,

To perform a ping command from a command-line interface, simply type “ping” followed by the IP address or domain name of the host you want to ping (e.g., ping google.com).

What is routing tables?
A routing table is a set of rules, often viewed in table format, that is used to determine where data packets traveling over an Internet Protocol (IP) network will be directed. All IP-enabled devices, including routers and switches, use routing tables. See below a Routing Table:

Destination      Subnet mask         Interface
128.75.43.0 255.255.255.0 Eth0
128.75.43.0 255.255.255.128 Eth1
192.12.17.5 255.255.255.255 Eth3
default Eth2

The entry corresponding to the default gateway configuration is a network destination of 0.0.0.0 with a network mask (netmask) of 0.0.0.0. The Subnet Mask of the default route is always 255.255.255.255.

To show the routing table, type: route -n

Let’s, create our setup

Here, I am using a Linux operating system that is able to ping to both website

Step1: Let’s check whether we are able to ping to both website or not

Type: ping www.google.com to ping with Google

Type: ping www.facebook.com to ping with Facebook

Check Routing Table

Step2: To view your current routing table,

Type: route -n

Step3: Now, check the IP of google using the nslookup command

Type: nslookup www.google.com to get the Google IP

Type: nslookup www.facebook.com to get the Facebook IP

Step4: Now, delete the default routing rule from the routing table

Type: route del -net 0.0.0.0 to delete default gateway rule

We have just deleted the internet gateway rule from the routing table. Now if you try to ping google or anything it won’t ping.

That is we just lost our internet connection by deleting the routing rule.

Step5: Now, we create a rule for only ping www.goggle.com but not Facebook

Type: route add -net 172.217.166.100 netmask 255.255.255.0 gw 192.168.43.1 enp0s3

and you can see the rule is attached to the routing table by typing: route -n

That means,

route add -net ip_of_google_that_we_get_earlier netmask 255.255.255.0 gw google_server_ip your_network_interface_name(ie, here in this case, enpos3)

To get the google_ip and google_Server_ip:

Type: nslookup www.google.com

To get the network_interface_name:

Type: ifconfig

It displays information about all network interfaces currently in operation and the output resembles the following:

Step6: Now, try to ping to google

Type: ping www.google.com, now its start working

Now let's see if we can ping Facebook, it will not work because we add the rule only for connecting with google, not able to connect with any other websites.

Hope you like it.

Thank You!

Python Enthusiast