CentOS 7 下使用 Firewall
时间:2015-07-30 06:43 来源:linux.it.net.cn 作者:IT
# yum install firewalld
# yum install firewall-config
一、介绍
-
drop: 丢弃所有进入的包,而不给出任何响应
-
block: 拒绝所有外部发起的连接,允许内部发起的连接
-
public: 允许指定的进入连接
-
external: 同上,对伪装的进入连接,一般用于路由转发
-
dmz: 允许受限制的进入连接
-
work: 允许受信任的计算机被限制的进入连接,类似 workgroup
-
home: 同上,类似 homegroup
-
internal: 同上,范围针对所有互联网用户
-
trusted: 信任所有连接
二、使用方法
# systemctl start firewalld # 启动,
# systemctl enable firewalld # 开机启动
# systemctl stop firewalld # 关闭
# systemctl disable firewalld # 取消开机启动
$ firewall-cmd --help
1. 查看规则
$ firewall-cmd --state
$ firewall-cmd --get-active-zones
public
interfaces: eth0 eth1
$ firewall-cmd --get-zone-of-interface=eth0
public
$ firewall-cmd --zone=public --list-interfaces
eth0
$ firewall-cmd --zone=public --list-all
public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client http ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
$ firewall-cmd --get-service
$ firewall-cmd --get-service --permanent
2. 管理规则
# firewall-cmd --panic-on # 丢弃
# firewall-cmd --panic-off # 取消丢弃
$ firewall-cmd --query-panic # 查看丢弃状态
# firewall-cmd --reload # 更新规则,不重启服务
# firewall-cmd --complete-reload # 更新规则,重启服务
# firewall-cmd --zone=public --add-interface=eth0 --permanent
# firewall-cmd --set-default-zone=public
a. 管理端口
# firewall-cmd --zome=dmz --list-ports
# firewall-cmd --zone=dmz --add-port=8080/tcp
# firewall-cmd --zome=public --add-port=5060-5059/udp --permanent
b. 管理服务
# firewall-cmd --zone=work --add-service=smtp
# firewall-cmd --zone=work --remove-service=smtp
c. 配置 ip 地址伪装
# firewall-cmd --zone=external --query-masquerade
# firewall-cmd --zone=external --add-masquerade
# firewall-cmd --zone=external --remove-masquerade
d. 端口转发
# firewall-cmd --zone=external --add-masquerade
# firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=3753
# firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toaddr=192.168.1.100
# firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.168.1.100
-
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html
-
https://fedoraproject.org/wiki/FirewallD
(责任编辑:IT)
# yum install firewalld # yum install firewall-config 一、介绍
二、使用方法# systemctl start firewalld # 启动, # systemctl enable firewalld # 开机启动 # systemctl stop firewalld # 关闭 # systemctl disable firewalld # 取消开机启动 $ firewall-cmd --help 1. 查看规则$ firewall-cmd --state $ firewall-cmd --get-active-zones public interfaces: eth0 eth1 $ firewall-cmd --get-zone-of-interface=eth0 public $ firewall-cmd --zone=public --list-interfaces eth0 $ firewall-cmd --zone=public --list-all public (default, active) interfaces: eth0 sources: services: dhcpv6-client http ssh ports: masquerade: no forward-ports: icmp-blocks: rich rules: $ firewall-cmd --get-service $ firewall-cmd --get-service --permanent 2. 管理规则# firewall-cmd --panic-on # 丢弃 # firewall-cmd --panic-off # 取消丢弃 $ firewall-cmd --query-panic # 查看丢弃状态 # firewall-cmd --reload # 更新规则,不重启服务 # firewall-cmd --complete-reload # 更新规则,重启服务 # firewall-cmd --zone=public --add-interface=eth0 --permanent # firewall-cmd --set-default-zone=public a. 管理端口# firewall-cmd --zome=dmz --list-ports # firewall-cmd --zone=dmz --add-port=8080/tcp # firewall-cmd --zome=public --add-port=5060-5059/udp --permanent b. 管理服务# firewall-cmd --zone=work --add-service=smtp # firewall-cmd --zone=work --remove-service=smtp c. 配置 ip 地址伪装# firewall-cmd --zone=external --query-masquerade # firewall-cmd --zone=external --add-masquerade # firewall-cmd --zone=external --remove-masquerade d. 端口转发# firewall-cmd --zone=external --add-masquerade # firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=3753 # firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toaddr=192.168.1.100 # firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.168.1.100
(责任编辑:IT) |