openVPN 连接,但大多数时候不起作用(RTNETLINK 回答:文件存在)

openVPN 连接,但大多数时候不起作用(RTNETLINK 回答:文件存在)

我最近创建了一个 openVPN 服务器,有时我可以连接(在 elementryOS 上使用 openVPN)并顺利访问互联网,但大多数时候我可以连接,但在尝试访问网站时会出现 DNS 错误。

我的朋友能够使用 tunnelblick 从 Mac 完美地连接。

当我启动它并且它不工作时我得到这个输出:

root@cclient:~# openvpn --config /home/user/vpn/client.ovpn 
Thu Aug 11 09:40:30 2016 OpenVPN 2.3.2 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [eurephia] [MH] [IPv6] built on Dec  1 2014
Thu Aug 11 09:40:30 2016 Control Channel Authentication: tls-auth using INLINE static key file
Thu Aug 11 09:40:30 2016 Outgoing Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
Thu Aug 11 09:40:30 2016 Incoming Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
Thu Aug 11 09:40:30 2016 Socket Buffers: R=[212992->131072] S=[212992->131072]
Thu Aug 11 09:40:30 2016 NOTE: UID/GID downgrade will be delayed because of --client, --pull, or --up-delay
Thu Aug 11 09:40:30 2016 UDPv4 link local: [undef]
Thu Aug 11 09:40:30 2016 UDPv4 link remote: [AF_INET]99.139.69.XX:1194
Thu Aug 11 09:40:30 2016 TLS: Initial packet from [AF_INET]99.139.69.94:1194, sid=dcc35439 e95aefe1
Thu Aug 11 09:40:30 2016 VERIFY OK: depth=1, C=US, ST=CA, L=SanFrancisco, O=Marvin, OU=MyOrganizationalUnit, CN=Marvin CA, name=server, [email protected]
Thu Aug 11 09:40:30 2016 Validating certificate key usage
Thu Aug 11 09:40:30 2016 ++ Certificate has key usage  00a0, expects 00a0
Thu Aug 11 09:40:30 2016 VERIFY KU OK
Thu Aug 11 09:40:30 2016 Validating certificate extended key usage
Thu Aug 11 09:40:30 2016 ++ Certificate has EKU (str) TLS Web Server Authentication, expects TLS Web Server Authentication
Thu Aug 11 09:40:30 2016 VERIFY EKU OK
Thu Aug 11 09:40:30 2016 VERIFY OK: depth=0, C=US, ST=CA, L=SanFrancisco, O=Marvin, OU=MyOrganizationalUnit, CN=server, name=server, [email protected]
Thu Aug 11 09:40:30 2016 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
Thu Aug 11 09:40:30 2016 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Thu Aug 11 09:40:30 2016 Data Channel Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
Thu Aug 11 09:40:30 2016 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Thu Aug 11 09:40:30 2016 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 2048 bit RSA
Thu Aug 11 09:40:30 2016 [server] Peer Connection Initiated with [AF_INET]99.139.69.94:1194
Thu Aug 11 09:40:32 2016 SENT CONTROL [server]: 'PUSH_REQUEST' (status=1)
Thu Aug 11 09:40:32 2016 PUSH: Received control message: 'PUSH_REPLY,redirect-gateway def1 bypass-dhcp,dhcp-option DNS 208.67.222.222,dhcp-option DNS 208.67.220.220,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.10 10.8.0.9'
Thu Aug 11 09:40:32 2016 OPTIONS IMPORT: timers and/or timeouts modified
Thu Aug 11 09:40:32 2016 OPTIONS IMPORT: --ifconfig/up options modified
Thu Aug 11 09:40:32 2016 OPTIONS IMPORT: route options modified
Thu Aug 11 09:40:32 2016 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
Thu Aug 11 09:40:32 2016 ROUTE_GATEWAY 10.245.243.254/255.255.252.0 IFACE=wlan0 HWADDR=b4:6d:83:25:c7:95
Thu Aug 11 09:40:32 2016 TUN/TAP device tun0 opened
Thu Aug 11 09:40:32 2016 TUN/TAP TX queue length set to 100
Thu Aug 11 09:40:32 2016 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
Thu Aug 11 09:40:32 2016 /sbin/ip link set dev tun0 up mtu 1500
Thu Aug 11 09:40:32 2016 /sbin/ip addr add dev tun0 local 10.8.0.10 peer 10.8.0.9
Thu Aug 11 09:40:32 2016 /sbin/ip route add 99.139.69.XX/32 via 10.245.XXX.254
RTNETLINK answers: File exists
Thu Aug 11 09:40:32 2016 ERROR: Linux route add command failed: external program exited with error status: 2
Thu Aug 11 09:40:32 2016 /sbin/ip route add 0.0.0.0/1 via 10.8.0.9
Thu Aug 11 09:40:32 2016 /sbin/ip route add 128.0.0.0/1 via 10.8.0.9
Thu Aug 11 09:40:32 2016 /sbin/ip route add 10.8.0.1/32 via 10.8.0.9
Thu Aug 11 09:40:32 2016 GID set to nogroup
Thu Aug 11 09:40:32 2016 UID set to nobody
Thu Aug 11 09:40:32 2016 Initialization Sequence Completed

然后当我按 ^CI 时

Thu Aug 11 09:44:57 2016 event_wait : Interrupted system call (code=4)
Thu Aug 11 09:44:57 2016 /sbin/ip route del 10.8.0.1/32
 RTNETLINK answers: Operation not permitted
 Thu Aug 11 09:44:57 2016 ERROR: Linux route delete command failed: external program exited with error status: 2
 Thu Aug 11 09:44:57 2016 /sbin/ip route del 99.139.69.94/32
 RTNETLINK answers: Operation not permitted
 Thu Aug 11 09:44:57 2016 ERROR: Linux route delete command failed: external program exited with error status: 2
 Thu Aug 11 09:44:57 2016 /sbin/ip route del 0.0.0.0/1
 RTNETLINK answers: Operation not permitted
 Thu Aug 11 09:44:57 2016 ERROR: Linux route delete command failed: external program exited with error status: 2
 Thu Aug 11 09:44:57 2016 /sbin/ip route del 128.0.0.0/1
 RTNETLINK answers: Operation not permitted
 Thu Aug 11 09:44:57 2016 ERROR: Linux route delete command failed: external program exited with error status: 2
 Thu Aug 11 09:44:57 2016 Closing TUN/TAP interface
 Thu Aug 11 09:44:57 2016 /sbin/ip addr del dev tun0 local 10.8.0.10 peer 10.8.0.9
 RTNETLINK answers: Operation not permitted
 Thu Aug 11 09:44:57 2016 Linux ip addr del failed: external program exited with error status: 2
 Thu Aug 11 09:44:57 2016 SIGINT[hard,] received, process exiting

这是我的客户端.ovpn

##############################################
# 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 99.139.69.XX 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

# 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
key-direction 1


# 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

# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
;cipher x

# 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
<ca>
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
</ca>
<cert>
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 4 (0x4)
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=US, ST=CA, L=SanFrancisco, O=Marvin, OU=MyOrganizationalUnit, CN=Marvin CA/name=server/[email protected]
        Validity
            Not Before: Aug  7 20:11:38 2016 GMT
            Not After : Aug  5 20:11:38 2026 GMT
        Subject: C=US, ST=CA, L=SanFrancisco, O=Marvin, OU=MyOrganizationalUnit, CN=theo/name=server/[email protected]
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Modulus:

                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                Easy-RSA Generated Certificate
            X509v3 Subject Key Identifier:
            X509v3 Authority Key Identifier: 
                keyid:
                DirName:/C=US/ST=CA/L=SanFrancisco/O=Marvin/OU=MyOrganizationalUnit/CN=Marvin CA/name=server/[email protected]
                serial:

            X509v3 Extended Key Usage: 
                TLS Web Client Authentication
            X509v3 Key Usage: 
                Digital Signature
            X509v3 Subject Alternative Name: 
                DNS:client
    Signature Algorithm: sha256WithRSAEncryption
             <STUFF HERE>
-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN PRIVATE KEY-----

-----END PRIVATE KEY-----
</key>
<tls-auth>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----

-----END OpenVPN Static key V1-----
</tls-auth>

答案1

所以我注意到你没有推送任何 DHCP 设置或类似的东西。你可以尝试将这些行添加到你的客户端 OVPN:推送“dhcp-option DNS 8.8.8.8”推送“dhcp-option DNS 8.8.4.4”

这将强制它使用那些 DNS 服务器(那些地址是 Google 的 DNS 服务器。如果您的网络上已经有 DNS 服务器,请使用该 IP 地址。)在过去设置 OpenVPN 时,我很久以前就使用过它作为指南,也许它可以提供一些关于如何设置 OVPN 的额外见解。

Ubuntu 作为家庭服务器 | Denis Gladkikh 的博客

答案2

这似乎是权限问题。您可以降级权限client.ovpn作为解决方法。

/home/user/vpn/client.ovpn在编辑器(nano/vim/emacs/gedit 等)中打开,然后取消注释usergroup行。

更改以下行:

# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nogroup

对此:

# Downgrade privileges after initialization (non-Windows only)
user nobody
group nogroup

相关内容