openVPN:如何在客户端之间建立连接?

时间:2015-03-01 09:44:50

标签: raspberry-pi openvpn umts

本周末,我正在研究我的两个覆盆子Pi(B和新型号2)之间的VPN连接。我为它选择了openVPN。两人都跑Raspbian Wheezy。

所以我的设置如下:

| B |在家里连接到互联网(DSL,静态IP)。 另一个Pi | 2 |我带着我。它通过UMTS路由器连接到互联网。这出乎意料的好:) 在家里| B |我有一台运行的服务器和| 2 |登录到它没有任何问题。

我的问题是你们: 如何从我的本地网络(与PI | B |相同),从我的iPhone连接到| 2 |已经连接到| B |?

的连接

我像这样配置了我的服务器:

dev tun
proto udp
port 34345
ca /etc/openvpn/easy-rsa/keys/ca.crt
cert /etc/openvpn/easy-rsa/keys/server.crt
key /etc/openvpn/easy-rsa/keys/server.key
dh /etc/openvpn/easy-rsa/keys/dh1024.pem
user nobody
group nogroup
server 10.8.0.0 255.255.255.0
persist-key
persist-tun
status /var/log/openvpn-status.log
verb 3
client-to-client
push "redirect-gateway def1 bypass-dhcp"
#set the dns servers
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
log-append /var/log/openvpn
comp-lzo
duplicate-cn
keepalive 10 120

那是我的客户端配置:

dev tun
client
proto udp
remote {myIP} 34345 #same port as on the server
resolv-retry infinite
nobind
persist-key
persist-tun
ca /home/pi/vpn/ca.crt
cert /home/pi/vpn/raspi.crt
key /home/pi/vpn/raspi.key
comp-lzo
verb 3

正如我所说,连接效果很好,如果我在新的覆盆子的控制台内发出“curl www.echoip.net/plain”,我会得到我的静态IP地址。所以我猜它一般都有用。

我已经尝试访问10.8.0。*但这不起作用,我想不出为什么?

有什么想法吗?

提前致谢, 菲利克斯

再次编辑:

服务器日志在成功验证后说明了raspi连接时的以下内容:

Tue Mar  3 18:59:00 2015 2.240.44.246:26966 [raspi] Peer Connection Initiated with [AF_INET]2.240.44.246:26966
Tue Mar  3 18:59:00 2015 raspi/2.240.44.246:26966 MULTI_sva: pool returned IPv4=10.8.0.6, IPv6=e8b6:d1be:808e:f8b6:34bb:fdb6:4405:79b8
Tue Mar  3 18:59:00 2015 raspi/2.240.44.246:26966 MULTI: Learn: 10.8.0.6 -> raspi/2.240.44.246:26966
Tue Mar  3 18:59:00 2015 raspi/2.240.44.246:26966 MULTI: primary virtual IP for raspi/2.240.44.246:26966: 10.8.0.6
Tue Mar  3 18:59:02 2015 raspi/2.240.44.246:26966 PUSH: Received control message: 'PUSH_REQUEST'
Tue Mar  3 18:59:02 2015 raspi/2.240.44.246:26966 send_push_reply(): safe_cap=960
Tue Mar  3 18:59:02 2015 raspi/2.240.44.246:26966 SENT CONTROL [raspi]: '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' (status=1)

在客户端RPi 2上运行的输出如下所示(再次,在成功验证后):

Tue Mar  3 18:59:00 2015 [server] Peer Connection Initiated with [AF_INET]2.240.44.246:34345
Tue Mar  3 18:59:02 2015 SENT CONTROL [server]: 'PUSH_REQUEST' (status=1)
Tue Mar  3 18:59:02 2015 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'
Tue Mar  3 18:59:02 2015 OPTIONS IMPORT: timers and/or timeouts modified
Tue Mar  3 18:59:02 2015 OPTIONS IMPORT: --ifconfig/up options modified
Tue Mar  3 18:59:02 2015 OPTIONS IMPORT: route options modified
Tue Mar  3 18:59:02 2015 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
Tue Mar  3 18:59:02 2015 ROUTE default_gateway=192.168.2.201
Tue Mar  3 18:59:02 2015 TUN/TAP device tun0 opened
Tue Mar  3 18:59:02 2015 TUN/TAP TX queue length set to 100
Tue Mar  3 18:59:02 2015 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
Tue Mar  3 18:59:02 2015 /sbin/ifconfig tun0 10.8.0.6 pointopoint 10.8.0.5 mtu 1500
Tue Mar  3 18:59:02 2015 /sbin/route add -net 2.240.44.246 netmask 255.255.255.255 gw 192.168.2.201
Tue Mar  3 18:59:02 2015 /sbin/route add -net 0.0.0.0 netmask 128.0.0.0 gw 10.8.0.5
Tue Mar  3 18:59:02 2015 /sbin/route add -net 128.0.0.0 netmask 128.0.0.0 gw 10.8.0.5
Tue Mar  3 18:59:02 2015 /sbin/route add -net 10.8.0.0 netmask 255.255.255.0 gw 10.8.0.5
Tue Mar  3 18:59:02 2015 Initialization Sequence Completed

ifconfig在服务器端返回lo和eth0:

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.1  P-t-P:10.8.0.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:1907 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1820 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:245870 (240.1 KiB)  TX bytes:1046186 (1021.6 KiB)

在客户端,它看起来像这样:

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
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:76 (76.0 B)  TX bytes:380 (380.0 B)

以下是结构图: http://i.stack.imgur.com/z9QUs.jpg

1 个答案:

答案 0 :(得分:0)

为了访问您的RPi | 2 |来自其他VPN客户端的客户端(在您的情况下是其iPhone),您必须知道RPi | 2 |的IP地址客户。在当前方案中,动态IP地址分配给RPi | 2 |客户端每次与服务器建立新连接时。

要解决此问题,必须为RPi | 2 |使用静态IP地址客户。可以找到设置特定客户端的静态IP地址的过程here.