OpenVPN - Linux クライアントは接続したがインターネットにアクセスできなかった、ルーティングの問題

OpenVPN - Linux クライアントは接続したがインターネットにアクセスできなかった、ルーティングの問題

かなり前に、すべてのインターネット トラフィックがルーティングされるゲートウェイ オプションを使用して OpenVPN サーバーをインストールしました。

Windows や Android フォンなどのクライアント マシンでは正常に動作しますが、Ubuntu ノートブック上の同じ Open VPN クライアント構成は動作しないようです。クライアントは VPN サーバーに接続しますが、インターネット トラフィックはルーティングされないようです。

接続がアクティブなときに VPN サーバーに ping を実行すると機能します: ping 10.8.0.1

何が足りないのか分かりません。これまで以下のオプションを試しました

  • クライアントにルート設定を追加しました: ルート 10.8.0.0/24
  • コンソール経由でルート設定を追加しようとします: sudo route add -net 10.8.0.0/24 gw 1​​0.8.0.1 dev tun0 しかし、VPN が稼働しているにもかかわらず、ネットワークに到達できないというエラーが発生します。
  • Ubuntuクライアントのファイアウォールをオフにしました

何かアドバイスやヒントがあれば、ぜひ教えてください。

サーバー設定:

port 443
proto tcp
dev tun
ca ...
cert ...
key ...
dh ...
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway def1 bypasss-dhcp"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
client-to-client
keepalive 10 120
comp-lzo
persist-key
persist-tun
status ...
log ...
verb 3

クライアント設定:

client
dev tun
proto tcp
remote www.serverdomain.com 443
resolv-retry infinite
nobind
persist-key
persist-tun
comp-lzo
verb 3
remote-cert-tls server
# route 10.8.0.0/24 --> adding such a route made no difference

クライアントのifconfig:

tun0      
      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
      inet addr:10.8.0.10  P-t-P:10.8.0.9  Mask:255.255.255.255
      inet6 addr: fe80::b393:268c:61db:72d4/64 Scope:Link
      UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
      RX packets:47 errors:0 dropped:0 overruns:0 frame:0
      TX packets:93 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:100 
      RX bytes:4394 (4.3 KB)  TX bytes:7012 (7.0 KB)

wlp1s0    
      Link encap:Ethernet  HWaddr a4:34:d9:5c:9d:06  
      inet addr:192.168.0.130  Bcast:192.168.0.255  Mask:255.255.255.0
      inet6 addr: fe80::5e97:3a8f:9596:8c30/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:24879 errors:0 dropped:0 overruns:0 frame:0
      TX packets:17473 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:14983497 (14.9 MB)  TX bytes:2721828 (2.7 MB)

クライアントログ出力:

 Thu Nov  3 21:03:25 2016 OpenVPN 2.3.10 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [MH] [IPv6] built on Feb  2 2016
 Thu Nov  3 21:03:25 2016 library versions: OpenSSL 1.0.2g-fips  1 Mar 2016, LZO 2.08
 Thu Nov  3 21:03:25 2016 Socket Buffers: R=[87380->87380] S=[16384->16384]
 Thu Nov  3 21:03:25 2016 Attempting to establish TCP connection with [AF_INET]188.62.xx.xx:443 [nonblock]
 Thu Nov  3 21:03:26 2016 TCP connection established with [AF_INET]188.62.xx.xx:443
 Thu Nov  3 21:03:26 2016 TCPv4_CLIENT link local: [undef]
 Thu Nov  3 21:03:26 2016 TCPv4_CLIENT link remote: [AF_INET]188.62.xx.xx:443
 Thu Nov  3 21:03:26 2016 TLS: Initial packet from [AF_INET]188.62.xx.xx:443, sid=ff1258e5 f87eeaf5
 Thu Nov  3 21:03:26 2016 VERIFY OK: depth=1, C=CH, ST=ZH, L=Hinwil, O=xxx, OU=IT, CN=xxxx, name=xxxx, emailAddress=xxxx.ch
 Thu Nov  3 21:03:26 2016 Validating certificate key usage
 Thu Nov  3 21:03:26 2016 ++ Certificate has key usage  00a0, expects 00a0
 Thu Nov  3 21:03:26 2016 VERIFY KU OK
 Thu Nov  3 21:03:26 2016 Validating certificate extended key usage
 Thu Nov  3 21:03:26 2016 ++ Certificate has EKU (str) TLS Web Server Authentication, expects TLS Web Server Authentication
 Thu Nov  3 21:03:26 2016 VERIFY EKU OK
 Thu Nov  3 21:03:26 2016 VERIFY OK: depth=0, C=CH, ST=ZH, L=Hinwil, O=xxxx, OU=IT, CN=xxxx, name=xxxxx, emailAddress=xxxx.ch
 Thu Nov  3 21:03:26 2016 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
 Thu Nov  3 21:03:26 2016 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
 Thu Nov  3 21:03:26 2016 Data Channel Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
 Thu Nov  3 21:03:26 2016 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
 Thu Nov  3 21:03:26 2016 Control Channel: TLSv1.2, cipher     TLSv1/SSLv3 DHE-RSA-AES256-GCM-SHA384, 2048 bit RSA
 Thu Nov  3 21:03:26 2016 [xxxx] Peer Connection Initiated with [AF_INET]188.62.xx.xx:443
 Thu Nov  3 21:03:28 2016 SENT CONTROL [diabolo]: 'PUSH_REQUEST' (status=1)
 Thu Nov  3 21:03:29 2016 PUSH: Received control message: 'PUSH_REPLY,redirect-gateway def1 bypass-dhcp,dhcp-option DNS 8.8.8.8,dhcp-option DNS 8.8.4.4,route 10.8.0.0 255.255.255.0,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5'
 Thu Nov  3 21:03:29 2016 OPTIONS IMPORT: timers and/or timeouts modified
 Thu Nov  3 21:03:29 2016 OPTIONS IMPORT: --ifconfig/up options modified
 Thu Nov  3 21:03:29 2016 OPTIONS IMPORT: route options modified
 Thu Nov  3 21:03:29 2016 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
 Thu Nov  3 21:03:29 2016 ROUTE_GATEWAY 192.168.0.1/255.255.255.0 IFACE=wlp1s0 HWADDR=a4:34:d9:5c:9d:06
 Thu Nov  3 21:03:29 2016 TUN/TAP device tun0 opened
 Thu Nov  3 21:03:29 2016 TUN/TAP TX queue length set to 100
 Thu Nov  3 21:03:29 2016 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
 Thu Nov  3 21:03:29 2016 /sbin/ip link set dev tun0 up mtu 1500
 Thu Nov  3 21:03:29 2016 /sbin/ip addr add dev tun0 local 10.8.0.6 peer 10.8.0.5
 Thu Nov  3 21:03:29 2016 /sbin/ip route add 188.62.79.43/32 via 192.168.0.1
 Thu Nov  3 21:03:29 2016 /sbin/ip route add 0.0.0.0/1 via 10.8.0.5
 Thu Nov  3 21:03:29 2016 /sbin/ip route add 128.0.0.0/1 via 10.8.0.5
 Thu Nov  3 21:03:29 2016 /sbin/ip route add 10.8.0.0/24 via 10.8.0.5
 Thu Nov  3 21:03:29 2016 Initialization Sequence Completed

クライアントnetstat -rn

 Kernel IP routing table
 Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
 0.0.0.0         10.8.0.9        128.0.0.0       UG        0 0          0 tun0
 0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 wlp1s0
 10.8.0.0        10.8.0.9        255.255.255.0   UG        0 0          0 tun0
 10.8.0.9        0.0.0.0         255.255.255.255 UH        0 0          0 tun0
 128.0.0.0       10.8.0.9        128.0.0.0       UG        0 0          0 tun0
 169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 wlp1s0
 188.62.xx.xx    192.168.0.1     255.255.255.255 UGH       0 0          0 wlp1s0
 192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 wlp1s0

答え1

イーサネット/WiFiカードの「メトリック」を下げることでこの問題を解決できました。「route」コマンドまたは追加ツール「イフメトリック「(sudo apt-get install ifmetric)つまり、ifmetric eth0 100(0 = 最高優先度)

その後、VPN 接続がセットアップされたときに、OpenVPN サーバーからの DNS エントリが引き継がれていないことに気付きました。そこで Google で検索したところ、Ubuntu クライアントの設定ファイルに次の行を追加する必要があるという回答が見つかりました。

script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf

これは、サーバーからプッシュされたエントリを使用して VPN 接続が確立されたときに、「/etc/resolv.conf」内の DNS エントリを更新します。

だから、今はそれが魔法のように機能しています。

答え2

試す:

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

答え3

OpenVPN Linuxクライアントのインストール時の権限の問題でしょうか?トゥン。 それで自分で作りました(それが実際の問題でした)

sudo ip tuntap add name tun0 mode tun
sudo ip link show

VPN ユーザー名とパスワードを要求された後、接続され、ようやくインターネットに接続できるようになりました。

ソース:https://www.naturalborncoder.com/virtualization/2014/10/17/understanding-tun-tap-interfaces

設定を自動的に実行する公式の openvpn3-linux クライアントとインストーラーを試すための代替ソリューション:https://github.com/OpenVPN/openvpn3-linux

関連情報