Linux Networking

Linux Networking

Task - Create a Setup so that you can ping google but not able to ping Facebook from the same system.

To complete this task we will modify our routing table in such a way that it can ping to Google but not Facebook.

So, first of all, we must have proper internet connectivity, initially, you check by pinging both Google and Facebook.

net connected.jpg

To check the default rules in the routing table, use command:-

route -n

route -n no changes.jpg

The first rule of the destination IP 0.0.0.0 is automatically created by the computer when we connect to the internet, according to which we can connect to any IP address in the world, but we want to create a setup from which can ping to Google only not to Facebook, so we have to delete this rule.

To delete this rule from the routing table we can use:-

route del -net 0.0.0.0

deleted 0.0.0.0.jpg

Now you can see this rule is deleted, we can neither ping to Google nor Facebook. But we want to create a setup which can ping to Google.

We know the IP of Google is 172.217.166.14 so if we try to ping this IP the computer won't create a packet for it:- pack not created.jpg

It is because the computer creates a packet for those IP address which are in the range of destination IP in the routing table.

Now we have to add Google IP address range into our routing table, to add a new rule to the routing table:-

route add -net 172.217.166.0 netmask 255.255.255.0 enp0s3

Now our routing table knows that the IP address in our destination range so if we use ping command, now our computer can create a packet for the IP but can't send it.

packet created unsucces.jpg The reason is that we haven't specified the gateway for the packet, Gateway is like the entry point of the packet into the system.

We have to specify the Gateway with the destination IP and netmask.

route add -net 172.217.166.0 netmask 255.255.255.0 gw 192.168.43.1 enp0s3

After running this command now we can successfully ping Google.

pinging successfully.jpg

You can see the total changes in the routing table.

changes in routing table.jpg

Now our task is completed, if we can ping Google successfully but not Facebook.

ping google but not facebook.jpg Our computer won't even create a single packet for Facebook but can successfully ping Google.

Thank you.