firewalld 停止到特定 IP 地址的传出流量

leo*_*587 5 redhat centos firewalld

我有centos 7。我试图阻止从服务器到特定IP地址的所有出站流量,但firewalld不会阻止流量。这就是我所做的:

[root@server network-scripts]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources:
  services: dhcpv6-client ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
        rule family="ipv4" destination address="134.223.116.100" drop

[root@server network-scripts]# firewall-cmd --get-active-zones
public
  interfaces: ens192

[root@server network-scripts]# firewall-cmd --state
running
Run Code Online (Sandbox Code Playgroud)

但我仍然可以curl到ip地址,那么有什么问题吗?

[root@server network-scripts]# curl 134.223.116.100
<HTML><HEAD>
<TITLE>Access Denied</TITLE>
Run Code Online (Sandbox Code Playgroud)

HBr*_*ijn 8

我不喜欢从前端调试防火墙问题,更喜欢使用[sudo] iptables -L -v -n或查看实际的规则集[sudo] iptables-save
认为这将表明您的丰富规则仍然仅适用于传入连接,而不是传出连接。

要对除传入流量之外的任何内容使用防火墙,据我所知相当难以实现,您可能必须诉诸直接规则

 sudo firewall-cmd --direct --add-rule ipv4 filter OUTPUT 0 -d 134.223.116.100/32  -j REJECT
Run Code Online (Sandbox Code Playgroud)