Centos7-firewalld防火墙配置

防火墙的配置

  • 在服务器S1上搭建了三个网站和一个FTP站点,具体配置和网络拓扑图如下:

    (1)外网网站1使用IP地址200.200.200.2/24和端口80;
    (2)内网网站1使用IP地址192.168.214.2/24和端口8080;
    (3)内网网站2使用IP地址192.168.214.2/24和端口8008;
    (4)FTP站点同时使用内外网IP地址。
    (注意:服务器S1需要两张网卡)




Centos7-firewalld防火墙配置





1. 配置双网卡,打开“虚拟机”-“设置”-“添加”-“网络适配器”,选择仅主机模式

Centos7-firewalld防火墙配置

Centos7-firewalld防火墙配置



2. “编辑”-“虚拟网络编辑器”-“更改设置”,给2张网卡分配网段,分别为192.168.214.0,200.200.200.0

Centos7-firewalld防火墙配置


Centos7-firewalld防火墙配置


外网网段网关为200.200.200.254

Centos7-firewalld防火墙配置
设置完成后按“应用”键,确定退出

3. 打开终端,进入/etc/sysconfig/network-scripts/目录,发现只有一张网卡ens33,进行复制后,网卡ens37出现

Centos7-firewalld防火墙配置



4. 进入网卡ens33,vim ifcfg-ens33 配置如下

Centos7-firewalld防火墙配置



5. 进入网卡ens37, vim ifcfg-en33 配置

Centos7-firewalld防火墙配置
将NAME、DEVICE改为ens37,UUID和HWADDR分别用nmcli connection、ip addr命令查看,将它复制进去即可



6.重启网络

Centos7-firewalld防火墙配置


7.用命令ifconfig查看两张网卡IP

Centos7-firewalld防火墙配置



8.查看有没有内网区域internal和外网区域public

Centos7-firewalld防火墙配置


9.将public设置为默认区域

Centos7-firewalld防火墙配置


10.外网区域public默认添加了两张网卡,内网区域internal无

Centos7-firewalld防火墙配置
Centos7-firewalld防火墙配置


11.将public区域的ens37转移到内网internal中

Centos7-firewalld防火墙配置


12.Internal区域添加端口8080、8008端口,走tcp协议
(即内网客户端可以访问内网网站1和内网网站2;)

Centos7-firewalld防火墙配置


13.Public区域添加http、ftp协议,internal区域添加ftp
(内外网客户端均可以访问服务器S1上的FTP服务;)
Centos7-firewalld防火墙配置
重新加载
Centos7-firewalld防火墙配置


14.查看public和internal添加情况
Centos7-firewalld防火墙配置


15.允许内网客户端使用SSH客户端连接到服务器S1,拒绝外网客户端使用SSH客户端连接到服务器S1;

Centos7-firewalld防火墙配置



16.服务器S1可以使用ping命令测试到内外客户端的连接,服务器S1允许内网客户端使用ping命令测试与服务器S1的连接,拒绝外网客户端使用ping命令测试与服务器S1的连接。
加阻塞
Centos7-firewalld防火墙配置

Centos7-firewalld防火墙配置


可以重新开启防火墙systemctl restart firewalld
这样防火墙就配置好了~