java多播数据包未正确到达podman内部。找到了解决方法,但不清楚是防火墙问题还是播客问题?
我对firewalld、podman和UDP/多播越来越着迷。当我看到UDP数据包到达podman时;使用tcpdump
命令确认。似乎我无法使用名为knx_multicast
的自定义防火墙区域进行配置,该区域仅在UDP数据包来自多播组224.0.23.12:3671
时才应接受
给出用Java编写的最小示例:
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
public class Test {
public static void main(String[] args) throws Throwable {
final var group = InetAddress.getByName("224.0.23.12");
final var s = new MulticastSocket(3671);
final var ni = NetworkInterface.getByName("enp1s0");
s.setNetworkInterface(ni);
s.joinGroup(group);
System.out.println("Start listening ... @" + ni );
final var buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
s.receive(recv);
System.out.println(recv.getData());
s.leaveGroup(group);
s.close();
}
}
我已将firewalld配置为:
knx_multicast (active)
target: default
icmp-block-inversion: no
interfaces:
sources: 224.0.23.12
services:
ports: 3671/udp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
public (active)
target: default
icmp-block-inversion: no
interfaces: enp1s0
sources:
services: cockpit dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
在CentOS 8.1上测试多播数据包
现在,我首先在CentOS 8.1中运行测试,它作为我获取一些数据的工具工作(请参见下面的:[B@61a52fbd
)
[root@PIT-Server ~]# javac Test.java && java Test
Start listening ... @name:enp1s0 (enp1s0)
[B@61a52fbd
在CentOS 8.1上使用PODMAN测试多播数据包
下一步是使用:podman run --rm -it --net host docker.io/adoptopenjdk/openjdk11 /bin/bash
在运行于“Ubuntu18.04.3 LTS”上的podman容器中进行测试(图:“采用OpenJDK/openjdk11:latest”)
在podman中,我还看到来自PIT-KNX(KNX路由器)的UDP数据包
root@PIT-Server:/tcpdump -i enp1s0 udp port 3671
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp1s0, link-type EN10MB (Ethernet), capture size 262144 bytes
19:49:35.583901 IP PIT-KNX.pit-router.3671 > 224.0.23.12.3671: UDP, length 17
19:49:36.032139 IP PIT-KNX.pit-router.3671 > 224.0.23.12.3671: UDP, length 18
... lines omitted ...
启动相同的java应用程序(在容器环境之外工作)时,我无法获取任何数据(在“开始侦听”之后没有到达字节数组)
root@PIT-Server:/# javac Test.java && java Test
Start listening ... @name:enp1s0 (enp1s0)
解决方法(防火墙)
在调查了几个小时/咖啡后,我发现允许区域中的端口=knx_多播是不够的。我还必须使用:firewall-cmd --add-port=3671/udp
将端口添加到zone=public
。firewalld的配置现在是:
knx_multicast (active)
target: default
icmp-block-inversion: no
interfaces:
sources: 224.0.23.12
services:
ports: 3671/udp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
public (active)
target: default
icmp-block-inversion: no
interfaces: enp1s0
sources:
services: cockpit dhcpv6-client ssh
ports: 3671/udp <== ADDED!!!! (that one fixes the problem)
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
在CentOS 8.1上使用PODMAN重新测试多播数据包
通过重新运行java应用程序,我现在可以看到到达的UDP多播数据包(请参阅下面的:[B@61a52fbd
)
root@PIT-Server:/# javac Test.java && java Test
Start listening ... @name:enp1s0 (enp1s0)
[B@61a52fbd
我的问题。。。发生了什么事?下一步强>
有人能帮我弄清楚到底是什么问题吗?为什么我也必须向zone=public
添加端口?在我这方面,这是一个bug还是一个配置问题?如何在不将端口添加到zone=public
的情况下解析它?我有误会吗
如果只添加一个新的firewalld区域(称为knx_multicast
),我会感到更舒服;并保持防火墙dpublic
区域的配置不变。建议
谢谢你,克里斯托夫
# 1 楼答案
感谢@Ron Maupin指出了这个问题。我的防火墙配置错误
该问题已通过创建新服务得到解决:
为了能够添加新创建的服务,请重新加载firewalld并添加它
这将创建一个包含以下内容的服务文件:
/etc/firewalld/services/knx.xml
:防火墙配置如下所示: