OpenVPN不是所有stream量的默认网关

我试图让我的客户端通过运行OpenVPN的VPS转发所有stream量。 正如你所看到的,它将允许ping到域名和原始IP地址,但是不允许像curl和traceroute这样的stream量不能提供任何东西。 没有连接到VPN时,stream量正常工作。

所有信息在这里: http : //pastebin.com/Zpvzs7gW

谢谢。

工作configuration感谢以下解决scheme:

服务器:

port <integer> proto udp dev tun ca ca.crt cert vpnserver.crt key vpnserver.key # This file should be kept secret dh dh4096.pem tls-auth ta.key 0 server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "redirect-gateway autolocal" push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4" keepalive 10 120 cipher AES-256-CBC comp-lzo user nobody group nogroup persist-key persist-tun status openvpn-status.log verb 3 

客户:

 client dev tun proto udp remote xxxx <port number> resolv-retry infinite nobind persist-key persist-tun ca ca.crt cert vpnclient.crt key vpnclient.key tls-auth ta.key 1 ns-cert-type server cipher AES-256-CBC comp-lzo verb 3 

解决scheme有两个部分:

1.将所有stream量redirect到隧道

最简单的解决scheme – 使用OpenVPN的 – --redirect-gateway autolocal选项(或把它作为redirect-gateway autolocalconfiguration文件。

2.处理OpenVPN服务器上的stream量

现在隧道已经开通,所有的stream量都进入隧道,并从tun0接口在服务器端popup。

您需要configuration两件事情才能使其工作:

一个。 启用数据包转发

默认情况下,在大多数分发中,数据包转发被禁用,因此来自通道接口的数据包永远不会将其发送到公共接口。 您必须启用转发:

 ~ # sysctl net.ipv4.ip_forward=1 net.ipv4.ip_forward = 1 

一旦testing,在/etc/sysctl.conf更改永久

还要确保iptables不阻止转发的stream量:

 ~ # iptables -I FORWARD -j ACCEPT 

这对于testing来说已经足够了 – 在生产中,您会希望使防火墙规则更具体一些,但这不在范围之内。

NAT从隧道传出的数据包

启用转发function后,数据包的默认转发源地址不变,即您的情况为10.8.0.6 – 这些数据包将丢弃在ISP网关上,或者即使它们到达目的地,回复也不会返回。 这些私人地址在互联网上不可路由。

解决的办法是对出口stream量进行NAT转换, 10.8.0.6私有的10.8.0.6地址replace为VPN服务器的公有IP。 这将确保答复到达VPN服务器,并在那里他们将被转回到隧道。

 ~ # iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE 

3.testing一下

现在尝试从你的VPN客户端ping 8.8.4.4 。 你应该看到一个答复。 让我们知道,如果没有:)