-1

我们有一个 openvpn 服务器(我相信我们的路由器)和移动客户端,这些客户端可以从很远的地方连接到互联网,但偶尔也会从我们办公室内部连接到互联网。这些系统是无头的,因此在连接到办公室网络之前对它们进行不同的配置是不可能的——我们希望通过它们的 avahi 主机名通过 SSH 连接到它们,而不管它们实际在哪里。

是的,当它们连接到我们网络之外的互联网时,我们可以 ping 和 SSH。当它们从我们的 LAN 内部连接时,有时会hostname.local解析为192.168.10.3(并且 ping 和 SSH 不起作用),有时会解析为(并且192.168.1.211ping 和 ssh 会起作用)。

在移动客户端上监控wireshark时,确实出现了对192.168.10.3地址的ping请求,但没有得到响应。

我们如何配置我们的客户端,以便在从我们的网络内部连接时可以访问它们?

客户端的输出ifconfig(通过我们的办公室 LAN 连接到 VPN):

eth0      Link encap:Ethernet  HWaddr 00:04:4b:a7:fa:e5  
          inet addr:192.168.1.223  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::7a45:f5b1:1b87:c6f0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8964 errors:0 dropped:0 overruns:0 frame:0
          TX packets:771 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1847719 (1.8 MB)  TX bytes:160760 (160.7 KB)
          Interrupt:42 

tap0      Link encap:Ethernet  HWaddr ce:d4:a6:18:48:21  
          inet addr:192.168.10.3  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::ccd4:a6ff:fe18:4821/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1381 errors:0 dropped:0 overruns:0 frame:0
          TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:214474 (214.4 KB)  TX bytes:7149 (7.1 KB)

客户端的输出route(通过我们的办公室 LAN 连接到 VPN):

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
default         192.168.10.1    0.0.0.0         UG    50     0        0 tap0
default         192.168.1.1     0.0.0.0         UG    100    0        0 eth0
link-local      *               255.255.0.0     U     1000   0        0 eth1
192.168.1.0     *               255.255.255.0   U     100    0        0 eth0
192.168.2.0     *               255.255.255.0   U     0      0        0 eth1
192.168.10.0    *               255.255.255.0   U     50     0        0 tap0

从同一 LAN 上的另一台机器到我们的移动客户端的背靠背 ping。无论出于何种原因,avahi.local名称都无法预测地解析为 VPN IP 或其他。无论如何,对 VPN IP(第二个)的 ping 只是挂起:

[15:51:25]~$ ping liber0.local
PING liber0.local (192.168.1.223) 56(84) bytes of data.
64 bytes from 192.168.1.223: icmp_seq=1 ttl=64 time=4.00 ms
64 bytes from 192.168.1.223: icmp_seq=2 ttl=64 time=6.09 ms
64 bytes from 192.168.1.223: icmp_seq=3 ttl=64 time=38.8 ms
^C
--- liber0.local ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 4.003/16.302/38.805/15.935 ms
[15:51:29]~$ ping liber0.local
PING liber0.local (192.168.10.3) 56(84) bytes of data.
^C
--- liber0.local ping statistics ---
27 packets transmitted, 0 received, 100% packet loss, time 26629ms

OpenVPN 配置文件:

client
dev tap
proto udp
remote <redacted>
float
resolv-retry infinite 
nobind
persist-key 
persist-tun 
verb 3
ca <redacted>.pem 
cert <redacted>.pem
key <redacted>.key
cipher AES-256-CBC
auth SHA256
4

1 回答 1

0

The key hint was that the ICMP packets made it to the VPN connected client, but were not answered. It turned out that the default rp_filter (reverse path filter) is the strictly checking and dropping packets. adding net.ipv4.conf.default.rp_filter = 2 to /etc/sysctl.conf sets rp_filter to loose reverse path checking, and everything works.

于 2018-06-26T15:58:26.913 回答