创buildOpenVPN隧道,但似乎没有数据传输

我有几个Amazon EC2实例,运行Ubuntu,需要进行通信(Web服务器和MySQL服务器)。 我想使用OpenVPN,以确保他们的通信是安全的,并减less开放端口的数量。 我一直在关注这篇文章 ,但是我遇到了一个问题。 注意:我正在使用端口1194,而不是端口80,如文章中所示。

我已经在MySQL服务器上安装并configuration了OpenVPN服务器,并设置了一个Web服务器作为客户端连接到它。 运行ifconfig显示双方都创build了隧道,但数据似乎没有被传输。

如何更改默认路由以使其使用VPN隧道? 我假设这是问题,但我不积极。


以下是我的server.conf和client.conf文件。 我使用tun而不是tap,从我读过的内容来看,我认为这是最好的select。 我目前压缩closures,只是为了消除这个问题。

为server.conf

 port 1194 proto udp server 10.4.0.0 255.255.255.0 dev tun dh dh1024.pem ca ca.crt cert mysqlserver.crt key mysqlserver.key 

client.conf

 ############################################## # 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 my-server-1 1194 ;remote my-server-2 1194 remote myopenvpnserver.com 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 webclient.crt key webclient.key # 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. ;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 

鉴于您目前的configuration,当一台主机连接10.4.0.0/24networking。 如果您使用10.4.0.0/24范围内的IP在主机之间进行通信,则应该跨越隧道。 您的服务器将很可能有地址10.4.0.1。 从一个客户端,你应该能够ping通10.4.0.1,同时在tun接口上运行一个捕获,并看到通过隧道的ICMP。

如果您希望主机之间的所有通信都通过隧道,则可能需要使用VPN子网中的专用IP在主机之间进行通信。

为了使这更容易,您可能需要调整您的VPNconfiguration来分配静态IP。

推动静态地址,你会像这样修改你的服务器configuration。

OpenVPN服务器configuration。

 #server 10.4.0.0 255.255.255.0 mode server tls-server push "topology net30" ifconfig 10.4.0.1 10.4.0.2 ifconfig-pool 10.4.0.192 10.4.0.251 route 10.4.0.0 255.255.255.0 push "route 10.4.0.1" # setup a per client config. Clients are defined by the CN value in the cert. client-config-dir /etc/openvpn/ccd 

/etc/openvpn/ccd/client1.example.org

 ifconfig-push 10.4.0.5 10.4.0.6 push "route 10.4.0.0 255.255.255.0" 

/etc/openvpn/ccd/client2.example.org

 ifconfig-push 10.4.0.9 10.4.0.10 push "route 10.4.0.0 255.255.255.0" 

/etc/openvpn/ccd/client3.example.org

 ifconfig-push 10.4.0.13 10.4.0.14 push "route 10.4.0.0 255.255.255.0" 

我对EC2不是很熟悉。 他们如何解决? 具体而言,每个主机位于不同的子网上,或者它们都位于同一个子网上。 如果他们在这个不同的子网上。

 Web server 192.168.25.5/30 Mysql server 192.168.25.17/30 

然后,您可以轻松地从您的OpenVPN服务器推送路由,以便所有发往这些networking之一的stream量都将使用vpn。

 push "route 192.168.25.4/30" push "route 192.168.25.16/30" 

如果主机的非vpn接口全部在同一个子网上,这将不起作用。 因为他们会直接连接。