1、虚拟机准备:ABC三台虚拟机(centos7.5,都装有httpd服务),B作为充当网络防火墙角色,实现B的转发功能,AC可相互ping通
vmA: 单网卡,桥接模式,网络设置可ping通外网,ip为192.168.1.101
[root@vma ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.101 netmask 255.255.255.0 broadcast 192.168.1.255
# 临时添加路由,vmC所在网段指向vmB的192.168网卡ip
[root@vma ~]# route add -net 10.1.0.0/16 gw 192.168.1.102
# 添加网页并开启httpd服务
[root@vma ~]# echo "vmA html" /var/www/html/index.html
vmA html /var/www/html/index.html
[root@vma ~]# systemctl start httpd
vmB:双网卡,ens33仅主机模式,ip为10.1.0.2;ens37桥接模式,ip为192.168.1.102
[root@vmb ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.1.0.2 netmask 255.255.0.0 broadcast 10.1.255.255 # 10网段掩码为255.255.0.0
……
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.102 netmask 255.255.255.0 broadcast 192.168.1.255
……
# 临时开启路由转发功能,重要!!
[root@vmb ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
# (可选