Network Topology Setup in such a way that System A can ping to two Systems B & C but both systems not able to ping each other
Tags: networking, netmask, route, linux
Published: 2021-06-11 04:58:36

**Note:** We are not going to use any firewall, since it is simple and everyone aware of this, so we are going to use unique way to achieve this topology setup.

**Concepts used:** Routing tables and Netmask

In this practical, We are going to use three Redhat Enterprise Linux Virtual Machines which are hosting by Oracle VirtualBox.

I already explained these Routing table and Netmask concepts in my previous blog, if you want to know these basic concepts then please refer [this](https://dev.to/vishnuswmech/setting-up-your-own-network-that-can-ping-google-but-not-able-to-ping-facebook-in-the-same-system-without-using-a-firewall-1c8p)

**Note:** Before starting these VM's, make sure that it is connected in Host-only adapter mode and the adapter name should be the same in all three VMs.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fe5z56jwfpicju3olq0a.png)
##Environment Setup
###System A
First step is to change the IP and set the Netmask by running the following command.
```ifconfig enp0s3 162.168.1.1/29```

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pzb1zotgnaqycapex1oh.png)
Second step is to create the route rule by running the following command.
```route add -net 162.168.1.0 netmask 255.255.255.248 enp0s3```

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hxwqzpillvaj48jhr2mq.png)
###System B
First step is to change the IP and set the Netmask by running the following command.
```ifconfig enp0s3 162.168.1.2/31```

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rs4hm9gom94co3pc786p.png)
Second step is to create the route rule by running the following command.
```route add -net 162.168.1.0 netmask 255.255.255.254 enp0s3```

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7lz7oaabi2ltqukz76sk.png)
###System C
First step is to change the IP and set the Netmask by running the following command.
```ifconfig enp0s3 162.168.1.4/31```

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qy4sy5czqctyo2ofggxp.png)
Second step is to create the route rule by running the following command.
```route add -net 162.168.1.0 netmask 255.255.255.254 enp0s3```
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q9yhhzsg5akiqj79amhp.png)

###Ping Checking
Now, We completed the environment setup. Now we have to run the ping command in order to check the status of Network connectivity.

###Pinging System B from System A
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6u959kszum1usd4s4bmc.png)
###Pinging System A from System B
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xbfmnu6wnq6oqk5mkplk.png)
###Pinging System C from System A
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jiwugp146foyqhva20cd.png)

###Pinging System A from System C
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p79xh5bsl85rdofilk9l.png)
###Pinging System B from System C
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/utortk5s43w9qp73vq39.png)
###Pinging System C from System B
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f04weibaq73zijvmhbzl.png)
##How is this Possible?
In simple words, it happened because of routing tables that use the Netmask for the IP range.

Let's take a look at the routing rule in System A
```route add -net 162.168.1.0 netmask 255.255.255.248 enp0s3```
In this, Netmask 255.255.255.248 denotes the IP range which have the connection between them.
If you convert to binary form means, it looks like this.

**11111111 11111111 11111111 11111000**

For the last **three places**(where the zeros located), we can accommodate **8 combinations**. So it decided the number of IP's (IP range) that can connect each other.

The range of IPs are that can connect each other is **162.168.1.0–162.168.1.7.**

So in this way, System A **can ping** to System B (162.168.1.2) and System C (162.168.1.4).

Then if you look at the routing rule in System B.
```route add -net 162.168.1.0 netmask 255.255.255.254 enp0s3```
The netmask is specified as 255.255.255.254
If you convert to binary form means, it looks like this.

**11111111 11111111 11111111 11111110**

For the last **one place**(where the zero located), We can accommodate **2 combinations**. So it decided the number of IPs (IP range) that can connect each other.

So the range of IP's that are connected to each other are two in numbers namely **168.162.1.0 and 162.168.1.1**.

In this way System B **can ping** to System A. It is noted that IP of System C (162.168.1.4) is **not** in range, that's the reason for not ping.

Finally, if you take a look on routing rule in System C.
```route add -net 162.168.1.0 netmask 255.255.255.254 enp0s3```
Here, the Netmask specified is 255.255.255.254. So the last **one place**(where the zero located), we can accommodate **2 combinations**. So it decided the number of IPs (IP range) that can **connect** each other.

So the range of IPs that are connected to each other are **two** in numbers namely **168.162.1.0 and 162.168.1.1**.

In this way, System C can **ping** to System A. It is noted that IP of B(162.168.1.2) is **not in range**, that’s the reason for not ping.

Thats it. Hope this practical help you to undertand the concepts of Netmask and Routing tables and its use cases in Networking. Stay tuned for my next article!!