我有一台 Proxmox Linux 服务器,它能够向本地网络上的主机发送和接收数据包,但无法处理来自网关的数据包。这导致互联网流量失败,因此我无法运行 apt 来更新软件包。所有协议似乎都受到影响。
服务器上运行的虚拟机能可以正常访问网关。
我的 /etc/network/interfaces 文件包含:
auto lo
iface lo inet loopback
iface enp10s0 inet manual
auto vmbr0
iface vmbr0 inet static
address 10.0.1.200/24
gateway 10.0.1.1
bridge_ports enp10s0
bridge_stp off
bridge_fd 0
auto wlp7s0
iface wlp7s0 inet static
hostapd /etc/hostapd/hostapd.conf
address 10.0.2.1
netmask 255.255.255.0
auto vmbr1
iface vmbr1 inet static
address 10.1.2.1
netmask 255.255.255.0
bridge_ports none
bridge-stp off
bridge-fd 0
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s '10.1.2.0/24' -o wlp7s0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '10.1.2.0/24' -o wlp7s0 -j MASQUERADE
wlp7s0 和 vmbr1 经过 NAT,以允许 VM 访问不应访问一般网络/互联网的无线物联网设备。
我的路线表:
$ ip route
default via 10.0.1.200 dev vmbr0 metric 100
10.0.1.0/24 dev vmbr0 proto kernel scope link src 10.0.1.200
10.0.2.0/24 dev wlp7s0 proto kernel scope link src 10.0.2.1
10.1.2.0/24 dev vmbr1 proto kernel scope link src 10.1.2.1
读了一些资料后,我尝试更改 rp_filter,但将值从 2 更改为 0 并没有帮助。默认设置(删除了 VM 接口):
$ sysctl -a | grep \\.rp_filter
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.enp10s0.rp_filter = 0
net.ipv4.conf.lo.rp_filter = 0
net.ipv4.conf.vmbr0.rp_filter = 0
net.ipv4.conf.vmbr1.rp_filter = 0
net.ipv4.conf.wlp7s0.rp_filter = 0
ip_forward 已设置:
$ cat /proc/sys/net/ipv4/ip_forward
1
我已经通过 tcpdump 验证,当我尝试从服务器 ping 到网关或从服务器 ping 到网关时,网关会收到数据包。此示例使用 ping:
# tcpdump -n -i vmbr0 host 10.0.1.1 and icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on vmbr0, link-type EN10MB (Ethernet), capture size 262144 bytes
22:42:37.136341 IP 10.0.1.200 > 10.0.1.1: ICMP echo request, id 22073, seq 1, length 64
22:42:37.136478 IP 10.0.1.1 > 10.0.1.200: ICMP echo reply, id 22073, seq 1, length 64
22:42:38.142240 IP 10.0.1.200 > 10.0.1.1: ICMP echo request, id 22073, seq 2, length 64
22:42:38.142429 IP 10.0.1.1 > 10.0.1.200: ICMP echo reply, id 22073, seq 2, length 64
ping -v 的输出为空:
$ ping -v 10.0.1.1
PING 10.0.1.1 (10.0.1.1) 56(84) bytes of data.
^C
--- 10.0.1.1 ping statistics ---
22 packets transmitted, 0 received, 100% packet loss, time 511ms
IP 表中的唯一条目是 NAT:
# iptables-save -c
# Generated by iptables-save v1.8.2 on Sat Jan 29 22:45:46 2022
*raw
:PREROUTING ACCEPT [1828405583:1847667077335]
:OUTPUT ACCEPT [10762322:981310704]
COMMIT
# Completed on Sat Jan 29 22:45:46 2022
# Generated by iptables-save v1.8.2 on Sat Jan 29 22:45:46 2022
*filter
:INPUT ACCEPT [10597558:1212589593]
:FORWARD ACCEPT [1782904005:1841102268241]
:OUTPUT ACCEPT [10762351:981313827]
COMMIT
# Completed on Sat Jan 29 22:45:46 2022
# Generated by iptables-save v1.8.2 on Sat Jan 29 22:45:46 2022
*nat
:PREROUTING ACCEPT [29808561:4940456833]
:INPUT ACCEPT [2456738:231340403]
:OUTPUT ACCEPT [1168080:75403202]
:POSTROUTING ACCEPT [2829337:181352732]
[190:11400] -A POSTROUTING -s 10.1.2.0/24 -o wlp7s0 -j MASQUERADE
COMMIT
# Completed on Sat Jan 29 22:45:46 2022
答案1
感谢 Nikita Kipriyanov 为我指明正确的方向,我解决了这个问题。
跑步时
tcpdump -en host 10.0.1.1
我注意到 ping 响应来自系统上不存在的接口:
# tcpdump -en host 10.0.1.1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp10s0, link-type EN10MB (Ethernet), capture size 262144 bytes
10:01:49.233889 24:4b:fe:4a:11:96 > 02:29:9a:f3:0a:00, ethertype IPv4 (0x0800), length 98: 10.0.1.200 > 10.0.1.1: ICMP echo request, id 5544, seq 1, length 64
10:01:49.234053 02:29:9a:f3:0a:00 > 00:26:18:e2:68:f9, ethertype IPv4 (0x0800), length 98: 10.0.1.1 > 10.0.1.200: ICMP echo reply, id 5544, seq 1, length 64
这意味着系统在 tcpdump 下看到了具有正确 IP 地址的传入数据包,但正确地忽略了它们并根据 MAC 地址进行处理。
我检查了网关路由器上的配置,发现它有一个固定的 ARP 条目,其中包含该错误地址(可能是旧配置)。将网关的设置更改为 enp10s0 的 MAC 地址解决了该问题。