Experiment: communication between hosts across the network
Experimental topology:
Step 1: Create four virtual machines
Step Two: Configure vmnet6 and network segment vmnet8
vmnet6: 10.0.0.0/8
vmnet8: 192.168.38.0/24
vmnet0: 172.18.0.0/24
Third, as shown above, the configuration of each network card type virtual machine
Fourth, configure IP
The first virtual machine
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.38.123
NETMASK=255.255.255.0
GATEWAY=192.168.38.2
NAME=ens33
DEVICE=ens33
ONBOOT=yes
[root@localhost ~]# systemctl restart network
The second virtual machine
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.38.200
NETMASK=255.255.255.0
GATEWAY=192.168.38.2
NAME=ens33
DEVICE=ens33
ONBOOT=yes
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens37
TYPE=Ethernet
BOOTPROTO=static
IPADDR=10.0.0.200
NETMASK=255.0.0.0
GATEWAY=10.0.0.1
NAME=ens37
DEVICE=ens37
ONBOOT=yes
[root@localhost ~]# systemctl restart network
The third virtual machine
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
IPADDR=10.0.0.201
NETMASK=255.0.0.0
GATEWAY=10.0.0.1
NAME=ens33
DEVICE=ens33
ONBOOT=yes
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens37
TYPE=Ethernet
BOOTPROTO=static
IPADDR=172.18.28.201
NETMASK=255.255.0.0
GATEWAY=172.18.0.1
NAME=ens37
DEVICE=ens37
ONBOOT=yes
[root@localhost ~]# systemctl restart network
The fourth virtual machine
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
IPADDR=172.18.28.202
NETMASK=255.255.0.0
GATEWAY=172.18.0.1
NAME=ens33
DEVICE=ens33
ONBOOT=yes
[root@localhost ~]# systemctl restart network
Fifth, configure routing rules
A ping B further now nowhere
[root@b ~]# ping 192.168.38.123
PING 192.168.38.123 (192.168.38.123) 56(84) bytes of data.
From 172.18.28.28 icmp_seq=1 Redirect Network(New nexthop: 172.18.0.1)
From 172.18.28.28: icmp_seq=1 Redirect Network(New nexthop: 172.18.0.1)
A default gateway should be 192.168.38.200 (or add a route to A, so that A knows 172.18 network is through 192.168.38.200 out, otherwise the whole packet sent to the 192.168.38.2 go)
[root@localhost ~]# ip route add default via 192.168.38.200
R1 172.18 network go through 10.0.0.201
[root@localhost ~]# ip route add 172.18.0.0/16 via 10.0.0.201
R2 walk 192.168.38 segment through 10.0.0.200
[root@r2 ~]# ip route add 192.168.38.0/24 via 10.0.0.200
B's default gateway should be 172.18.28.201
[root@b ~]# ip route add default via 172.18.28.201
Six, three second virtual machine is turned on routing and forwarding
The second and third virtual machine to be executed
[root@localhost ~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.d/ip_forward.conf
[root@localhost ~]# sysctl -p /etc/sysctl.d/ip_forward.conf
net.ipv4.ip_forward = 1
Seven, the next step is to witness the miracle of the moment
B ping A
[root@b ~]# ping 192.168.38.123 -c3
PING 192.168.38.123 (192.168.38.123) 56(84) bytes of data.
64 bytes from 192.168.38.123: icmp_seq=1 ttl=62 time=4.83 ms
64 bytes from 192.168.38.123: icmp_seq=2 ttl=62 time=1.03 ms
64 bytes from 192.168.38.123: icmp_seq=3 ttl=62 time=1.12 ms
--- 192.168.38.123 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 1.034/2.329/4.832/1.770 ms
B ping A (after the first experiment done NAT can be directly ping to the bridge, I do not know why )
[root@localhost ~]# ping 172.18.28.202 -c3
PING 172.18.28.202 (172.18.28.202) 56(84) bytes of data.
64 bytes from 172.18.28.202: icmp_seq=1 ttl=62 time=2.20 ms
64 bytes from 172.18.28.202: icmp_seq=2 ttl=62 time=1.14 ms
64 bytes from 172.18.28.202: icmp_seq=3 ttl=62 time=0.876 ms
--- 172.18.28.202 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 0.876/1.408/2.202/0.573 ms
A how to get to the B:
[root@localhost ~]# tracepath -n 172.18.28.202
1?: [LOCALHOST] pmtu 1500
1: 192.168.38.200 0.558ms
1: 192.168.38.200 1.848ms
2: 10.0.0.201 2.290ms
3: 172.18.28.202 4.786ms reached
Resume: pmtu 1500 hops 3 back 3
B to A how to go
[root@b ~]# tracepath -n 192.168.38.123
1?: [LOCALHOST] pmtu 1500
1: 172.18.28.201 0.887ms
1: 172.18.28.201 0.863ms
2: 10.0.0.200 5.798ms
3: 192.168.38.123 9.648ms reached
Resume: pmtu 1500 hops 3 back 3
Now I do not know how the virtual machine will be able to ping the default NAT to bridge the virtual machine, and now tracepath look at (this is a new virtual machine)
# 能ping通
[qqq@ubuntu ~]$ ping 172.18.28.202 -c2
PING 172.18.28.202 (172.18.28.202) 56(84) bytes of data.
64 bytes from 172.18.28.202: icmp_seq=1 ttl=128 time=2.15 ms
64 bytes from 172.18.28.202: icmp_seq=2 ttl=128 time=0.738 ms
--- 172.18.28.202 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 3ms
rtt min/avg/max/mdev = 0.738/1.442/2.146/0.704 ms
#看一下怎么走的
[qqq@ubuntu ~]$ tracepath -n 172.18.28.202
1?: [LOCALHOST] pmtu 1500
1: 192.168.38.2 0.480ms
1: 192.168.38.2 0.120ms
2: no reply
3: no reply
4: no reply
... (确实是到了NAT桥那里,后面一直noreply了)