如何将所有互联网流量重定向到 OpenVPN 服务器

如何将所有互联网流量重定向到 OpenVPN 服务器

我已经看到了一些解决强制互联网流量通过 OpenVPN 服务器的问题的有效解决方案,但它们都是在 Linux 中完成的,我只想知道如何在 Windows 中的路由表中添加条目以实现这一点。客户端和服务器之间的连接很好,我的 Windows 7 客户端可以建立与 Windows 2008 Server 的连接,但是建立互联网流量后,仍然从本地 Windows 7 计算机传输。以下是详细信息:

服务器:

Windows 2008 Server with one NIC
OpenVPN IP Address: 192.168.0.1
Local NIC IP Address (connects the server to the Internet): 10.242.69.107

客户:

Windows 7 with one NIC
OpenVPN IP Address: 192.168.0.2
ISP allocated IP Address: 10.0.8.2 (gateway 10.0.8.1)

服务器 OpenVPN 配置:

dev tun
ifconfig 192.168.0.1 192.168.0.2
secret static.key
push "redirect-gateway def1"

客户端 OpenVPN 配置:

remote xxx.xxx.com
dev tun
ifconfig 192.168.0.2 192.168.0.1
secret static.key

我不是添加路由等方面的专家。如果有人能告诉我如何在我的服务器/客户端路由表中添加此条目,我将不胜感激。

编辑:

客户端 netstat -rnv 的输出

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0         10.0.8.1         10.0.8.2     20
         10.0.8.0  255.255.255.252         On-link          10.0.8.2    276
         10.0.8.2  255.255.255.255         On-link          10.0.8.2    276
         10.0.8.3  255.255.255.255         On-link          10.0.8.2    276
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    306
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    306
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    306
      192.168.0.0  255.255.255.252         On-link       192.168.0.2    286
      192.168.0.2  255.255.255.255         On-link       192.168.0.2    286
      192.168.0.3  255.255.255.255         On-link       192.168.0.2    286
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    306
        224.0.0.0        240.0.0.0         On-link          10.0.8.2    276
        224.0.0.0        240.0.0.0         On-link       192.168.0.2    286
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    306
  255.255.255.255  255.255.255.255         On-link          10.0.8.2    276
  255.255.255.255  255.255.255.255         On-link       192.168.0.2    286
===========================================================================

编辑:

手动表更新

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0      192.168.0.1         10.0.8.2     21
      192.168.0.1  255.255.255.255         On-link          10.0.8.2     21
  204.236.211.109  255.255.255.255         10.0.8.1         10.0.8.2     21
===========================================================================

客户端 OpenVPN 日志:

Sat Nov 12 10:34:42 2011 us=740000 Notified TAP-Win32 driver to set a DHCP IP/netmask of 192.168.0.2/255.255.255.252 on interface {C79F7583-EF9F-4E4F-86A7-16DC58BAC404} [DHCP-serv: 192.168.0.1, lease-time: 31536000]
Sat Nov 12 10:34:42 2011 us=740000 Successful ARP Flush on interface [18] {C79F7583-EF9F-4E4F-86A7-16DC58BAC404}
Sat Nov 12 10:34:42 2011 us=771000 Data Channel MTU parms [ L:1544 D:1450 EF:44 EB:4 ET:0 EL:0 ]
Sat Nov 12 10:34:42 2011 us=771000 Local Options String: 'V4,dev-type tun,link-mtu 1544,tun-mtu 1500,proto UDPv4,ifconfig 192.168.0.1 192.168.0.2,cipher BF-CBC,auth SHA1,keysize 128,secret'
Sat Nov 12 10:34:42 2011 us=771000 Expected Remote Options String: 'V4,dev-type tun,link-mtu 1544,tun-mtu 1500,proto UDPv4,ifconfig 192.168.0.2 192.168.0.1,cipher BF-CBC,auth SHA1,keysize 128,secret'
Sat Nov 12 10:34:42 2011 us=771000 Local Options hash (VER=V4): '9960c5ae'
Sat Nov 12 10:34:42 2011 us=771000 Expected Remote Options hash (VER=V4): '9978ceb9'
Sat Nov 12 10:34:42 2011 us=771000 UDPv4 link local (bound): [undef]:1194
Sat Nov 12 10:34:42 2011 us=771000 UDPv4 link remote: 204.236.211.109:1194
Sat Nov 12 10:34:52 2011 us=615000 Peer Connection Initiated with 204.236.211.109:1194
Sat Nov 12 10:34:59 2011 us=42000 TEST ROUTES: 0/0 succeeded len=-1 ret=1 a=0 u/d=up
Sat Nov 12 10:34:59 2011 us=42000 Initialization Sequence Completed

答案1

我在 Windows 7 上遇到了同样的问题。以管理员身份启动 VPN 客户端后,它就可以正常工作了。似乎没有管理员权限就无法添加路由。

答案2

问题是默认路由是 via 10.0.8.1,而不是 via 192.168.0.2。这意味着redirect-gateway被忽略了。

redirect-gateway def1应添加0.0.0.0/1128.0.0.0/1通过路线192.168.0.2

尝试增加客户端的详细程度,找出未添加0/1128/1路由的原因。或者,您也可以不添加,然后进行测试def1,您应该会看到默认路由被替换。

相关内容