Setup so that you can ping google but not Facebook from same system
So let’s start our task of pinging only google.com and not facebook.com 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
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 google.com
ping -4 facebook.com
Here we have used -4 to give priority to IPv4 protocol over Ipv6.
Now let’s delete the default gateway(0.0.0.0) so that system cannot connect to internet.The command for the same is —
route del -net 0.0.0.0
Since we have deleted the default gateway we cannot connect to the outer world.We can check by pinging command .
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 255.255.255.0 gw <system IP network name> (network card name)
route add -net 172.217.166.0 netmask 255.255.255.0 gw 192.168.29.1 enp0s3
Prior we deleted to universal ip address i.e 0.0.0.0 which connects with everyone.
After adding the route now try to ping to google and to facebook as below.
You can see above google.com is connected but facebook.com is not able to connect.
If you want to reverse the routing table as before just run the command —
route add -net 0.0.0.0 gw 192.168.29.1
Thank you All:)
Harsh Agrawal