我需要連接到我公司的 VPN 才能訪問內部網站和 Web 應用程序,而連接到 VPN 時我無法訪問常規內部,除非透過特定的ocks5代理。在 Mac 或 PC 上,我可以連接到 openVPN,然後使用 SwitchyOmega 連接到需要定期訪問互聯網的網站的ocks5代理,但在 Android 或 iOS 上,我無法同時使用 openVPN 和ocks5。
我想知道我是否可以(以及如何)修改客戶端設定文件,以便在 openVPN 隧道後面指定一個ocks5代理來路由我的流量。請注意,我沒有更改伺服器端配置的權限。
##############################################
# 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 伺服器(如果公司有的話)。