Routing and forwarding small experiment

Now there are two hosts A and B, and there are four routers Ra, Rb, Rc, and Rd in the middle. The goal is to realize the communication between the two hosts A and B.

Ready to work:

The preparation part is mainly in the VMware part. Since our purpose is to better understand routing forwarding, this may not make much sense. All the content below is based on the operation of the linux virtual machine. Let's start the preparations first, since we are using the system instead of the router, 6 linux virtual machines are necessary. For convenience, the network card is used to simulate the port of the router. That is to say, except for the two hosts A and B, the remaining four Linux virtual machines use two network cards.
1. 6 linux virtual machines, two as hosts and four as routers
2. Add two network cards to the virtual machine as routers 3.
Add five networks in the virtual network editor and assign them to the corresponding network cards.
The four networks of VMnet10, 11, 12, 13, and 14 are added to the network, then the corresponding settings can be that A and Ra1 use VMnet10, Ra2 and Rb1 use VMnet11, and so on. The topology diagram is roughly as follows:

Routing and forwarding small experiment

Step 1: Plan IP and divide subnets

Four routers are five subnets. In order to facilitate the distinction, the IP is divided as follows.
Host A IP: 192.168.1.141

Ra1 IP:192.168.1.1
Ra2 IP:192.168.2.2

Rb1 IP:192.168.2.1
Rb2 IP:192.168.3.3

Rc1 IP:192.168.3.1
Rc2 IP:192.168.4.4

Rd1 IP:192.168.4.1
Rd2 IP:192.168.5.5

Host B IP: 192.168.5.1 The
mask is all: 255.255.255.0

Step 2: Configure the host and route IP

This part of the content is mainly to modify the configuration files of each network card. The general format is as follows. Modify each configuration file according to the pre-assigned IP, and then restart the network service.

DEVICE=ens33
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.141
PREFIX=24
GATEWAY=192.168.1.1

After configuration it should look like this

Routing and forwarding small experiment

Step 3: Turn on the forwarding function and turn off the firewall


Execute echo 1 > /proc/sys/net/ipv4/ip_forward on the four routers to
view the value of this file, make sure that all are 1 to
close the firewall, execute systemctl stop firewalld in Centos7, and ensure that the firewall has been closed through systemctl status firewalld
In Centos6 Execute service iptables stop in the service iptables stop, and make sure the firewall is closed through service iptables status

Step 4: Add a route

In order to avoid the interference caused by default routes, I ignore the existence of default routes and add routing information directly.
A. ip route add 192.168.5.0/24 via 192.168.1.1 dev ens33
Ra, ip route add 192.168.5.0/24 via 192.168.2.1 dev ens34
Rb, ip route add 192.168.5.0/24 via 192.168.3.1 dev ens34
Rc, ip route add 192.168.5.0/24 via 192.168.4.1 dev ens34
Rd, ip route add 192.168.5.0/24 via 192.168.5.1 dev ens34

This is the routing information of the outgoing way, and then the routing information of the loop
B, ip route add 192.168.1.0/24 via 192.168.5.5 dev ens33
Rd, ip route add 192.168.1.0/24 via 192.168.4.4 dev ens33
Rc, ip route add 192.168.1.0/24 via 192.168.3.3 dev ens33
Rb, ip route add 192.168.1.0/24 via 192.168.2.2 dev ens33
Ra, ip route add 192.168.1.0/24 via 192.168.1.1 dev ens33

But only these words are not possible. To be precise, if the default route is really ignored, the above routing table may not be added, so before adding the above route, you should ensure that the adjacent network segments are interoperable. Therefore, before adding the above route, you need to add two routes to each route. The reason is that each router is connected to two network segments, and the role of these two routes is to throw the corresponding address to the corresponding gateway. Specifically, it should be as follows:

host A

ip route add 192.168.1.0/24 via 0.0.0.0 dev ens33

Out,

ip route add 192.168.2.0/24 via 0.0.0.0 dev ens34
ip route add 192.168.1.0/24 via 0.0.0.0 dev ens33
(In fact, with this, the route from Ra above can be added without adding it, but I think it is easier to understand )

Rb、

The principle is the same, Rb needs to send out the gateway to the 192.168.3.0 network segment through the ens34 gateway, and send the one to 192.168.2.0 through ens33, so these two should be
ip route add 192.168.3.0/24 via 0.0. 0.0 dev ens34
ip route add 192.168.2.0/24 via 0.0.0.0 dev ens33

Rc、

ip route add 192.168.4.0/24 via 0.0.0.0 dev ens34
ip route add 192.168.3.0/24 via 0.0.0.0 dev ens33

Rd、

ip route add 192.168.5.0/24 via 0.0.0.0 dev ens34
ip route add 192.168.4.0/24 via 0.0.0.0 dev ens33

host B

ip route add 192.168.5.0/24 via 0.0.0.0 dev ens33

Once done make sure that each router has routes to the two network segments connected to it and routes to A and B. After completion, use the ping command to check whether it is connected.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325345321&siteId=291194637