Today in this blog we will be exploring some concepts of subnetting and routing table and create an interesting setup where our system can ping to Google but can't ping to Facebook at the same time .

Let's first understand some of the basic terminologies that help us in understanding this networking practical more accurately.

📌What is a routing table?

Routing Table provides the device with instructions for sending the packet to the next hop on its route across the network.

A routing table contains the information necessary to forward a packet along the best path toward its destination. Each packet contains information about its origin and destination. Routing Table provides the device with instructions for sending the packet to the next hop on its route across the network.

Each entry in the routing table consists of the following entries:

  1. Network ID: The network ID or destination corresponding to the route.
  2. Subnet Mask: The mask that is used to match a destination IP address to the network ID.
  3. Next Hop: The IP address to which the packet is forwarded
  4. Outgoing Interface: Outgoing interface the packet should go out to reach the destination network.
  5. Metric: A common use of the metric is to indicate the minimum number of hops (routers crossed) to the network ID.

📌What is Gateway?

While a gateway protects the nodes within the network, it also a node itself. The gateway node is considered to be on the “edge” of the network as all data must flow through it before coming in or going out of the network. It may also translate data received from outside networks into a format or protocol recognized by devices within the internal network.

📌What is IP Address?

How do IP addresses work:

Internet Protocol works the same way as any other language, by communicating using set guidelines to pass information. All devices find, send, and exchange information with other connected devices using this protocol. By speaking the same language, any computer in any location can talk to one another.

The use of IP addresses typically happens behind the scenes. The process works like this:

  1. Our device indirectly connects to the internet by connecting at first to a network connected to the internet, which then grants our device access to the internet.
  2. When we are at home, that network will probably be our Internet Service Provider (ISP). At work, it will be our company network.
  3. Our IP address is assigned to our device by our ISP.
  4. Our internet activity goes through the ISP, and they route it back to us, using our IP address. Since they are giving us access to the internet, it is their role to assign an IP address to our device.
  5. However, our IP address can change. For example, turning our modem or router on or off can change it. Or we can contact your ISP, and they can change it for us.
  6. When we are out and about — for example, traveling — and we take our device with us, our home IP address does not come with us. This is because we will be using another network (Wi-Fi at a hotel, airport, or coffee shop, etc.) to access the internet and will be using a different (and temporary) IP address, assigned to you by the ISP of the hotel, airport or coffee shop.

There are two versions of IP addresses: IPv4 and IPv6.
Addresses in IPv4 are 32-bits long. This allows for a maximum of 4,294,967,296 (232) unique addresses
Addresses in IPv6 are 128-bits, which allows for 3.4 x 1038 (2128) unique addresses.

📌What is 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.

A netmask is a shorthand for describing a range of IP addresses. A netmask may describe just a single IP address:

192.168.0.1/32: just the address 192.168.0.1

Or all possible IP addresses:

192.168.0.1/32: all 4.3 billion addresses from 0.0.0.0 to 255.255.255.255

More usefully, it does something in between:

192.168.0.1/32: the IP addresses 192.168.0.0 and 192.168.0.1

How to read a netmask?

For instance, in the netmask,192.168.0.1/32 the host address is 192.168.0.1 This can be written in binary as 11000000.10101000.11111111.00000001. To match this netmask, an address must have match exactly 32 digits - i.e. have the same binary digit in each position. This means only one address will be matched by this pattern.

The netmask 192.168.0.1/31 states that the last binary digit is not significant so will match two addresses: 11000000.10101000.11111111.00000000 and 11000000.10101000.11111111.00000001 (written more readably as 192.168.0.0 and 192.168.0.1).

Similarly 192.168.0.1/30 states that the last two binary digits are not significant so will match four different addresses.

Task Description:

🎯Create a Setup so that we can ping Google but not able to ping Facebook from the same system.

🎯 In Linux, we use ifconfig command to see the IP address and netmask of the system.️

🎯 In Linux, we use the route -n command to see the route table of the system.️

🎯 In Linux, we use the ping command to check connectivity .️

Now, we check if our system can ping to Google or Facebook:

Google:

Facebook:

Here, we see that our system is successfully pinging to both Google and Facebook.

🎯 In Linux, we use nslookup command to see the ip address of any server .️

🎯 Now,we have to delete Quad Route(default route).

The default route in Internet Protocol Version 4 (IPv4) is designated as the zero-address 0.0.0.0/0 in CIDR notation, often called the quad-zero route.

Now, if we again try to ping Google and Facebook its fail because we deleted the default rule from the routing table.

🎯 Now , we add the rule in routing table according to google’s ip so that google’s ip will come in that range/routing table and add internet gateway for it so that google is able to ping.

So, for this we write Google Ip in Destination and gateway will be localhost and write netmask 255.255.255.255

Now if we again ping to google as well as Facebook and we see that our system is able to ping google but it cant ping to Facebook at the same time.

The Wrap-Up

In the upcoming days I am going to publish lots of articles on different automation Tools and other Technologies, So definitely follow me on Medium.

Here is my LinkedIn profile if u have any queries definitely comment below or DM me on Linkedin

I am tech enthusiast fascinated towards technology and its various disciplines including Big Data, Hadoop, Web Development, Competative Programming,ML,etc.