我的主要目标是,如果您连接到 VPN,那么一台特定的 Windows 10 机器可以从任何地方访问。该机器在办公室使用超高速连接,下载速度可达几百兆,但当完全连接到 VPN(使用默认的 OpenVPN 配置redirect-gateway def1 bypass-dhcp
)时,下载速度会降至 20 兆。
在 VPN 上,VPN 服务器是 10.8.0.1,这台机器是 10.8.0.2,10.8.0.x 上还有大约 5 个其他 VPN 客户端。我希望 VPN 能够提供 10.8.0.x 机器具有常规的非 VPN 连接,并且可以相互通信。
所有连接都很好,直到我尝试删除redirect-gateway ...
。无论我尝试什么配置,如果没有那行,当连接到 VPN 时,我就无法连接互联网,并且到处都会出现 DNS 超时。
我认为主要选项是仅通过路由 VPN 流量,route 10.8.0.0 255.255.255.0
虽然这确实允许机器访问 VPN 上的其他机器,但我仍然失去互联网连接。
我是不是理解错了?我希望所有客户端只通过 VPN 路由 VPN 流量,其他所有流量都通过常规路由。我认为这可以通过删除重定向网关并添加静态路由来实现。
tracert -d 8.8.8.8
VPN 已连接但未连接redirect-gateway
(即没有互联网连接/DNS 问题)时的输出:
Tracing route to 8.8.8.8 over a maximum of 30 hops
1 <1 ms <1 ms <1 ms 10.247.28.1
2 1 ms 1 ms 1 ms 80.169.236.161
3 <1 ms <1 ms <1 ms 80.169.58.193
4 1 ms 1 ms 1 ms 212.74.69.151
5 12 ms 12 ms 12 ms 185.6.36.57
6 12 ms 12 ms 12 ms 216.239.43.3
7 11 ms 11 ms 11 ms 8.8.8.8
Trace complete.
无需VPN:
ipconfig /all
Ethernet adapter Ethernet:
Description . . . . . . . . . . . : Intel(R) I211 Gigabit Network Connection
Physical Address. . . . . . . . . : 2C-FD-A1-xxxx
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 10.247.29.176(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.254.0
Lease Obtained. . . . . . . . . . : Tuesday, June 26, 2018 5:55:10 PM
Lease Expires . . . . . . . . . . : Tuesday, July 3, 2018 8:00:57 PM
Default Gateway . . . . . . . . . : 10.247.28.1
DHCP Server . . . . . . . . . . . : 10.247.28.1
DNS Servers . . . . . . . . . . . : 8.8.8.8
8.8.4.4
NetBIOS over Tcpip. . . . . . . . : Enabled
route print -4
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.247.28.1 10.247.29.176 25
10.247.28.0 255.255.254.0 On-link 10.247.29.176 281
10.247.29.176 255.255.255.255 On-link 10.247.29.176 281
10.247.29.255 255.255.255.255 On-link 10.247.29.176 281
127.0.0.0 255.0.0.0 On-link 127.0.0.1 331
127.0.0.1 255.255.255.255 On-link 127.0.0.1 331
127.255.255.255 255.255.255.255 On-link 127.0.0.1 331
224.0.0.0 240.0.0.0 On-link 127.0.0.1 331
224.0.0.0 240.0.0.0 On-link 10.247.29.176 281
255.255.255.255 255.255.255.255 On-link 127.0.0.1 331
255.255.255.255 255.255.255.255 On-link 10.247.29.176 281
===========================================================================
Persistent Routes:
None
使用 VPN(无重定向网关/损坏/无连接):
ipconfig /all
Ethernet adapter VPN:
Description . . . . . . . . . . . : TAP-Windows Adapter V9
Physical Address. . . . . . . . . : 00-FF-73-xxxx
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::1d1a:6e1c:e80e:3dcf%3(Preferred)
IPv4 Address. . . . . . . . . . . : 10.8.0.2(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : Tuesday, July 3, 2018 10:42:37 AM
Lease Expires . . . . . . . . . . : Wednesday, July 3, 2019 10:42:36 AM
Default Gateway . . . . . . . . . :
DHCP Server . . . . . . . . . . . : 10.8.0.254
DHCPv6 IAID . . . . . . . . . . . : 5039xxxx
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-xxxx
DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
NetBIOS over Tcpip. . . . . . . . : Enabled
Ethernet adapter Ethernet:
Description . . . . . . . . . . . : Intel(R) I211 Gigabit Network Connection
Physical Address. . . . . . . . . : 2C-FD-A1-xxxx
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 10.247.29.176(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.254.0
Lease Obtained. . . . . . . . . . : Tuesday, June 26, 2018 5:55:10 PM
Lease Expires . . . . . . . . . . : Tuesday, July 3, 2018 8:00:56 PM
Default Gateway . . . . . . . . . : 10.247.28.1
DHCP Server . . . . . . . . . . . : 10.247.28.1
DNS Servers . . . . . . . . . . . : 8.8.8.8
8.8.4.4
NetBIOS over Tcpip. . . . . . . . : Enabled
route print -4
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.247.28.1 10.247.29.176 25
10.8.0.0 255.255.255.0 On-link 10.8.0.2 259
10.8.0.2 255.255.255.255 On-link 10.8.0.2 259
10.8.0.255 255.255.255.255 On-link 10.8.0.2 259
10.247.28.0 255.255.254.0 On-link 10.247.29.176 281
10.247.29.176 255.255.255.255 On-link 10.247.29.176 281
10.247.29.255 255.255.255.255 On-link 10.247.29.176 281
127.0.0.0 255.0.0.0 On-link 127.0.0.1 331
127.0.0.1 255.255.255.255 On-link 127.0.0.1 331
127.255.255.255 255.255.255.255 On-link 127.0.0.1 331
224.0.0.0 240.0.0.0 On-link 127.0.0.1 331
224.0.0.0 240.0.0.0 On-link 10.247.29.176 281
224.0.0.0 240.0.0.0 On-link 10.8.0.2 259
255.255.255.255 255.255.255.255 On-link 127.0.0.1 331
255.255.255.255 255.255.255.255 On-link 10.247.29.176 281
255.255.255.255 255.255.255.255 On-link 10.8.0.2 259
===========================================================================
Persistent Routes:
None
为了完整起见,使用 VPN 和重定向网关,
ipconfig /all
Ethernet adapter VPN:
Description . . . . . . . . . . . : TAP-Windows Adapter V9
Physical Address. . . . . . . . . : 00-FF-73-xxxx
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::1d1a:6e1c:e80e:3dcf%3(Preferred)
IPv4 Address. . . . . . . . . . . : 10.8.0.2(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : Thursday, June 28, 2018 5:50:04 PM
Lease Expires . . . . . . . . . . : Friday, June 28, 2019 5:50:02 PM
Default Gateway . . . . . . . . . :
DHCP Server . . . . . . . . . . . : 10.8.0.254
DHCPv6 IAID . . . . . . . . . . . : 5039xxxx
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-22-xxxx
DNS Servers . . . . . . . . . . . : 8.8.8.8
8.8.4.4
NetBIOS over Tcpip. . . . . . . . : Enabled
Ethernet adapter Ethernet:
Description . . . . . . . . . . . : Intel(R) I211 Gigabit Network Connection
Physical Address. . . . . . . . . : 2C-FD-A1-xxxx
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 10.247.29.176(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.254.0
Lease Obtained. . . . . . . . . . : Tuesday, June 26, 2018 5:55:10 PM
Lease Expires . . . . . . . . . . : Friday, June 29, 2018 9:01:01 PM
Default Gateway . . . . . . . . . : 10.247.28.1
DHCP Server . . . . . . . . . . . : 10.247.28.1
DNS Servers . . . . . . . . . . . : 8.8.8.8
8.8.4.4
NetBIOS over Tcpip. . . . . . . . : Enabled
route print -4
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.247.28.1 10.247.29.176 25
0.0.0.0 128.0.0.0 10.8.0.1 10.8.0.2 35
10.8.0.0 255.255.255.0 On-link 10.8.0.2 291
10.8.0.2 255.255.255.255 On-link 10.8.0.2 291
10.8.0.255 255.255.255.255 On-link 10.8.0.2 291
10.247.28.0 255.255.254.0 On-link 10.247.29.176 281
10.247.29.176 255.255.255.255 On-link 10.247.29.176 281
10.247.29.255 255.255.255.255 On-link 10.247.29.176 281
52.49.219.24 255.255.255.255 10.247.28.1 10.247.29.176 25
127.0.0.0 255.0.0.0 On-link 127.0.0.1 331
127.0.0.1 255.255.255.255 On-link 127.0.0.1 331
127.255.255.255 255.255.255.255 On-link 127.0.0.1 331
128.0.0.0 128.0.0.0 10.8.0.1 10.8.0.2 35
224.0.0.0 240.0.0.0 On-link 127.0.0.1 331
224.0.0.0 240.0.0.0 On-link 10.8.0.2 291
224.0.0.0 240.0.0.0 On-link 10.247.29.176 281
255.255.255.255 255.255.255.255 On-link 127.0.0.1 331
255.255.255.255 255.255.255.255 On-link 10.8.0.2 291
255.255.255.255 255.255.255.255 On-link 10.247.29.176 281
===========================================================================
Persistent Routes:
None
答案1
删除指令时,请务必验证以下事项redirect-gateway
:
- 检查您的 IP 配置。您是从 openvpn 服务器(程序)获取的吗?还是通过网络后面的真实 DHCP 服务器获取的 DHCP,还是通过本地 openvpn 配置文件静态获取的,还是通过接口配置静态获取的?
- 确保不要从上述任何 vpn 接口配置中获取默认网关 ip 地址。Windows 有时会出现奇怪的行为,将网关地址切换到隧道接口,然后由于接口更改而失去与服务器的连接。
- 如果不需要,请确保不要为隧道接口获取 DNS 服务器。
最简单的选择(至少对于测试而言,但不是很动态)是在 Windows 10 客户端上静态配置接口。仅配置 ip 地址和子网掩码。尝试在route PRINT -4
连接时使用 cmd/powershell 分析默认网关,此时互联网连接停止工作。
答案2
我的一个朋友已经设置了很多这样的功能,他建议我这样做,
> tracert -d 8.8.8.8
Tracing route to 8.8.8.8 over a maximum of 30 hops
1 <1 ms <1 ms <1 ms 10.247.28.1
2 1 ms 1 ms 1 ms 80.169.236.161
3 <1 ms <1 ms <1 ms 80.169.58.193
4 1 ms 1 ms 1 ms 212.74.69.151
5 12 ms 12 ms 12 ms 185.6.36.57
6 12 ms 12 ms 12 ms 216.239.43.3
7 11 ms 11 ms 11 ms 8.8.8.8
Trace complete.
然后,
> tracert -d 10.8.0.1
Tracing route to 10.8.0.1 over a maximum of 30 hops
1 13 ms 13 ms 13 ms 10.8.0.1
Trace complete.
然后,在服务器上,
$ sudo netstat -tunpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 29471/memcached
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 22123/sshd
tcp6 0 0 :::22 :::* LISTEN 22123/sshd
udp 0 0 0.0.0.0:1194 0.0.0.0:* 17359/openvpn
udp 0 0 0.0.0.0:68 0.0.0.0:* 966/dhclient
当他看到这个时,他意识到服务器并让我安装 DNSMasq,
$ sudo apt install dnsmasq
然后netstat
在服务器上看起来像这样,
$ sudo netstat -tunpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 29471/memcached
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 22123/sshd
tcp6 0 0 :::22 :::* LISTEN 22123/sshd
udp 0 0 0.0.0.0:1194 0.0.0.0:* 17359/openvpn
udp 0 0 0.0.0.0:68 0.0.0.0:* 966/dhclient
但这仍然不起作用,所以我在 Windows 机器上重新尝试了以前尝试过但没有起作用的选项,dhcp-option DNS 10.8.0.1
回到它的 OpenVPN 选项......一切正常。
所以现在,它正如我所愿,我不仅拥有办公室网络的全部速度,而且还拥有完整的 vpn 连接。
感谢@felix-h 和@kevin-k 帮助我调试这个问题,现在我对它有了更好的理解,但就我的情况而言,这个问题并不完全是客户端的问题。