无法在我的Ubuntu中添加静态路由,SIOCADDRT:networking无法访问

我试图在我的VPS中添加一个静态路由到位于VPN隧道另一端的客户端,并通过隧道转发它。

这是我计划添加路线的目的地的设置。 Raspi作为一个路由器,它本身连接到一个AP,NAS连接到Raspi,并通过VPN隧道redirect它的stream量:

+--------------------------------+ | Raspi | (192.168.0.101/24)| |(192.168.1.1/24) (192.168.0.1/24) AP<>=================={wlan0 eth0}================<>NAS (192.168.1.102/24) | \ / | | +----------------------+ | | | iptables and | | | | routing engine | | | +-----------+----------+ | | | | | {tun0} | | 10.8.0.6 | +--------------------------------+ 

我试图做的route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.8.0.6 ,为了与Raspi后面的我的NAS通信,但它得到SIOCADDRT: Network is unreachable

这些是服务器端信息:

$ ifconfig -a

 eth0 Link encap:Ethernet HWaddr XX:XX:XX:XX:XX:XX inet addr:217.BCD Bcast:217.BCD Mask:255.255.255.255 inet6 addr: XXXX::XXX:XXXX:XXXX:XXXX/XX Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1598 errors:0 dropped:0 overruns:0 frame:0 TX packets:1453 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:176137 (176.1 KB) TX bytes:165179 (165.1 KB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:9 errors:0 dropped:0 overruns:0 frame:0 TX packets:9 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:460 (460.0 B) TX bytes:460 (460.0 B) 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 PtP:10.8.0.2 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:169 errors:0 dropped:0 overruns:0 frame:0 TX packets:183 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:14825 (14.8 KB) TX bytes:15071 (15.0 KB) 

$ netstat -anr

 Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 10.255.255.1 0.0.0.0 UG 0 0 0 eth0 10.8.0.0 10.8.0.2 255.255.255.0 UG 0 0 0 tun0 10.8.0.2 0.0.0.0 255.255.255.255 UH 0 0 0 tun0 10.255.255.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0 

$ ip路由列表

 default via 10.255.255.1 dev eth0 10.8.0.0/24 via 10.8.0.2 dev tun0 10.8.0.2 dev tun0 proto kernel scope link src 10.8.0.1 10.255.255.1 dev eth0 scope link 

附加信息:

如果你想知道如何实现接口之间的stream量redirect,下面是我的post,描述了如何使用iptablespipe理所有事情:

https://unix.stackexchange.com/questions/273926/redirect-secondary-network-interface-traffic-along-with-port-forwarding-to-tun0

客户端networking块(在p2p拓扑中 ):

 10.8.0.4 : Network address 10.8.0.5 : Virtual remote endpoint; Non pingable; Only used for routing 10.8.0.6 : Client IP address 10.8.0.7 : Network broadcast address 

更新1:

我已将VPN服务器configuration更改为topology subnet ,并将VPN客户端的相应ccd文件中的ifconfig-push 10.8.0.6 255.255.255.0更改为/24子网中的VPN服务器和客户端,而不是/32 ,然后添加路线。 这次route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.8.0.6route add -net 192.168.1.0 netmask 255.255.255.0 dev tun0没有返回错误,但仍然没有ping 192.168.1.102netstat -anr虽然改变( route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.8.0.6 )。

 Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 10.255.255.1 0.0.0.0 UG 0 0 0 eth0 10.8.0.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0 10.255.255.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0 192.168.1.0 10.8.0.6 255.255.255.0 UG 0 0 0 tun0 

我阅读说明:

https://openvpn.net/index.php/open-source/documentation/howto.html#scope

我已经添加了route 192.168.1.0 255.255.255.0到我的VPS上的server.conf ,并且还将iroute 192.168.1.0 255.255.255.0到客户端的对应ccd文件。 然后我用命令route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.8.0.6就是这样! 我可以从我的VPS:D上ping我的OpenVPN客户端后面的192.168.1.102客户端

PS:我仍然在subnet topology模式。 我没有在正常的p2p topology尝试过,但我认为它应该工作得很好。