带有 IP 别名的防火墙 (eth0:0)

bnx*_*bnx 5 firewalld centos7

(找到解决方案,见下文...)

服务器 (CentOS 7) 有多个公共 IP,这些都是通过常用的ifcfg-eth0:0配置文件设置的,并且运行良好。我正在尝试适应 firewalld(来自 iptables)。我喜欢能够为每个 IP 别名指定开放端口 - 使用 iptables,只需将目标 IP 设置为匹配端口所需的任何别名即可完成。

认为使用 firewalld 我可以对每个接口应用不同的区域以达到相同的效果,但似乎我不能这样做。

我们从:

# firewall-cmd --get-active-zones
public
  interfaces: eth0 eth0:0
trusted
  interfaces: eth1
Run Code Online (Sandbox Code Playgroud)

我创建了一个public_web我想用于的新区域eth0:0

# firewall-cmd --permanent --new-zone=public_web
success
# firewall-cmd --permanent --zone=public_web --add-service=http
success
# firewall-cmd --permanent --zone=public_web --add-interface=eth0:0
success
# firewall-cmd --reload
success
Run Code Online (Sandbox Code Playgroud)

但...

# firewall-cmd --get-active-zones
public
  interfaces: eth0 eth0:0
trusted
  interfaces: eth1
Run Code Online (Sandbox Code Playgroud)

我尝试了--remove-interface--change-interface以及各种顺序的各种其他命令,但eth0:0不会让步。我似乎无法在任何地方找到任何关于使用别名的文档,所以我不确定这是否是实现我想要的正确方法?

谢谢大家。


解决方案:

解决方案是destination在服务文件中使用标签,每个服务只能使用一次。

因此,假设您想要 87.98.256.512 上的端口 443,将https.xml文件复制(建议您不要触摸原件)到/etc/firewalld/services,在这里我将使用https-admin.xml

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>HTTPS for 87.98.256.512</short>
  <description>...</description>
  <port protocol="tcp" port="443"/>
  <destination ipv4="87.98.256.512" />
</service>
Run Code Online (Sandbox Code Playgroud)

然后

# firewall-cmd --permanent --zone=public --add-service=https-admin
success
# firewall-cmd --reload
success
# firewall-cmd --zone=public --list-services
http https-admin
Run Code Online (Sandbox Code Playgroud)

最后用 iptables 确认这一点

Chain IN_public_allow (1 references)
target     prot opt source               destination
ACCEPT     tcp  --  0.0.0.0/0            87.98.256.512        tcp dpt:443 ctstate NEW
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80 ctstate NEW
Run Code Online (Sandbox Code Playgroud)

请记住:destination每个服务只有一个标签,所以如果这是您的要求,只需制作多个服务。

Zor*_*che 5

整个界面别名功能都是过去遗留下来的。它实际上并没有创建一个单独的界面。很长一段时间以来,您都不需要使用别名为单个接口分配多个 IP。因为它不是一个“真实”的界面,你的防火墙软件不能把它当作一个真实的界面来对待。如果您使用该ip addr命令,您将看到所有地址都分配给了主接口,并且eth0:0被简单地视为该地址的标签。

考虑到所有这些,我不完全确定您需要做什么来调整您的防火墙。我怀疑您可能需要按 IP 指定端口,而不是按 IP 地址而不是别名。