Creating a setup such that we can ping Google but not Facebook from the same system
Using firewall is the most common approach for this but we can make this happen without disturbing the firewall i.e. by using the Routing Table
Router:
A Router is a networking device that usually use to connect two or more than two different networks. This is the one which forwards data packet between different devices. For example, a router provides you internet access by connecting your LAN with the Internet.
Whenever a node sends data to another node on the network, it must first know where to send it. If the node is not directly connected, then it sends it via other nodes along a route to the destination node. Each node needs to keep track of way to deliver data, and for this, it uses a routing table.
Routing Table:
A routing table is a database that keeps track of paths, like a map, and uses these to determine which way to forward traffic. A routing table is a data file in RAM that is used to store route information about directly connected and remote networks. Nodes can also share the contents of their routing table with other nodes.
- To see the routing table :
route -n
This route table gives information of Destination IP, Gateway, Interface, Netmask, Metrics, etc. Here we can see that ,“0.0.0.0” is the default IP for connecting with the internet. The netmask 255.255.255.0 will tell us that 256 IPs can come under this network range. This is a pre-created gateway rule in the routing table which helps the system in creating the packets and sending them to the outside world.
Let us move forward to the task:
We can check the public IP of both Google and Facebook by using the nslookup command. Nslookup (stands for “Name Server Lookup”) is a useful command for getting information from DNS server. It is a network administration tool for querying the Domain Name System (DNS) to obtain domain name or IP address mapping or any other specific DNS record.
Editing my routing table:
First we delete the row of routing table which is used to connect to the Internet.
- Deleting the rule for connecting anywhere in internet :
route del -net 0.0.0.0
Now If we try to connect to the Internet, it never connects.
Now, let us add Google’s IP in routing table, so that we can connect to Google only.
route add -net 172.217.166.0 gw 192.168.43.1 netmask 255.255.255.0
- Let’s check if we can ping to Google or not:
- Now, let us find the IP of Facebook/any other site and try to ping: