我需要连接到公司的 VPN 才能访问内部网站和 Web 应用程序,但连接到 VPN 时,除非通过特定的 socks5 代理,否则我无法访问常规内部网站。在 Mac 或 PC 上,我可以连接到 openVPN,然后使用 SwitchyOmega 连接到需要常规互联网访问的网站的 socks5 代理,但在 Android 或 iOS 上,我无法同时使用 openVPN 和 socks5。
我想知道我是否可以(以及如何)修改客户端配置文件,以便指定 openVPN 隧道后面的 socks5 代理来路由我的流量。请注意,我没有更改服务器端配置的权限。
##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server. #
# #
# This configuration can be used by multiple #
# clients, however each client should have #
# its own cert and key files. #
# #
# On Windows, you might want to rename this #
# file so it has a .ovpn extension #
##############################################
# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client
# Use the same setting as you are using on
# the server.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel
# if you have more than one. On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap
# Are we connecting to a TCP or
# UDP server? Use the same setting as
# on the server.
proto tcp
;roto udp
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote fake.com 7777
;remote my-server-2 1194
# Choose a random host from the remote
# list for load-balancing. Otherwise
# try hosts in the order specified.
;remote-random
# Keep trying indefinitely to resolve the
# host name of the OpenVPN server. Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite
# Most clients don't need to bind to
# a specific local port number.
nobind
# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nogroup
# Try to preserve some state across restarts.
persist-key
persist-tun
# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here. See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]
# Wireless networks often produce a lot
# of duplicate packets. Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings
# SSL/TLS parms.
# See the server config file for more
# description. It's best to use
# a separate .crt/.key file pair
# for each client. A single ca
# file can be used for all clients.
;ca ca.crt
;cert client.crt
;key client.key
# Verify server certificate by checking that the
# certicate has the correct key usage set.
# This is an important precaution to protect against
# a potential attack discussed here:
# http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the keyUsage set to
# digitalSignature, keyEncipherment
# and the extendedKeyUsage to
# serverAuth
# EasyRSA can do this for you.
remote-cert-tls server
# If a tls-auth key is used on the server
# then every client must also have the key.
;tls-auth ta.key 1
key-direction 1
reneg-sec 21600
# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
cipher AES-256-CBC
auth SHA256
# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
comp-lzo
# Set log file verbosity.
verb 3
# Silence repeating messages
;mute 20
# script-security 2
# up /etc/openvpn/update-resolv-conf
# down /etc/openvpn/update-resolv-conf
<ca>
-----BEGIN CERTIFICATE-----
xxx
-----END CERTIFICATE-----
</ca>
<tls-auth>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
xxx
-----END OpenVPN Static key V1-----
</tls-auth>
auth-user-pass
auth-nocache
以上是我客户端的.opvn文件的模拟版本。
答案1
您提供的配置不包含任何有关路由的信息。这意味着路由将从 OpenVPN 服务器推送。您需要查看成功连接的日志文件并检查推送了哪些路由。如果您只得到redirect-gateway def1
,则必须自己找出路由。基本上,您需要查看您连接的 IP 地址(例如1.2.3.4)并创建您自己的路由目标表:
- 1.2.3.4/24
- 4.3.2.1/24
- …
然后使用获得的信息修改客户端配置:
route 1.2.3.4 255.255.255.0
route 4.3.2.1 255.255.255.0
route …
pull-filter ignore "route"
这将使您的客户端忽略来自服务器的路由,同时设置您需要达到所需目标的明确规则。
可能会出现一个问题:如果您的任何公司网络与您的家庭网络位于同一子网,则这将无法轻松实现。在这种情况下,最好的选择是更改本地子网。
如果您只连接到非常特定的目标(没有冲突),您可以通过不使用网络掩码来规避此问题。然后它将默认为255.255.255.255。
如果您不想为这些烦恼,而且公司只使用内部 IP 范围,您也可以这样做:
route 10.0.0.0 255.0.0.0
route 172.16.0.0 255.224.0.0
route 192.168.0.0 255.255.0.0
pull-filter ignore "route"
这会起作用,因为您的家庭网络(希望)具有更长的前缀,从而由于更高的特异性而使其路由匹配。
请记住,如果公司有内部 DNS 服务器,您可能需要在某处设置一个内部 DNS 服务器。