OpenWRT上的OpenVPN:通过VPN隧道路由特定的子网

我已经安装了安装了OpenWRT 15.05的路由器(Chaos Calmer),并configuration了两个Wi-Finetworking,每个networking都有自己的networking接口:

  • wi-fi-1 :接口br-lan ip address 10.0.2.1; 地址范围10.0.2.0/24
  • wi-fi-2 :接口br-vpn ip地址10.0.10.1; 地址范围10.0.10.0/24

我configuration了OpenVPN客户端软件连接到vpn服务vpnservice1 。 在OpenWRT系统日志中,我可以看到openvpn客户端成功连接到vpnservice1并打开了接口tun0

我的目标是通过默认网关路由来自networkingwi-fi-1 (10.0.2.0/24)的所有stream量; 并通过vpn接口tun0路由在Wi-Fi-2 (10.0.10.0/24)上的所有互联网绑定的stream量。 注意。 我仍然希望连接到wi-fi-2networking(10.0.10.0/24)的设备能够连接到此networking上的其他设备。

通过我目前的configuration, wi-fi-1networking上的设备可以通过默认网关连接到互联网。 但是连接到wi-fi-2的设备无法连接到互联网。 任何援助是欢迎:)

我的configuration如下所述:

  1. 防火墙configuration(/ etc / config / firewall):

    config rule config rule option src 'wan' option dest 'lan' option proto 'esp' option target 'ACCEPT' config rule option src 'wan' option dest 'lan' option dest_port '500' option proto 'udp' option target 'ACCEPT' config zone option input 'ACCEPT' option output 'ACCEPT' option name 'stream' option network 'stream' option masq '1' option forward 'ACCEPT'
    config zone option input 'ACCEPT' option output 'ACCEPT' option name 'stream_vpn' option forward 'ACCEPT' option network 'stream_vpn' option masq '1' config forwarding option dest 'stream' option src 'stream_vpn' config forwarding option dest 'stream_vpn' option src 'stream'

  2. networkingconfiguration(/ etc / config / network):

    config interface 'lan' option ifname 'eth1' option force_link '1' option type 'bridge' option proto 'static' option netmask '255.255.255.0' option ip6assign '60' option ipaddr '10.0.2.1' config interface 'wan' option ifname 'eth0' option proto 'dhcp' config interface 'stream_vpn' option proto 'none' option ifname 'tun0' config interface 'stream' option proto 'static' option ipaddr '10.0.10.1' option netmask '255.255.255.0' option type 'bridge' option _orig_ifname 'stream_lan wlan1-2' option _orig_bridge 'true' option ifname 'stream_lan'

  3. OpenVPN客户端'vpnservice1'configuration(/ etc / openvpn):

config openvpn 'vpnservice1' option dev_type 'tun' option client '1' option resolv_retry 'infinite' option persist_tun '1' option persist_key '1' option tun_ipv6 '1' option cipher 'AES-256-CBC' option remote_random '0' option route_delay '2' option route_nopull '1' option route '10.0.10.1 255.255.255.255' option auth_retry 'interact' option auth 'SHA1' option remote_cert_tls 'server' option reneg_sec '0' option tls_client '1' option verb '3' option mute '20' option float '1' option ifconfig_nowarn '1' option auth_user_pass '/etc/openvpn/vpnservice1/userpass.txt' option port '1194' option remote 'vpnservice1.com' option auth_nocache '1' option dev 'tun0' option proto 'udp' option comp_lzo 'adaptive' option enabled '1' option fast_io '1' option tun_mtu '1500' option tun_mtu_extra '32' option ca '/etc/openvpn/vpnservice1/vpnservice1_com.crt' option ping '15' option ping_restart '0' option tls_auth '/etc/openvpn/vpnservice1/vpnservice1_com_tls.key 1' option script_security '2'

  1. 接口列表(ifconfig -a):

    br-lan Link encap:Ethernet HWaddr C0:56:27:7A:92:D3 inet addr:10.0.2.1 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::c256:27ff:cd56:92a1/64 Scope:Link inet6 addr: fd1d:c378:aa11::1/60 Scope:Global UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:15469 errors:0 dropped:0 overruns:0 frame:0 TX packets:15465 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2029206 (1.9 MiB) TX bytes:9594955 (9.1 MiB) br-vpn Link encap:Ethernet HWaddr 06:25:9C:13:97:F5 inet addr:10.0.10.1 Bcast:10.0.10.255 Mask:255.255.255.0 inet6 addr: fe80::425:cc22:ab34:22e1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:640 errors:0 dropped:0 overruns:0 frame:0 TX packets:566 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:101972 (99.5 KiB) TX bytes:71890 (70.2 KiB) eth0 Link encap:Ethernet HWaddr C2:56:27:7A:92:D3 inet addr:10.0.1.21 Bcast:10.0.1.255 Mask:255.255.255.0 inet6 addr: fe80::c056:34ff:abcd:84d3/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:13175 errors:0 dropped:0 overruns:0 frame:0 TX packets:12879 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:532 RX bytes:8697083 (8.2 MiB) TX bytes:1939234 (1.8 MiB) Interrupt:194 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.8.134 PtP:10.8.8.133 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)

  2. 路由列表(route -n):

    Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.1.1 0.0.0.0 UG 0 0 0 eth0 10.0.10.0 0.0.0.0 255.255.255.0 U 0 0 0 br-vpn 10.0.10.1 205.1.2.3 255.255.255.255 UGH 0 0 0 tun0 205.1.2.3 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 0 0 0 eth0 10.0.1.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 br-lan

应该可以使用iproute2软件包:

 opkg update opkg install ip 

我刚开始使用它,所以我想我只能提供一些提示,没有适合您的具体情况的工作解决scheme。 使用iproute2,您可以实施策略路由(条件路由)。 在你的情况下,你需要两个不同的路由为你的两个设备(br-lan和br-vpn)。 对于networking来说,这似乎已经到位了。 现在,您需要通过您的tun0设备和vpn路由来自br-vpn(或其代表的子网)的所有stream量。

我的猜测会是这样的(可能不工作,但希望能让你朝着正确的方向前进):

编辑/ etc / iproute2 / rt_tables并添加这一行

 0 admin 

然后:

 ip rule add from 10.0.10.0/24 table admin ip route add default dev tun0 table admin 

直觉:为来自10.0.10.0/24子网的所有stream量添加一条规则,并告诉iproute2查看pipe理表,了解如何处理这个问题。 然后你在你的pipe理表中添加一个默认规则,默认路由一切通过你的VPN。

我有点困惑你的configuration。 你确定“route -n”输出和ifconfig和/ etc / config / network输出是来自同一个会话吗?

请注意,这些更改不会反映在“route -n”中,而是看看

 ip rule list ip route show table admin 

@porchez我尝试了你所build议的改变。 我安装了iproute2软件包。

在/ etc / iproute2 / rt_tables中添加了这一行

 0 admin 

我创build了一个新的shell脚本/etc/openvpn/guest-up.sh并添加了行

 ip rule add from 10.0.10.0/24 table admin ip route add default dev tun0 table admin 

在我的openvpnconfiguration文件(/ etc / config / openvpn)中添加了选项

 option script_security '2' option up '/etc/openvpn/guest-up.sh' 

重新启动VPN会话后,syslog条目指示vpn会话已成功连接。 然而,Wi-Finetworking不通过VPN连接到互联网。

运行ip route list显示

 0: from all lookup 128 0: from 10.0.10.0/24 lookup 1 0: from 10.0.10.0/24 lookup 2 0: from 10.0.10.0/24 lookup 3 0: from 10.0.10.0/24 lookup 4 0: from 10.0.10.0/24 lookup 5 0: from 10.0.10.0/24 lookup 6 0: from 10.0.10.0/24 lookup 7 0: from 10.0.10.0/24 lookup 8 

运行命令ip route show table admin | grep "10.0.10.0 ip route show table admin | grep "10.0.10.0返回

 10.0.10.0/24 dev br-vpn proto kernel scope link src 10.0.10.1 broadcast 10.0.10.0 dev br-vpn table local proto kernel scope link src 10.0.10.1 

道歉我是相当新的Linuxnetworking和路由。