Linux 服务器开启 firewalld 后,无法访问公网网站

275 天前
 hutoer

Linux 服务器开启 firewalld 后,无法访问公网网站

Linux OS:CentOS 7

没有启动 iptables 服务,仅仅启动 firewalld 服务,启动后一开始能访问公网网站,大约 5 分钟后,无法访问公网网站。

能 ping 通公网网站域名

# firewall-cmd --list-all
public (default, active)
  interfaces: eno1
  sources: 
  services: 
  ports: 58426/tcp 80/tcp
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
INPUT_direct  all  --  0.0.0.0/0            0.0.0.0/0           
INPUT_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           
INPUT_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
FORWARD_direct  all  --  0.0.0.0/0            0.0.0.0/0           
FORWARD_IN_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           
FORWARD_IN_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           
FORWARD_OUT_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           
FORWARD_OUT_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
OUTPUT_direct  all  --  0.0.0.0/0            0.0.0.0/0           

Chain FORWARD_IN_ZONES (1 references)
target     prot opt source               destination         
FWDI_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto] 
FWDI_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto] 

Chain FORWARD_IN_ZONES_SOURCE (1 references)
target     prot opt source               destination         

Chain FORWARD_OUT_ZONES (1 references)
target     prot opt source               destination         
FWDO_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto] 
FWDO_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto] 

Chain FORWARD_OUT_ZONES_SOURCE (1 references)
target     prot opt source               destination         

Chain FORWARD_direct (1 references)
target     prot opt source               destination         

Chain FWDI_public (2 references)
target     prot opt source               destination         
FWDI_public_log  all  --  0.0.0.0/0            0.0.0.0/0           
FWDI_public_deny  all  --  0.0.0.0/0            0.0.0.0/0           
FWDI_public_allow  all  --  0.0.0.0/0            0.0.0.0/0           

Chain FWDI_public_allow (1 references)
target     prot opt source               destination         

Chain FWDI_public_deny (1 references)
target     prot opt source               destination         

Chain FWDI_public_log (1 references)
target     prot opt source               destination         

Chain FWDO_public (2 references)
target     prot opt source               destination         
FWDO_public_log  all  --  0.0.0.0/0            0.0.0.0/0           
FWDO_public_deny  all  --  0.0.0.0/0            0.0.0.0/0           
FWDO_public_allow  all  --  0.0.0.0/0            0.0.0.0/0           

Chain FWDO_public_allow (1 references)
target     prot opt source               destination         

Chain FWDO_public_deny (1 references)
target     prot opt source               destination         

Chain FWDO_public_log (1 references)
target     prot opt source               destination         

Chain INPUT_ZONES (1 references)
target     prot opt source               destination         
IN_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto] 
IN_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto] 

Chain INPUT_ZONES_SOURCE (1 references)
target     prot opt source               destination         

Chain INPUT_direct (1 references)
target     prot opt source               destination         

Chain IN_public (2 references)
target     prot opt source               destination         
IN_public_log  all  --  0.0.0.0/0            0.0.0.0/0           
IN_public_deny  all  --  0.0.0.0/0            0.0.0.0/0           
IN_public_allow  all  --  0.0.0.0/0            0.0.0.0/0           

Chain IN_public_allow (1 references)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:58426 ctstate NEW
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80 ctstate NEW

Chain IN_public_deny (1 references)
target     prot opt source               destination         

Chain IN_public_log (1 references)
target     prot opt source               destination         

Chain OUTPUT_direct (1 references)
target     prot opt source               destination         

firewalld 的配置非常简单,仅仅打开 ports: 58426/tcp 80/tcp

大家给看看要如何排查

1279 次点击
所在节点    Linux
13 条回复
dode
275 天前
防火墙启动后只会阻止新建连接,所以开始可能能打开,你关掉浏览器程序,重新试试,
你的电脑有几个网口?
把对外服务的网口更改为 public 区域

firewall-cmd --zone=public --change-interface=xxx --permanent
LPLaser
275 天前
可能是 outpu 指向的 chain 里没有规则然后就默认 drop 掉了?
可以试试先把 OUPUT 的策略清空试试
hutoer
275 天前
@dode 没用浏览器,使用的是 curl 命令行
服务器 2 个网口
访问公网的网口是在 public 区域的

firewall-cmd --get-active-zones
public
interfaces: eno1
hutoer
275 天前
@LPLaser 规则是 firewalld 服务自动产生的
我看过能访问网站时和不能访问时的规则是一样的
dode
275 天前
还有就是网站 80 等端口备案问题,你换 8000 ,81 比较一下
ufok
275 天前
发网址出来,让大家搜一下
gvdlmjwje
275 天前
我就吐槽下 firewalld 的命令真是繁琐的一逼
GoodRui
275 天前
@gvdlmjwje 是和 ufw 比吗?目前 Linux 中好用成熟的防火墙都有哪些啊?
ysc3839
275 天前
@gvdlmjwje @GoodRui
个人觉得 firewalld 不用高级功能的话还是挺好用的,ufw 不支持端口转发,要用的时候更麻烦。
ShallowAi
275 天前
是无法入网(被访问)还是无法出网(向外 ping )?如果是无法入网需要检查是否备案,tcpping 指定 80 端口,不行再换个其他端口试试看。

一些其他说明:其实 firewalld 是个防火墙前端,底层调用 iptables (现在的实现是 nftables )。
hutoer
275 天前
@ShallowAi 是无法出网
busier
260 天前
@hutoer 能 ping 通公网网站域名说的不够明确!是一直在 ping 同一个,还是网不通后,再 ping 其它也能通。毕竟 dns 有缓存,而且一直 ping 的话,也不会重复 dns 解析。

既然始终能 ping 通,说明到达目标路由和 icmp 协议放行没问题

建议在不通的时候 用 nslookup 或 dig 诊断下 DNS
hutoer
260 天前
@busier 始终能 ping 通,与 DNS 无关。将域名改为公网 IP ,故障依旧。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/963238

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX