firewalld防火墙(二)
结构
开启三台虚拟机
开启centos01(内网LAN)
开启centos02(将02模拟成为防火墙)添加一块vmnet2网卡
开启centos03(外网WAN) 将网卡改为vmnet2
centos02(防火墙)
给新增的网卡复制一个配置文件 本次内网为100.0 外网为200.0
查看新增网卡的id
[root@centos02 ~]# ifconfig
给ens34复制一个配置文件
[root@centos02 ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens32 /etc/sysconfig/network-scripts/ifcfg-ens34
编辑ens34,修改名字,将ip地址改为200.20
[root@centos02 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens34
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
NAME=ens34
DEVICE=ens34
ONBOOT=yes
IPADDR=192.168.200.20
NETMASK=255.255.255.0
重启网卡服务
[root@centos02 ~]# systemctl restart network
开启路由功能
[root@centos02 ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
启动防火墙服务-设置为开机自动启动
[root@centos02 ~]# systemctl start firewalld.service
[root@centos02 ~]# systemctl enable firewalld.service
将接口ens32添加到trusted
[root@centos02 ~]# firewall-cmd --add-interface=ens32 --zone=trusted
将接口ens34添加到external
[root@centos02 ~]# firewall-cmd --add-interface=ens34 --zone=external
查看两个接口所在的区域
[root@centos02 ~]# firewall-cmd --get-zone-of-interface=ens32
trusted
[root@centos02 ~]# firewall-cmd --get-zone-of-interface=ens34
external
如果不对应 修改默认区域
[root@centos02 ~]# firewall-cmd --set-default-zone=trusted
centos03(外网)
编辑网卡,将IP地址修改为200.10,添加网关192.168.200.20
重启网卡服务
查看IP地址
ifconfig
查看路由表
route -n
centos01 (内网)
编辑网卡配置文件,添加网关192.168.100.20
[root@centos01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
NAME=ens32
DEVICE=ens32
ONBOOT=yes
IPADDR=192.168.100.10
NETMASK=255