Setup so that you can ping google but not Facebook from same system

Task to be performed

So let’s start our task of pinging only and not by doing some minor changes in Routing table

Routing Table

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

To see Routing table —

  • In Windows command is — route print
  • In Linux command is — route -n
Routing table on RHEL8

On a RHEL8 system, the route -n command displays the routing table with the following fields:

  • Destination — The destination network (or host).
  • Gateway — The gateway to use to reach the specified destination.
  • Flags — The flags describe certain characteristics of this route. The possible flag values are:

U— Indicates that the route is up and operational.

H — Indicates this is a route to a specific host (most routes are to networks).

G — Means the route uses a gateway. The system’s network interfaces provide routes to directly connected networks. All other routes use remote gateways. Directly connected networks do not have the G flag set; all other routes do.

D — Means that this route was added because of an ICMP Redirect Message. When a system learns of a route via an ICMP Redirect, it adds the route to its routing table, so that additional packets bound for that destination will not need to be redirected. The system uses the D flag to mark these routes.

  • Ref — The number of times the route has been referenced to establish a connection.
  • Use — The number of packets transmitted via this route.
  • Interface — The name of the network interface used by this route.

Now let’s ping to google and facebook to check the connectivity.Command to check the same is -

ping -4
ping -4

Here we have used -4 to give priority to IPv4 protocol over Ipv6.

pinging to
pinging to

Now let’s delete the default gateway( so that system cannot connect to internet.The command for the same is —

route del -net
deleting the default gateway

Since we have deleted the default gateway we cannot connect to the outer world.We can check by pinging command .

Checking the connectivity

To ping to google(or any other website) we need to add public ip address in the routing table primarily and gateway and netmask so that our system can connect to goole with given gateway.

Command format to add ip address and all is —

route add -net <google’s IP network > netmask gw <system IP network name> (network card name)

route add -net netmask gw enp0s3

Prior we deleted to universal ip address i.e which connects with everyone.

After adding the route now try to ping to google and to facebook as below.

You can see above is connected but is not able to connect.

If you want to reverse the routing table as before just run the command —

route add -net gw

Thank you All:)

Harsh Agrawal



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store