OpenVPN 在无线网络上无法使用

OpenVPN 在无线网络上无法使用

在某些连接上,我使用 OpenVPN 访问互联网和家里的内部网络时遇到问题。我可以在家里做到这一点,但当我去公共 wifi 场所时,我无法访问我的本地网络,甚至无法浏览网页。VPN 在我的内部网络上完美地连接到我家里的服务器。

会不会是 WiFi 网络覆盖了服务器推送的 DHCP 和 OpenVPN 呢?

我正在运行服务器和客户端 2.2

配置:

##############################################
# 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
proto udp

# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote 72.4.49.4 1194
;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

# 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>
-----BEGIN CERTIFICATE-----
IIDcTCCAlmgAwIBAgIJAIZRqgdnPrXvMA0GCSqGSIb3DQEBCwUAMCoxKDAmBgNV
AMTH2ludGVybmFsLnNvbGlkc2hlbGxzZWN1cml0eS5jb20wHhcNMTQwMTI4MjA1
TI1WhcNMjQwMTI2MjA1OTI1WjAqMSgwJgYDVQQDEx9pbnRlcm5hbC5zb2xpZHNo
Wxsc2VjdXJpdHkuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
qqzyHE72PtHsubKQBe/D8amuW/7m9tGvzQtzCmlmA5FspfBbibAG2ZizF35UrPL
e6enR0lTcj2xRXAbw5Ku7lffSsj1k2j+GucxVY7S6XEcHHLaNj5yXzyPa10aQHL
V1mOnFdac0y4ap23oZsmlDpgkGwSq39OxGQamqzMAxkKQ8NadXE2yKaAurGQd6Q
op/AjvhNfUbVHdKIESZHvtiIFlOOlqTvWulWMb6LzSdBaHRoHsRljl5h9hhpsKv
JqH7cDHaY7djvOtaDlwn5Uj/BDbXp243Mjw3FUsT3NMhodNJFJ+TfZC7Q54XHaI
45J5yl5amx9P5OUGsf0iQIDAQABo4GZMIGWMB0GA1UdDgQWBBQu7oClMkROaA2D
Atl+gnBWMV2WjBaBgNVHSMEUzBRgBQu7oClMkROaA2DTAtl+gnBWMV2WqEupCww
jEoMCYGA1UEAxMfaW50ZXJuYWwuc29saWRzaGVsbHNlY3VyaXR5LmNvbYIJAIZR
gdnPrXvMAwGA1UdEwQFMAMBAf8wCwYDVR0PBAQDAgEGMA0GCSqGSIb3DQEBCwUA
4IBAQCLkr5LPRdG4K2Y24MLQwgoiCIKKzgx9OF7e+PH/rAkci1ss4Uj4DaBzSRA
50XIXEb7Ut5j19H6qBYVwmkM4PGanTYNxTZ+4bZwLXFdgeVrVBpCUSHEa3cyMbv
FuOGAuzpzpu5spm5BMFMscalgTC/8VIhJLbCLhmT7R6VmWfOnKDWQS4eL9EyUqO
9zdjfU3vpx9Fut+dn4MqkmudIDd35b+v543U2nOkdH1l+1iXvxp1aERm2wn8ZCk
bgC2YyrFGFH68pKvuIa82//YXarOfRT3mXKRkg9AGZ0cHJrgI2laBlyxY7I9Ydf
sIfCdK99NpppyaB7yFhWsL5nAa6
-----END CERTIFICATE-----
</ca>

# Verify server certificate by checking
# that the certicate has the nsCertType
# field set to "server".  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 nsCertType
# field set to "server".  The build-key-server
# script in the easy-rsa folder will do this.
#ns-cert-type server

# If a tls-auth key is used on the server
# then every client must also have the key.
auth-user-pass
key-direction 1
<tls-auth>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
1fd6645f91c3a7f70549e8754e8bb5b
411361047787956cf76979f4572821c
551f04d42505f0a7434437c16d43972
fd074f2d2044fbca84e274edbcbe446
d09397b40cd025863e6bd7857b8658e
c60d14fe4212a7fd51d87ae847b3ff1
be2ab5d46cd46b721247b7579a2456c
d7ed5c0f17b96e024449b15892ccfdd
6b54b124471ef526becd464c6c5169c
a6667f7a4e988ae2a17569b46292709
42ead7a7824cdd12c88f3e9ddd032bd
169325478212090bb3243ff8f43e3c5
b886d265f618db002d7c599d270453a
bb09a4ec7f962dee0e541c7d4f0edcd
77d944ebd164748a3aff3ad02f1dec8
32ad9c0cd09b1a33ac1be790ae562e3
-----END OpenVPN Static key V1-----
</tls-auth>

# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
cipher AES-256-CBC

# 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

在公共网络

连接到 VPN 时的我的路线:

192.168.5.x = local network at startbucks
192.168.2.x = my home local network
10.162.129.x = Open
72.4.49.4 = home ip

===========================================================================
Interface List
 25...00 ff 0c 42 83 bf ......TAP-Win32 Adapter V9
  4...18 3d a2 1a 1e 78 ......Intel(R) Centrino(R) Advanced-N 6200 AGN
  3...b4 99 ba e2 86 52 ......Intel(R) 82577LM Gigabit Network Connection
  1...........................Software Loopback Interface 1
  6...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface
  9...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #4
 12...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #5
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0      192.168.5.1     192.168.5.78     25
          0.0.0.0        128.0.0.0     10.162.129.5     10.162.129.6     30
     10.162.129.1  255.255.255.255     10.162.129.5     10.162.129.6     30
     10.162.129.4  255.255.255.252         On-link      10.162.129.6    286
     10.162.129.6  255.255.255.255         On-link      10.162.129.6    286
     10.162.129.7  255.255.255.255         On-link      10.162.129.6    286
        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
        128.0.0.0        128.0.0.0     10.162.129.5     10.162.129.6     30
     72.4.49.4  255.255.255.255      192.168.5.1     192.168.5.78     25
      192.168.2.0    255.255.255.0     10.162.129.5     10.162.129.6     30
      192.168.5.0    255.255.255.0         On-link      192.168.5.78    281
     192.168.5.78  255.255.255.255         On-link      192.168.5.78    281
    192.168.5.255  255.255.255.255         On-link      192.168.5.78    281
        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      192.168.5.78    281
        224.0.0.0        240.0.0.0         On-link      10.162.129.6    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      192.168.5.78    281
  255.255.255.255  255.255.255.255         On-link      10.162.129.6    286
===========================================================================
Persistent Routes:
  None

IPv6 Route Table
===========================================================================
Active Routes:
 If Metric Network Destination      Gateway
  1    306 ::1/128                  On-link
  4    281 fe80::/64                On-link
 25    286 fe80::/64                On-link
  4    281 fe80::8c74:c5fb:4207:9f1f/128
                                    On-link
 25    286 fe80::98c9:2d2c:5e88:a0b6/128
                                    On-link
  1    306 ff00::/8                 On-link
  4    281 ff00::/8                 On-link
 25    286 ff00::/8                 On-link
===========================================================================
Persistent Routes:
  None

ipconfig /全部

Windows IP Configuration

   Host Name . . . . . . . . . . . . : StarBucks
   Primary Dns Suffix  . . . . . . . : 
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : sbx08514.tampafl.wayport.net

Ethernet adapter Local Area Connection 2:

   Connection-specific DNS Suffix  . : 
   Description . . . . . . . . . . . : TAP-Win32 Adapter V9
   Physical Address. . . . . . . . . : 00-FF-0C-42-83-BF
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::98c9:2d2c:5e88:a0b6%25(Preferred) 
   IPv4 Address. . . . . . . . . . . : 10.162.129.6(Preferred) 
   Subnet Mask . . . . . . . . . . . : 255.255.255.252
   Lease Obtained. . . . . . . . . . : Friday, January 31, 2014 8:46:59 AM
   Lease Expires . . . . . . . . . . : Saturday, January 31, 2015 8:46:59 AM
   Default Gateway . . . . . . . . . : 
   DHCP Server . . . . . . . . . . . : 10.162.129.5
   DHCPv6 IAID . . . . . . . . . . . : 419495692
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1A-41-7E-04-B4-99-BA-E2-86-52
   DNS Servers . . . . . . . . . . . : 192.168.2.10
                                       8.8.8.8
                                       8.8.4.4
   Primary WINS Server . . . . . . . : 192.168.2.10
   NetBIOS over Tcpip. . . . . . . . : Enabled

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : sbx08514.tampafl.wayport.net
   Description . . . . . . . . . . . : Intel(R) Centrino(R) Advanced-N 6200 AGN
   Physical Address. . . . . . . . . : 18-3D-A2-1A-1E-78
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::8c74:c5fb:4207:9f1f%4(Preferred) 
   IPv4 Address. . . . . . . . . . . : 192.168.5.78(Preferred) 
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Friday, January 31, 2014 7:59:12 AM
   Lease Expires . . . . . . . . . . : Friday, January 31, 2014 9:29:12 AM
   Default Gateway . . . . . . . . . : 192.168.5.1
   DHCP Server . . . . . . . . . . . : 192.168.5.1
   DHCPv6 IAID . . . . . . . . . . . : 68697506
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1A-41-7E-04-B4-99-BA-E2-86-52
   DNS Servers . . . . . . . . . . . : 192.168.5.1
   Primary WINS Server . . . . . . . : 192.168.5.1
   NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter Ethernet:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : busines.network
   Description . . . . . . . . . . . : Intel(R) 82577LM Gigabit Network Connection
   Physical Address. . . . . . . . . : B4-99-BA-E2-86-52
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Tunnel adapter Teredo Tunneling Pseudo-Interface:

   Connection-specific DNS Suffix  . : 
   Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   IPv6 Address. . . . . . . . . . . : 2001:0:9d38:6abd:8e:336c:bf79:2674(Preferred) 
   Link-local IPv6 Address . . . . . : fe80::8e:336c:bf79:2674%6(Preferred) 
   Default Gateway . . . . . . . . . : ::
   DHCPv6 IAID . . . . . . . . . . . : 234881024
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1A-41-7E-04-B4-99-BA-E2-86-52
   NetBIOS over Tcpip. . . . . . . . : Disabled

Tunnel adapter isatap.sbx08514.tampafl.wayport.net:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : sbx08514.tampafl.wayport.net
   Description . . . . . . . . . . . : Microsoft ISATAP Adapter #4
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.{0C4283BF-8997-4AD9-BA99-944BEB2C0BCA}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : 
   Description . . . . . . . . . . . : Microsoft ISATAP Adapter #5
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes

OpenVPN 服务器配置:

#################################################
# Sample OpenVPN 2.0 config file for            #
# multi-client server.                          #
#                                               #
# This file is for the server side              #
# of a many-clients <-> one-server              #
# OpenVPN configuration.                        #
#                                               #
# OpenVPN also supports                         #
# single-machine <-> single-machine             #
# configurations (See the Examples page         #
# on the web site for more info).               #
#                                               #
# This config should work on Windows            #
# or Linux/BSD systems.  Remember on            #
# Windows to quote pathnames and use            #
# double backslashes, e.g.:                     #
# "C:\\Program Files\\OpenVPN\\config\\foo.key" #
#                                               #
# Comments are preceded with '#' or ';'         #
#################################################

# Which local IP address should OpenVPN
# listen on? (optional)
;local a.b.c.d

# Which TCP/UDP port should OpenVPN listen on?
# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one.  You will need to
# open up this port on your firewall.
port 1194

# TCP or UDP server?
;proto tcp
proto udp

# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
# Use "dev tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# If you want to control access policies
# over the VPN, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use "dev-node" for this.
# 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 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don't need this.
;dev-node MyTap

# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key).  Each client
# and the server must have their own cert and
# key file.  The server and all clients will
# use the same ca file.
#
# See the "easy-rsa" directory for a series
# of scripts for generating RSA certificates
# and private keys.  Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
ca /etc/openvpn/internal.home.network/keys/ca.crt
cert /etc/openvpn/internal.home.network/keys/issued/internal.home.network.crt
key /etc/openvpn/internal.home.network/keys/private/internal.home.network.key

# Diffie hellman parameters.
# Generate your own with:
#   openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh /etc/openvpn/internal.home.network/keys/dh.pem


username-as-common-name
plugin /usr/lib/openvpn/openvpn-auth-pam.so /etc/pam.d/login
client-cert-not-required

# Configure server mode and supply a VPN subnet
# for OpenVPN to draw client addresses from.
# The server will take 10.8.0.1 for itself,
# the rest will be made available to clients.
# Each client will be able to reach the server
# on 10.8.0.1. Comment this line out if you are
# ethernet bridging. See the man page for more info.
server 10.162.129.0 255.255.255.0

# Maintain a record of client <-> virtual IP address
# associations in this file.  If OpenVPN goes down or
# is restarted, reconnecting clients can be assigned
# the same virtual IP address from the pool that was
# previously assigned.
ifconfig-pool-persist /var/lib/openvpn/internal.home.network-ipp.txt

# Configure server mode for ethernet bridging.
# You must first use your OS's bridging capability
# to bridge the TAP interface with the ethernet
# NIC interface.  Then you must manually set the
# IP/netmask on the bridge interface, here we
# assume 10.8.0.4/255.255.255.0.  Finally we
# must set aside an IP range in this subnet
# (start=10.8.0.50 end=10.8.0.100) to allocate
# to connecting clients.  Leave this line commented
# out unless you are ethernet bridging.
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100

# Configure server mode for ethernet bridging
# using a DHCP-proxy, where clients talk
# to the OpenVPN server-side DHCP server
# to receive their IP address allocation
# and DNS server addresses.  You must first use
# your OS's bridging capability to bridge the TAP
# interface with the ethernet NIC interface.
# Note: this mode only works on clients (such as
# Windows), where the client-side TAP adapter is
# bound to a DHCP client.
;server-bridge

# Push routes to the client to allow it
# to reach other private subnets behind
# the server.  Remember that these
# private subnets will also need
# to know to route the OpenVPN client
# address pool (10.8.0.0/255.255.255.0)
# back to the OpenVPN server.
;push "route 192.168.10.0 255.255.255.0"
;push "route 192.168.20.0 255.255.255.0"

# To assign specific IP addresses to specific
# clients or if a connecting client has a private
# subnet behind it that should also have VPN access,
# use the subdirectory "ccd" for client-specific
# configuration files (see man page for more info).

# EXAMPLE: Suppose the client
# having the certificate common name "Thelonious"
# also has a small subnet behind his connecting
# machine, such as 192.168.40.128/255.255.255.248.
# First, uncomment out these lines:
;client-config-dir ccd
;route 192.168.40.128 255.255.255.248
# Then create a file ccd/Thelonious with this line:
#   iroute 192.168.40.128 255.255.255.248
# This will allow Thelonious' private subnet to
# access the VPN.  This example will only work
# if you are routing, not bridging, i.e. you are
# using "dev tun" and "server" directives.

# EXAMPLE: Suppose you want to give
# Thelonious a fixed VPN IP address of 10.9.0.1.
# First uncomment out these lines:
;client-config-dir ccd
;route 10.9.0.0 255.255.255.252
# Then add this line to ccd/Thelonious:
#   ifconfig-push 10.9.0.1 10.9.0.2

# Suppose that you want to enable different
# firewall access policies for different groups
# of clients.  There are two methods:
# (1) Run multiple OpenVPN daemons, one for each
#     group, and firewall the TUN/TAP interface
#     for each group/daemon appropriately.
# (2) (Advanced) Create a script to dynamically
#     modify the firewall in response to access
#     from different clients.  See man
#     page for more info on learn-address script.
;learn-address ./script

# If enabled, this directive will configure
# all clients to redirect their default
# network gateway through the VPN, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the VPN
# (The OpenVPN server machine may need to NAT
# or bridge the TUN/TAP interface to the internet
# in order for this to work properly).
push "redirect-gateway def1 bypass-dhcp"

# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses.  CAVEAT:
# http://openvpn.net/faq.html#dhcpcaveats
# The addresses below refer to the public
# DNS servers provided by opendns.com.
;push "dhcp-option DNS 208.67.222.222"
;push "dhcp-option DNS 208.67.220.220"

# Uncomment this directive to allow different
# clients to be able to "see" each other.
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server's TUN/TAP interface.
;client-to-client

# Uncomment this directive if multiple clients
# might connect with the same certificate/key
# files or common names.  This is recommended
# only for testing purposes.  For production use,
# each client should have its own certificate/key
# pair.
#
# IF YOU HAVE NOT GENERATED INDIVIDUAL
# CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
# EACH HAVING ITS OWN UNIQUE "COMMON NAME",
# UNCOMMENT THIS LINE OUT.
;duplicate-cn

# The keepalive directive causes ping-like
# messages to be sent back and forth over
# the link so that each side knows when
# the other side has gone down.
# Ping every 10 seconds, assume that remote
# peer is down if no ping received during
# a 120 second time period.
keepalive 10 120

# For extra security beyond that provided
# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
#   openvpn --genkey --secret ta.key
#
# The server and each client must have
# a copy of this key.
# The second parameter should be '0'
# on the server and '1' on the clients.
tls-auth /etc/openvpn/internal.home.network/keys/ta.key 0

# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
;cipher BF-CBC        # Blowfish (default)
;cipher AES-128-CBC   # AES
;cipher DES-EDE3-CBC  # Triple-DES

# Enable compression on the VPN link.
# If you enable it here, you must also
# enable it in the client config file.
comp-lzo

# The maximum number of concurrently connected
# clients we want to allow.
;max-clients 100

# It's a good idea to reduce the OpenVPN
# daemon's privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
user nobody
group nogroup

# The persist options will try to avoid
# accessing certain resources on restart
# that may no longer be accessible because
# of the privilege downgrade.
persist-key
persist-tun

# Output a short status file showing
# current connections, truncated
# and rewritten every minute.
status /var/log/openvpn/internal.home.network-status.log

# By default, log messages will go to the syslog (or
# on Windows, if running as a service, they will go to
# the "\Program Files\OpenVPN\log" directory).
# Use log or log-append to override this default.
# "log" will truncate the log file on OpenVPN startup,
# while "log-append" will append to it.  Use one
# or the other (but not both).
;log         openvpn.log
log-append /var/log/openvpn/internal.home.network.log

# Set the appropriate level of log
# file verbosity.
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 3

# Silence repeating messages.  At most 20
# sequential messages of the same message
# category will be output to the log.
;mute 20
# Use a secure cryptographic cipher.
cipher AES-256-CBC

# Revoked certificate list
crl-verify /etc/openvpn/internal.home.network/keys/crl.pem

# Advanced clients configurations
client-config-dir /etc/openvpn/internal.home.network/configs
push "route 192.168.2.0 255.255.255.0"; Allow access to local network.
push "dhcp-option DNS 192.168.2.10"
push "dhcp-option WINS 192.168.2.10"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"

OpenVPN 服务器路由:

root@openvpn:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.2.254   0.0.0.0         UG    0      0        0 eth0
10.162.129.0    10.162.129.2    255.255.255.0   UG    0      0        0 tun0
10.162.129.2    0.0.0.0         255.255.255.255 UH    0      0        0 tun0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

我如何添加网关/路线以便我的网关/路线胜过星巴克的网关/路线?

答案1

您的 VPN 服务器有此选项push "redirect-gateway def1"。这意味着 openvpn 服务器没有推送“默认”网关,该网关通常被理解为由 定义的网络范围的路由0.0.0.0/0

使用该选项意味着您的 VPN 服务器将发送两个路由0.0.0.0/1、 和128.0.0.0/1(或者如果您喜欢扩展掩码,则为 0.0.0.0/128.0.0.0 和 128.0.0.0/128.0.0.0)。由于路由是从最具体到最不具体的顺序处理的,这意味着这两条路由应该优先于 的任何路由0.0.0.0/0

您还可以设置bypass-dhcp选项redirect-gateway。这将为客户端使用的 DHCP 服务器添加静态路由。

答案2

尝试添加此语句

 redirect-gateway def1

到您的客户端配置文件。

相关内容