jon*_*our 5 openvpn ping tcpdump ip-forwarding
我们正在为在云中运行的一些服务器设置 OpenVPN 服务器。我们被一个连接问题难住了,VPN 服务器的 LAN 上的主机可以 ping te VPN 客户端,但反之则不然。
VPN 客户端可以在其 VPN 地址上 ping VPN 服务器,但不能在其 LAN 地址上 ping 通。
tcpdump 显示来自客户端的 ping 数据包到达主机并发出回复的证据,但由于某种原因,回复从未到达 VPN 服务器或客户端上的 tun0 接口。相反,根据 tcpdump,从 VPN 服务器的 LAN 到 VPN 客户端的 ping 请求的流量在所有预期的接口上都可以看到。
下面给出了我们迄今为止的配置和故障排除的详细说明。
该问题似乎与从服务器网络上的地址转发回客户端网络有关。真正奇怪(对我而言)是 LAN 发起的 ping 可以进行完整的往返,但是客户端发起的 ping 似乎在 VPN 服务器的 tun0 和 eth1 接口之间的某个地方被丢弃。
我们缺少什么?
3台主机:
两台服务器都是虚拟机,运行 RHEL 5.7。我认为(但不完全确定)虚拟主机环境是 VMWare。
但:
对于 10.11.11.7 和 10.8.0.22 之间的 ping 测试:
对于 10.11.11.2 和 10.8.0.22 之间的 ping 测试:
对于 10.8.0.22 和 10.11.11.2 之间的 ping 测试:
对于 10.8.0.22 和 10.11.11.7 之间的 ping 测试:
ip_fowarding 已在 VPN 服务器上启用 rp_filter 已在 VPN 服务器上为除面向 Internet 的接口 eth0 之外的所有接口禁用。
出于调试底层问题的目的,iptables 已在客户端上使用(默认接受)规则禁用。
我已经为每个主机上的相关接口包含了路由 -n 和 ifconfig 的转储。
$ /sbin/route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.8.0.2 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
10.11.11.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
10.8.0.0 10.8.0.2 255.255.255.0 UG 0 0 0 tun0
x.x.x.x 0.0.0.0 255.255.248.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
0.0.0.0 x.x.x.x 0.0.0.0 UG 0 0 0 eth0
$ find /proc/sys/net -name 'rp_filter' | while read f
> do echo $f $(cat $f)
> done
/proc/sys/net/ipv4/conf/tun0/rp_filter 0
/proc/sys/net/ipv4/conf/eth1/rp_filter 0
/proc/sys/net/ipv4/conf/eth0/rp_filter 1
/proc/sys/net/ipv4/conf/lo/rp_filter 0
/proc/sys/net/ipv4/conf/default/rp_filter 0
/proc/sys/net/ipv4/conf/all/rp_filter 0
$ cat /proc/sys/net/ipv4/ip_forward
1
$ sudo /sbin/iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
$ /sbin/ifconfig -a
eth0 Link encap:Ethernet HWaddr DE:AD:BE:A6:28:21
inet addr:x.x.x.x Bcast:x.x.x.x Mask:255.255.248.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:233929 errors:0 dropped:0 overruns:0 frame:0
TX packets:24776 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:27881415 (26.5 MiB) TX bytes:30534780 (29.1 MiB)
eth1 Link encap:Ethernet HWaddr DE:AD:BE:3B:24:48
inet addr:10.11.11.2 Bcast:10.11.11.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4929 errors:0 dropped:0 overruns:0 frame:0
TX packets:10209 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:423658 (413.7 KiB) TX bytes:863546 (843.3 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:11992 errors:0 dropped:0 overruns:0 frame:0
TX packets:11992 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:34820967 (33.2 MiB) TX bytes:34820967 (33.2 MiB)
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.8.0.1 P-t-P:10.8.0.2 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:69 errors:0 dropped:0 overruns:0 frame:0
TX packets:57 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:5796 (5.6 KiB) TX bytes:4788 (4.6 KiB)
$ uname -a
Linux vhost0273 2.6.18-274.el5 #1 SMP Fri Jul 8 17:36:59 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
$ ping -c1 10.8.0.22 -w 1
PING 10.8.0.22 (10.8.0.22) 56(84) bytes of data.
64 bytes from 10.8.0.22: icmp_seq=1 ttl=64 time=145 ms
--- 10.8.0.22 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 145.676/145.676/145.676/0.000 ms
$ ping -c1 10.11.11.7 -w 1
PING 10.11.11.7 (10.11.11.7) 56(84) bytes of data.
64 bytes from 10.11.11.7: icmp_seq=1 ttl=64 time=0.794 ms
--- 10.11.11.7 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.794/0.794/0.794/0.000 ms
Run Code Online (Sandbox Code Playgroud)
$ /sbin/ifconfig -a
eth0 Link encap:Ethernet HWaddr DE:AD:BE:7F:45:72
inet addr:10.11.11.7 Bcast:10.11.11.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:33897 errors:0 dropped:0 overruns:0 frame:0
TX packets:38294 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2536157 (2.4 MiB) TX bytes:8910725 (8.4 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:77779 errors:0 dropped:0 overruns:0 frame:0
TX packets:77779 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
$ /sbin/route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.11.11.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.8.0.0 10.11.11.2 255.255.255.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 10.11.11.2 0.0.0.0 UG 0 0 0 eth0
$ ping -c1 10.8.0.1 -w 1
PING 10.8.0.1 (10.8.0.1) 56(84) bytes of data.
64 bytes from 10.8.0.1: icmp_seq=1 ttl=64 time=0.516 ms
--- 10.8.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.516/0.516/0.516/0.000 ms
$ ping -c1 10.8.0.22 -w 1
PING 10.8.0.22 (10.8.0.22) 56(84) bytes of data.
64 bytes from 10.8.0.22: icmp_seq=1 ttl=63 time=146 ms
--- 10.8.0.22 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 146.913/146.913/146.913/0.000 ms
$ ping -c1 10.11.11.2 -w 1
PING 10.11.11.2 (10.11.11.2) 56(84) bytes of data.
64 bytes from 10.11.11.2: icmp_seq=1 ttl=64 time=0.775 ms
--- 10.11.11.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.775/0.775/0.775/0.000 ms
Run Code Online (Sandbox Code Playgroud)
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.8.0.22 P-t-P:10.8.0.21 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
$ /sbin/route -n | grep ^10
10.8.0.21 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
10.8.0.1 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
10.0.1.0 0.0.0.0 255.255.255.0 U 2 0 0 wlan0
10.1.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
10.11.11.0 10.8.0.1 255.255.255.0 UG 0 0 0 tun0
$ ping 10.8.0.1
PING 10.8.0.1 (10.8.0.1) 56(84) bytes of data.
64 bytes from 10.8.0.1: icmp_seq=1 ttl=64 time=145 ms
$ ping 10.8.0.2 -w 1
PING 10.8.0.2 (10.8.0.2) 56(84) bytes of data.
--- 10.8.0.2 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
$ ping 10.11.11.2 -w 1
PING 10.11.11.2 (10.11.11.2) 56(84) bytes of data.
--- 10.11.11.2 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
$ ping 10.11.11.7 -w 1
PING 10.11.11.7 (10.11.11.7) 56(84) bytes of data.
--- 10.11.11.7 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 999ms
Run Code Online (Sandbox Code Playgroud)
此问题的根本原因是一些隐式默认路由在 /sbin/route 显示的表中不可见,但在 /sbin/ip 路由和 /sbin/ip 规则显示的表中可见。
然后显示这些表格,很明显存在这样的规则:
default table route_eth0 via 10.11.11.1 dev eth0
Run Code Online (Sandbox Code Playgroud)
覆盖了这个规则:
10.8.0.0 10.11.11.2 255.255.255.0 UG 0 0 0 eth0
Run Code Online (Sandbox Code Playgroud)
通过编辑 /etc/sysconfig/network-scripts/route-eth0 (大概是使用 /sbin/ip 路由,尽管在本例中是手动完成的),我能够解决这个问题。
因此,我从中学到的是,不能依赖 /sbin/route 来准确了解 Linux 的有效路由规则,最好使用 /sbin/ip 来实现此目的。
感谢 ptman 对这个问题的回答帮助我看到了光明。谢谢普特曼!
归档时间: |
|
查看次数: |
12316 次 |
最近记录: |