firewalld 更改默认目标
firewalld change default target
来自 firewalld 手册页:
–permanent [–zone=zone] --set-target=target
Set the target of a permanent zone. target is one of: default, ACCEPT, DROP, REJECT
默认目标是拒绝。是否可以将默认目标更改为 DROP?如果不是,如果默认选项总是拒绝,为什么存在默认选项?
我使用的是 CentOS 7.4
我知道我可以以任何我喜欢的方式配置 firewalld 而不能更改默认目标,但我想知道如何更改它(如果可能)。
It is not possible to change the default target - it's hardcoded. It's possible "default" was included so we could potentially introduce a "--set-default-target" option in the future, but I'm just speculating.
关于 firewalld(1) 及其截至 2020 年的目标:
- 可能的政策目标
- 继续
- 接受
- 丢弃
- 拒绝
- 策略仅在 firewalld>=0.9.0
- 可能的区域目标
- 默认
- 接受
- 丢弃
- 拒绝
- 目标:默认
- 拒绝
- 允许 ICMP
- 如果入口区域是默认的,转发将遵循出口区域目标
- 可能会根据全局设置应用区域漂移
区域中的目标是如果没有其他区域规则匹配,目标数据包将被发送到的目的地,并且可以是
- 接受
- 丢弃
- 拒绝
- 或者是...默认值
'DEFAULT' 基本上是一个简单的 REJECT 加上其他理智的东西以获得更明智的默认设置,它的名称选择有点不吉利。
接受的答案有点误导,因为它谈到重新定义目标 'DEFAULT'。
然而,问题应该是针对是否可以在一个区域中设置不同的 'default' 目标,这是完美的:
firewall-cmd --permanent --zone=YOUR_ZONE_HERE --set-target=ACCEPT
firewall-cmd --reload
#some different oneliners to verify your config
#1.
(firewall-cmd --list-all;for i in $(firewall-cmd --get-active-zones|grep -v "^\s");do firewall-cmd --list-all --zone=$i;done)|grep -v ':\s*$'
#2.
fwstatus() { _fwstate=$(firewall-cmd --state 2>&1);printf "FIREWALLD=%s\n" "${_fwstate}";[[ "not running" == ${_fwstate} ]]&&return;_panicstate=$(firewall-cmd --query-panic);if [[ "on" == "${_panicstate}" ]];then printf "\e[41;1m";else printf "\e[32;1m";fi;printf "PANIC MODE=%s\e[m\n" "${_panicstate}";printf "LOCKDOWN=%s\n\n" "$(firewall-cmd --query-lockdown)";_defaultzone=$(firewall-cmd --get-default-zone);firewall-cmd --list-all-zones|sed 's/^'"$_defaultzone"'/& (default)/'|sed -n '/^'"$_defaultzone"'\|active/,/^$/p'|grep -v -e ':\s*$' -e icmp-block-inversion|awk 'NF>0'|grep --color -e$ -e^\w.\+;}&&fwstatus ## show full firewalling state,only works when firewalld is running
#3.
firewall-cmd --zone=YOUR_ZONE_HERE --list-all
来自 firewalld 手册页:
–permanent [–zone=zone] --set-target=target Set the target of a permanent zone. target is one of: default, ACCEPT, DROP, REJECT
默认目标是拒绝。是否可以将默认目标更改为 DROP?如果不是,如果默认选项总是拒绝,为什么存在默认选项?
我使用的是 CentOS 7.4
我知道我可以以任何我喜欢的方式配置 firewalld 而不能更改默认目标,但我想知道如何更改它(如果可能)。
It is not possible to change the default target - it's hardcoded. It's possible "default" was included so we could potentially introduce a "--set-default-target" option in the future, but I'm just speculating.
关于 firewalld(1) 及其截至 2020 年的目标:
- 可能的政策目标
- 继续
- 接受
- 丢弃
- 拒绝
- 策略仅在 firewalld>=0.9.0
- 可能的区域目标
- 默认
- 接受
- 丢弃
- 拒绝
- 目标:默认
- 拒绝
- 允许 ICMP
- 如果入口区域是默认的,转发将遵循出口区域目标
- 可能会根据全局设置应用区域漂移
区域中的目标是如果没有其他区域规则匹配,目标数据包将被发送到的目的地,并且可以是
- 接受
- 丢弃
- 拒绝
- 或者是...默认值
'DEFAULT' 基本上是一个简单的 REJECT 加上其他理智的东西以获得更明智的默认设置,它的名称选择有点不吉利。
接受的答案有点误导,因为它谈到重新定义目标 'DEFAULT'。
然而,问题应该是针对是否可以在一个区域中设置不同的 'default' 目标,这是完美的:
firewall-cmd --permanent --zone=YOUR_ZONE_HERE --set-target=ACCEPT
firewall-cmd --reload
#some different oneliners to verify your config
#1.
(firewall-cmd --list-all;for i in $(firewall-cmd --get-active-zones|grep -v "^\s");do firewall-cmd --list-all --zone=$i;done)|grep -v ':\s*$'
#2.
fwstatus() { _fwstate=$(firewall-cmd --state 2>&1);printf "FIREWALLD=%s\n" "${_fwstate}";[[ "not running" == ${_fwstate} ]]&&return;_panicstate=$(firewall-cmd --query-panic);if [[ "on" == "${_panicstate}" ]];then printf "\e[41;1m";else printf "\e[32;1m";fi;printf "PANIC MODE=%s\e[m\n" "${_panicstate}";printf "LOCKDOWN=%s\n\n" "$(firewall-cmd --query-lockdown)";_defaultzone=$(firewall-cmd --get-default-zone);firewall-cmd --list-all-zones|sed 's/^'"$_defaultzone"'/& (default)/'|sed -n '/^'"$_defaultzone"'\|active/,/^$/p'|grep -v -e ':\s*$' -e icmp-block-inversion|awk 'NF>0'|grep --color -e$ -e^\w.\+;}&&fwstatus ## show full firewalling state,only works when firewalld is running
#3.
firewall-cmd --zone=YOUR_ZONE_HERE --list-all