我有一个Linux设备运行无线热点:
my laptop (LAN only: 192.168.1.100)
|
LAN
|
wireless hotspot laptop (LAN: 192.168.1.101, wireless hotspot: 10.42.0.1, VMs: 10.254.2.x)
|
wireless printer (wifi: 10.42.0.67)从我的笔记本电脑上,我可以使用它的LAN (192.168.1.101)平/连接到无线热点笔记本电脑。
在我的笔记本电脑上添加了以下路由之后,我还可以打开/连接到它的无线热点IP (10.42.0.1):
ip route add to 10.42.0.0/24 via 192.168.1.101
如果我添加了以下路由规则,我也可以在笔记本电脑上ping/连接到am:
ip route add to 10.254.2.0/24 via 192.168.1.101
然而,点击/连接到无线网络中的任何东西(10.42.0.0/24) -没有骰子,得到“无法到达的目的端口”:
# ping 10.42.0.67
PING 10.42.0.67 (10.42.0.67) 56(84) bytes of data.
From 192.168.1.101 icmp_seq=1 Destination Port Unreachable
From 192.168.1.101 icmp_seq=2 Destination Port Unreachable
^C
--- 10.42.0.67 ping statistics ---
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1001ms在无线热点笔记本上添加以下伪装规则允许我的笔记本电脑与8.8.8.8进行通信:
iptables -t nat -A POSTROUTING -s 192.168.1.100 -j MASQUERADE无线热点膝上型计算机上的tcpdump表示从我的笔记本到8.8.8.8的通信量正在通过它:
# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=44.4 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=46.9 ms
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 44.425/45.668/46.912/1.243 ms但是,连接到10.42.0.67 (无线热点后面的无线打印机)-没有骰子(下面是无线热点上的tcpdump ):
01:25:20.901823 enp1s0 In IP (tos 0x0, ttl 64, id 37541, offset 0, flags [DF], proto ICMP (1), length 84)
192.168.1.100 > 10.42.0.67: ICMP echo request, id 216, seq 16, length 64
01:25:20.902038 enp1s0 Out IP (tos 0xc0, ttl 64, id 11555, offset 0, flags [none], proto ICMP (1), length 112)
192.168.1.101 > 192.168.1.100: ICMP 10.42.0.67 protocol 1 port 12067 unreachable, length 92
IP (tos 0x0, ttl 63, id 37541, offset 0, flags [DF], proto ICMP (1), length 84)
192.168.1.100 > 10.42.0.67: ICMP echo request, id 216, seq 16, length 64wifi有什么特别之处吗? Linux不想路由,NAT也不想进入它?
当前的nftable规则如下;lxd部件涉及运行在那里的容器;nm-shared-wlp2s0与无线热点有关;没有iptables规则(在上面的示例中没有我的伪装):
table inet lxd {
chain pstrt.lxdbr0 {
type nat hook postrouting priority srcnat; policy accept;
ip saddr 10.254.2.0/24 ip daddr != 10.254.2.0/24 masquerade
}
chain fwd.lxdbr0 {
type filter hook forward priority filter; policy accept;
ip version 4 oifname "lxdbr0" accept
ip version 4 iifname "lxdbr0" accept
}
chain in.lxdbr0 {
type filter hook input priority filter; policy accept;
iifname "lxdbr0" tcp dport 53 accept
iifname "lxdbr0" udp dport 53 accept
iifname "lxdbr0" icmp type { destination-unreachable, time-exceeded, parameter-problem } accept
iifname "lxdbr0" udp dport 67 accept
}
chain out.lxdbr0 {
type filter hook output priority filter; policy accept;
oifname "lxdbr0" tcp sport 53 accept
oifname "lxdbr0" udp sport 53 accept
oifname "lxdbr0" icmp type { destination-unreachable, time-exceeded, parameter-problem } accept
oifname "lxdbr0" udp sport 67 accept
}
}
table ip nm-shared-wlp2s0 {
chain nat_postrouting {
type nat hook postrouting priority srcnat; policy accept;
ip saddr 10.42.0.0/24 ip daddr != 10.42.0.0/24 masquerade
}
chain filter_forward {
type filter hook forward priority filter; policy accept;
ip daddr 10.42.0.0/24 oifname "wlp2s0" ct state { established, related } accept
ip saddr 10.42.0.0/24 iifname "wlp2s0" accept
iifname "wlp2s0" oifname "wlp2s0" accept
iifname "wlp2s0" reject
oifname "wlp2s0" reject
}
}发布于 2022-07-18 09:43:18
在命名过程中,您的系统有两个应用防火墙规则的工具: LXD (它不干扰:没有任何掉落或拒绝)和另一个工具,您必须从它选择的命名: table nm-shared-wlp2s0中找出它。
您必须弄清楚这是什么工具,并配置此工具,以添加一个异常,以从您的另一个LAN到达打印机的网络。
同时,在许多等效的选择中,您可以手动完成此操作。例如,从另一个LAN向此LAN启用传入数据包:
nft insert rule nm-shared-wlp2s0 filter_forward ip saddr 192.168.1.0/24 ip daddr 10.42.0.0/24 oifname "wlp2s0" ct state new accept每次工具重新配置防火墙规则时都必须这样做(希望它不会“主动”删除您的规则)。
此外,这个表(以及创建它的工具)没有遵循在拒绝数据包之前丢弃无效数据包的最佳实践。拒绝(而不是丢弃)无效数据包会导致问题,特别是重新排序的数据包。有关详细信息,请参阅iptables引号后面的说明(但也影响nftable):
警告:您不应该不加区别地将拒绝目标应用于连接状态被归类为无效的数据包;相反,您应该只删除这些数据包。
或者,在前面的命令之后,也应该添加以下内容:
nft insert rule nm-shared-wlp2s0 filter_forward index 2 ct state invalid drop为了防止重新排序的数据包可能发生的流中断(Wifi可以创建此条件)。
请注意,nftable中的每个表都提供了有可能影响数据包的钩链的机会。即使一个表的链接受了一个数据包,它仍然可以被丢弃在另一个链接中,链接到相同的位置:这里有两条链连接在Netfilter的过滤器/转发:inet lxd fwd.lxdbr0和ip nm-shared-wlp2s0 filter_forward:它们都有机会丢弃一个数据包。
https://unix.stackexchange.com/questions/710212
复制相似问题