如何通过VPN openvpn 仅路由私有网络?

如何通过VPN openvpn 仅路由私有网络?

我使用 pivpn 访问具有特定服务的专用网络。此网络有一个 DNS 和许多规则,不允许访问一些简单的网站,例如 youtube 或 google。由于 pivpn 默认处于完全隧道状态,因此我的所有流量都通过我的 vpn 网络,我无法执行诸如观看 youtube 视频或进行一些 google 搜索之类的操作。我想仅通过 vpn 路由我的 vpn 连接,并让所有其他操作通过客户端网络。我如何启用这种拆分隧道?

这是我的/etc/openvpn/server.conf

dev tun
proto tcp
port X
ca /etc/openvpn/easy-rsa/pki/ca.crt
cert /etc/openvpn/easy-rsa/pki/issued/VPN_28154d4a-2d8f-42b8-b083-a16948349746.crt
key /etc/openvpn/easy-rsa/pki/private/VPN_28154d4a-2d8f-42b8-b083-a16948349746.key
dh none
ecdh-curve secp521r1
topology subnet
server X.X.X.X 255.255.255.0
# Set your primary domain name server address for clients
push "dhcp-option xxxx.com"
push "dhcp-option DNS X.X.X.X"
push "block-outside-dns"
# Override the Client default gateway by using 0.0.0.0/1 and
# 128.0.0.0/1 rather than 0.0.0.0/0. This has the benefit of
# overriding but not wiping out the original default gateway.
push "redirect-gateway def1"
client-to-client
client-config-dir /etc/openvpn/ccd
keepalive 15 120
remote-cert-tls client
tls-version-min 1.2
 tls-crypt /etc/openvpn/easy-rsa/pki/ta.key
cipher AES-256-CBC
auth SHA256
user openvpn
group openvpn
persist-key
persist-tun
crl-verify /etc/openvpn/crl.pem
status /var/log/openvpn-status.log 20
status-version 3
syslog
verb 3
#DuplicateCNs allow access control on a less-granular, per user basis.
#Remove # if you will manage access by user instead of device.
#duplicate-cn
# Generated for use by PiVPN.io

你知道我怎样才能实现这个目标吗?

答案1

由于您的配置要求这:

# Override the Client default gateway by using 0.0.0.0/1 and
# 128.0.0.0/1 rather than 0.0.0.0/0. This has the benefit of
# overriding but not wiping out the original default gateway.
push "redirect-gateway def1"

删除“ redirect-gateway”选项,OpenVPN 将恢复默认行为,即仅路由 VPN 自己的网络(即 XXXX/255.255.255.0 网络)。如果单个客户端配置有此选项,请确保也将其从那里删除。

route进行该更改后,您可以通过添加选项(例如从服务器推送到所有客户端)通过 VPN 路由特定的附加网络:

push "route 192.168.7.0 255.255.255.0 vpn_gateway"
push "route 192.168.11.0 255.255.255.0 vpn_gateway"

相关内容