Firewall防火墙

1.查看当前默认区域
firewall-cmd --get-default-zone 
2.查看当前正在活动的区域
firewall-cmd --get-active-zones
3.防火墙规则列表
firewall-cmd --list-all
4.放行端口
firewall-cmd --add-port=8080/tcp --add-port=8080/udp
firewall-cmd --add-port={8081,8082}/tcp
firewall-cmd --add-port={8090..8095}/tcp
# --perment 永久开放
5.删除放行的端口
firewall-cmd --remove-port={8090..8095}/tcp
6.放行服务
firewall-cmd --add-service=http
7.自定义服务名称
# /usr/lib/firewalld/services/
cd  /usr/lib/firewalld/services/
cp http.xml nginx.xml
firewall-cmd --reload'
firewall-cmd --add-service=nginx
8.防火墙转发规则 (四层负载)
firewall-cmd --permanent --zone=<区域> --add-forward-port=port=<源端口号>:proto=<协议>:toport=<目标端口号>:toaddr=<目标IP地址>
firewall-cmd --add-forward-port=port=5555:proto=tcp:toport=22:toaddr=172.16.1.7
firewall-cmd --add-masquerade
9.Firewalld 富规则
# 查看富规则帮助手册
man firewall-cmd  
# 获取富规则手册
man firewalld.richlanguage
rule
  [source]
  [destination]
  service|port|protocol|icmp-block|masquerade|forward-port
  [log]
  [audit]
  [accept|reject|drop]
# accept  		允许
# reject  		拒绝,回句话
# drop	  		拒绝,不搭理
rule [family="ipv4|ipv6"]
source address="address[/mask]" [invert="True"]
service name="service name"
port port="port value" protocol="tcp|udp"
forward-port port="port value" protocol="tcp|udp" to-port="port value" to-addr="address"
accept | reject [type="reject type"] | drop
#  允许10.0.0.1主机能够访问80
firewall-cmd --add-rich-rule='rule family=ipv4 source address=10.0.0.1/32 port port="80" protocol="tcp" accept'
# 允许172.16.1.0/24能访问8081端口
firewall-cmd --add-rich-rule='rule family=ipv4 source address=172.16.1.0/24 port port="8081" protocol="tcp" accept
# 默认public区域对外开放所有人能通过ssh服务连接,但拒绝172.16.1.0/24网段通过ssh连接服务器
firewall-cmd --add-rich-rule='rule family=ipv4 source address="172.16.1.0/24" service name="ssh" drop'
# 允许所有人能访问http,https服务,但只有10.0.0.1主机可以访问ssh服务
firewall-cmd --remove-service=ssh
firewall-cmd --add-service={http,https}
firewall-cmd --add-rich-rule='rule family=ipv4 source address="10.0.0.1/32" service name="ssh" accept'
# 当用户来源IP地址是10.0.0.1主机,则将用户请求的5555端口转发至后端172.16.1.7的22端口
firewall-cmd --add-rich-rule='rule family=ipv4 source address="10.0.0.1/32" forward-port port="6666" protocol="tcp" to-port="22" to-addr="172.16.1.7"'
firewall-cmd --add-masquerade
10.Firewalld 实现共享上网
(1) 开启共享上网
firewall-cmd --add-masquerade
(2)客户端将默认网关指向---> 能上网的地址
[root@web01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
	IPADDR=172.16.1.7
	GATEWAY=172.16.1.61
	DNS1=223.5.5.5
	PREFIX=24
posted @ 2020-01-02 18:40  IMSCZ  阅读(328)  评论(0编辑  收藏  举报