DAY—FOR—13—ma了gedu—实验zuoye—主机(linuxOS)之间跨网通信

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DAY—FOR—13—ma了gedu—实验zuoye—主机(linuxOS)之间跨网通信相关的知识,希望对你有一定的参考价值。

第一步:创建四个虚拟机
第二步:配置vmnet6和vmnet8网段
vmnet6:10.0.0.0/8

vmnet8:192.168.38.0/24

vmnet0:172.18.0.0/24

三、如上图所示,配置好每个虚拟机的网卡类型
四、配置IP
第一个虚拟机

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33<br/>TYPE=Ethernet<br/>BOOTPROTO=static<br/>IPADDR=192.168.38.123<br/>NETMASK=255.255.255.0<br/>GATEWAY=192.168.38.2<br/>NAME=ens33<br/>DEVICE=ens33<br/>ONBOOT=yes<br/>[root@localhost ~]# systemctl restart network<br/>第二个虚拟机

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33<br/>TYPE=Ethernet<br/>BOOTPROTO=static<br/>IPADDR=192.168.38.200<br/>NETMASK=255.255.255.0<br/>GATEWAY=192.168.38.2<br/>NAME=ens33<br/>DEVICE=ens33<br/>ONBOOT=yes<br/>[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens37<br/>TYPE=Ethernet<br/>BOOTPROTO=static<br/>IPADDR=10.0.0.200<br/>NETMASK=255.0.0.0<br/>GATEWAY=10.0.0.1<br/>NAME=ens37<br/>DEVICE=ens37<br/>ONBOOT=yes<br/>[root@localhost ~]# systemctl restart network<br/>第三个虚拟机

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33<br/>TYPE=Ethernet<br/>BOOTPROTO=static<br/>IPADDR=10.0.0.201<br/>NETMASK=255.0.0.0<br/>GATEWAY=10.0.0.1<br/>NAME=ens33<br/>DEVICE=ens33<br/>ONBOOT=yes<br/>[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens37<br/>TYPE=Ethernet<br/>BOOTPROTO=static<br/>IPADDR=172.18.28.201<br/>NETMASK=255.255.0.0<br/>GATEWAY=172.18.0.1<br/>NAME=ens37<br/>DEVICE=ens37<br/>ONBOOT=yes<br/>[root@localhost ~]# systemctl restart network<br/>第四个虚拟机<br/>
[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
五、配置路由规则
现在B还ping不通A

[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的默认网关应该是192.168.38.200(或者给A加一条路由,让A知道172.18网段是要通过192.168.38.200出去的,不然数据包全发到192.168.38.2去了)

[root@localhost ~]# ip route add default via 192.168.38.200
R1走172.18网段通过10.0.0.201

[root@localhost ~]# ip route add 172.18.0.0/16 via 10.0.0.201
R2走192.168.38网段通过10.0.0.200

[root@r2 ~]# ip route add 192.168.38.0/24 via 10.0.0.200
B的默认网关应该是172.18.28.201

[root@b ~]# ip route add default via 172.18.28.201
六、第二三个虚拟机开启路由转发
第二个和第三个虚拟机都要执行

[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
七、接下来就是见证奇迹的时刻
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
A ping B (第一次实验做完后NAT就可以直接ping到桥接了,不知道什么原因)

[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到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到A怎么走的

[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
现在虚拟机不知道怎么了默认NAT就能ping到桥接的虚拟机,现在tracepath看一下(这是新的一台虚拟机)

能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了)

以上是关于DAY—FOR—13—ma了gedu—实验zuoye—主机(linuxOS)之间跨网通信的主要内容,如果未能解决你的问题,请参考以下文章

JAVA Day13

day13 js 练习

day2-20180327笔记

2020.3.13实验室周赛题解(2019山东)

LeetCode 五月打卡-day13

python-fullstack-s13-day07-python基础