Inter-network communication Linux small experiment

First, the experimental scene.

Experimental preparation, Linux host four. A host respectively, the host ip route R1, the host route R2, the host C, the host A is 192.168.56.66/24, and only one network card eth0; routing host eth0 R1 have two network cards in the same segment A and its host ip 192.168.56.100/24,eth1 address ip address is 172.16.56.223/16; R2 hosts have two network cards and host C eth0 to which R1 10.0.0.25/8,eth1 same network segment with the same network segment address which address, 172.16.56.200 / 16, C only one network card eth0 host whose address is 10.0.0.18/8

Experimental purposes, to achieve hosts A and C communicate with each other. Analog Linux host communication theory, in-depth understanding of the communication process.

 

Those are the experiments topology (picture a bit ugly, can read on the line, ha ha ha)

Then start the test.

1, from the above topology, we can see there are three networks, in order to prevent other network impact of this experiment, we added three virtual network inside vmware

 

After adding a good virtual network is now ready to four hosts, and configure their corresponding ip

Description: the ip centos herein are systems, edit the corresponding file / etc / sysconfig / network-scripts / ifcfg-eth0 or eth1, and then restart the network service on it.

2. Open r1, r2 forwarding and routing configurator

Note: Because the host A and R1 on the same network segment, where we do not need to configure A host route, only need to configure a host route to C R1 and R2 is pointing to a gateway, that is to access the host on C R1 must be routed through the message told to look for R2. R1 is because of open forward, but when the message arrives at R1, and it checks the data packets are not their own, if it is not the default is discarded, turn forwarded it means not native to the package, it will be forwarded to another host . After such time the configuration can be reached from the message A theory of R2, R2 forward if open, the message will reach C, but the message came back C R2, because R2 which is not configured to route A, so back packets is not able to reach the a, arranged next route R2.

说明:配置R2的路由的作用是当访问C主机的时候,C主机回应回来的报文,在经过R2是会查看R2的路由,这样从C回来的报文才能够顺利到达A

3,验证从ApingC

 从CpingA

4,扩展

1.查看到达目标网络所经过的路由

说明:可以得之到达10.0.0.18 从本机经过了2个路由才到达。

2,删除同网段的路由是否能够通讯?

说明:这里要把默认路由也要删除,因为删除同网段的路由后,它默认会走默认路由,这样就可以得出删除了同网段的路由后,本机上不能和本网段的其他主机通信。

3,在r1上配置一个不是同网段的地址,主机A是否能够与之通讯?

说明:是可以通讯的,因为在Linux里ip是属于主机,不是属于某块网卡,只要主机A有到达主机R1的路由,就可以和R1上的所有ip通讯。这里主机A是走的默认路由

4,将R1的转发关了,数据报文还能到达C吗?

说明:是不可以的,因为当主机R1收到来自A主机的报文时,它会检查时不时它的,如果不是,它将会丢弃,不予回应,这里我们可以在R1上抓包就明白了

说明:可以看出在R1上是收到了A主机的发往C的报文,但是R1并没有给出回应。

说明:当我们打开R1的转发时,就可以看到从C回应A的数据报文,当然A主机上也会收到相应的回应报文。

5,在C上抓包看源ip和目标ip,源MAC和目标MAC的变化

说明:源ip是主机A的地址,目标ip是主机C的地址

主机A的MAC

主机C的MAC

主机R2的MAC

说明:通过上面的抓包,我们可以知道源ip和目标ip在以太网帧结构中是不会变化的,因为ip是在以太网上层internel协议的内容,但是源mac会变的。这是因为mac地址是Ethernet协议的内容,也可以得出在数据链路层通讯以太网协议是通过ARP mac地址通信的,在到达C主机的报文源MAC都是R2的MAC地址,也就是说在通讯的时候,以太网帧的结构中,源ip和目标ip是不会变化的,源mac会记录上一个发送数据报文的设备的MAC。

从上面的实验我们可以得出从A到C我们经过了两个路由;一个主机想要和另一个主机通讯,在通讯前主机会先查看自己的路由表,如果本机没有到达目标主机的路由时,本机的数据报文是不能发送到目标主机的;要让一个主机转发另一个主机的报文时,我们必须开启转发才行,否则不予转发;路由配置所指定的网关必须是本机能够到达的地址(也就是本机路由表有到达网关的路由),否则配置的路由无意义。同一网段的主机通讯,也必须配置路由,当然这个路由一般我们不用管,因为配置了其ip后,路由表就会默认生成相应的路由信息。如果没有路由,同一网段的主机也是无法通信的;在Linux里ip地址是属于主机不属于某一个网卡,所以只要有能够到达主机的地址,我们也可以将报文送到主机的另外一个地址。

Guess you like

Origin www.cnblogs.com/qiuhom-1874/p/11524833.html