标签:规则 配置信息 网站服务 用户 公网ip地址 关闭 erro auth protocol
关于防火墙基础配置可参考博文:保证Linux系统安全之CentOS 7 firewalld防火墙入门详解
- 连接内网网卡ens33地址为192.168.1.1,分配到firewall的trusted区域;
连接服务器网卡ens37地址为192.168.2.1,分配到firewall的dmz区域;
网关服务器连接互联网网卡ens38地址为192.168.3.1,为公网IP地址,分配到firewall的external区域;- 网站服务器和网关服务器均通过SSH来远程管理,为了安全,将SSH默认端口改为12345;
- 网站服务器开启 HTTPS,过滤未加密的HTTP流量;
- 网站务器拒绝ping测试,网关服务器拒绝来自互联网上的ping测试;
- 公司内网用户需要通过网关服务器共享上网;
- 互联网用户需要访问网站服务器;
- 基本环境配置;
- DMZ网站服务器环境搭建并启动服务;
- DMZ网站服务器上启动并配置firewalld防火墙策略;
- Internet测试网站环境搭建并启动服务、设置防火墙规则;
- 网关服务器配置firewalld策略;
- 配置IP伪装与端口转发;
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::46cb:a832:aea4:7b65 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:00:11:89 txqueuelen 1000 (Ethernet)
RX packets 158 bytes 46815 (45.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 31 bytes 4270 (4.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# ifconfig ens37
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.1 netmask 255.255.255.0 broadcast 192.168.2.255
inet6 fe80::8e69:6ed5:da33:fda4 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:00:11:93 txqueuelen 1000 (Ethernet)
RX packets 104 bytes 27490 (26.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 189 bytes 31923 (31.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# ifconfig ens38
ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.1 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::5348:53e2:b3bc:d35b prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:00:11:9d txqueuelen 1000 (Ethernet)
RX packets 101 bytes 27238 (26.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 188 bytes 31304 (30.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# vim /etc/sysctl.conf
……………… //省略部分内容,添加以下内容
net.ipv4.ip_forward = 1
[root@localhost ~]# sysctl -p
net.ipv4.ip_forward = 1
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.2 netmask 255.255.255.0 broadcast 192.168.2.255
inet6 fe80::8744:c79c:521f:823f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:2b:56:b5 txqueuelen 1000 (Ethernet)
RX packets 114 bytes 34398 (33.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30 bytes 4162 (4.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.2.1 0.0.0.0 UG 100 0 0 ens33
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.2 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::7c8b:1ec0:7e4d:ac6 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:98:41:ac txqueuelen 1000 (Ethernet)
RX packets 113 bytes 31388 (30.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 40 bytes 4541 (4.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.3.1 0.0.0.0 UG 100 0 0 ens33
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::9bb5:2c48:1095:d75a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:fb:76:60 txqueuelen 1000 (Ethernet)
RX packets 106 bytes 29223 (28.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 31 bytes 4349 (4.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 ens33
[root@localhost ~]# systemctl start firewalld
[root@localhost ~]# yum -y install httpd
//基于http访问的HTTP网站
[root@localhost ~]# yum -y install httpd mod_ssl
//基于https访问的HTTP网站
[root@localhost ~]# systemctl start httpd
//开启HTTP服务
[root@localhost ~]# vim /etc/ssh/sshd_config
………… //省略部分内容,修改以下内容
Port 12345
[root@localhost ~]# setenforce 0
//临时关闭SELinux
[root@localhost ~]# systemctl restart sshd
//重启ssh服务
[root@localhost ~]# firewall-cmd --set-default-zone=dmz
success
[root@localhost ~]# firewall-cmd --zone=dmz --add-service=https
success
[root@localhost ~]# firewall-cmd --zone=dmz --add-port=12345/tcp
success
[root@localhost ~]# firewall-cmd --zone=dmz --add-icmp-block=echo-request
success
[root@localhost ~]# firewall-cmd --zone=dmz --remove-service=ssh
success
[root@localhost ~]# firewall-cmd --runtime-to-permanent
success
//将临时配置转换为永久配置
[root@localhost ~]# firewall-cmd --list-all --zone=dmz
//查看并确认配置信息
dmz (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: https
ports: 12345/tcp
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks: echo-request
rich rules:
搭建方法可参考第2、3步
[root@localhost ~]# systemctl start firewalld
[root@localhost ~]# firewall-cmd --set-default-zone=external
success
[root@localhost ~]# firewall-cmd --change-interface=ens33 --zone=trusted
success
[root@localhost ~]# firewall-cmd --change-interface=ens37 --zone=dmz
success
[root@localhost ~]# firewall-cmd --runtime-to-permanent
success
[root@localhost ~]# firewall-cmd --get-active-zones
dmz
interfaces: ens37
external
interfaces: ens38
trusted
interfaces: ens33
[root@localhost ~]# vim /etc/ssh/sshd_config
………… //省略部分内容,修改以下内容
Port 12345
[root@localhost ~]# setenforce 0
//临时关闭SELinux
[root@localhost ~]# systemctl restart sshd
//重启ssh服务
[root@localhost ~]# firewall-cmd --zone=external --add-port=12345/tcp
success
[root@localhost ~]# firewall-cmd --zone=external --remove-service=ssh
success
[root@localhost ~]# firewall-cmd --zone=external --add-icmp-block=echo-request
success
[root@localhost ~]# firewall-cmd --runtime-to-permanent
success
[root@localhost ~]# ssh -p 12345 192.168.3.1
The authenticity of host ‘[192.168.3.1]:12345 ([192.168.3.1]:12345)‘ can‘t be established.
ECDSA key fingerprint is b2:4e:e8:f9:23:9f:85:dc:54:87:97:eb:15:cc:b0:48.
Are you sure you want to continue connecting (yes/no)?
[root@localhost ~]# ssh -p 12345 192.168.2.2
The authenticity of host ‘[192.168.2.2]:12345 ([192.168.2.2]:12345)‘ can‘t be established.
ECDSA key fingerprint is 25:54:5c:d5:ce:e1:04:9f:25:19:be:73:ce:93:86:54.
Are you sure you want to continue connecting (yes/no)?
默认external区域有IP转发功能!
[root@localhost ~]# firewall-cmd --remove-masquerade --zone=external
success
[root@localhost ~]# firewall-cmd --zone=external --add-rich-rule=‘rule family=ipv4 source address=192.168.1.0/24 masquerade‘
success
[root@localhost ~]# firewall-cmd --zone=external --add-forward-port=port=443:proto=tcp:toaddr=192.168.2.2
success
//网关服务器将互联网测试机的请求转发到dmz区域网站服务器
需在ens38网卡上配置一个临时IP地址
[root@localhost ~]# firewall-cmd --zone=external --add-rich-rule=‘rule family=ipv4 destination address=192.168.3.100 forward-port port=443 protocol=tcp to-addr=192.168.2.2‘
success
保证Linux系统安全之配置firewalld防火墙的地址伪装及端口转发实例,可跟做!!!
标签:规则 配置信息 网站服务 用户 公网ip地址 关闭 erro auth protocol
原文地址:https://blog.51cto.com/14157628/2433980