Create a setup that would ping Google but not Facebook from same system
Robin Kumar
Software Engineer @Oracle || Ex - @wipro || Java ||Spring Boot || MySQL || Docker || Kafka || Angular || AWS DVA-C02 || AWS CLF-C02
Content of this Blog
- Basic Concepts
- Setup Procedure
Basic Concepts
Before understanding procedure required for the setup, let’s understand the basic terminologies regarding the same
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.
- It contains the information necessary to forward a packet along the best path toward its destination. Each packet contains information about its origin and destination.
- When a packet is received, a network device examines the packet and matches it to the routing table entry providing the best match for its destination. The table then provides the device with instructions for sending the packet to the next hop on its route across the network.
Netmask
- Netmasks (or subnet masks) are a shorthand for referring to ranges of consecutive IP addresses in the Internet Protocol. They used for defining networking rules in e.g. routers and firewalls.
Gateway
- Gateway is a network connecting device that can be used to connect two devices in two different networks implementing different networking protocols and overall network architecture.
route command
- route command in Linux is used to set up static routes to specific hosts or networks via an interface and for showing or updating the IP/kernel routing table.
Prerequisite
? You Need One VM(Virtual Machine) (Here I am using Redhat VM in VirtualBox)that has internet connectivity.
Solution ??
? Here we need to add the Rule in our OS.??.
Step-1)Check how many Rules are there
route -n
Here you can see there are some rules added, so if we want some customization for our setup, First we have to remove the 0.0.0.0 rule.
Step-2)Removing Rule
route del -net 0.0.0.0
As You can see 0.0.0.0 removed from the destination
- Now if you tried to ping 172.217.167.0 (GOOGLE IP) it won’t work because we have removed 0.0.0.0
- Add a new entry to the routing table that that makes google.com pingable and makes facebook.com not pingable and then check the routing table, observe the difference
- Here we need to type Google Ip in the net, after that netmask and finally, we have to type Gateway.
- As you can see we are pinging Google Ip.
- grep command obtains the output from nslookup command and uses regular expression to obtain IPv4 address, and then tail -1 command is used to obtain the IP required in this case. sed command is used to convert the IP address obtained to CIDR format.
THANKS FOR READING!!!!