Amazon EC2 Ubuntu 12.04 - 无法通过OpenVPN路由所有流量

时间:2013-10-03 14:01:12

标签: ubuntu-12.04 iptables openvpn

我正在尝试在我的远程Ubuntu 12.04网络服务器上使用OpenVPN,但是一旦OpenVPN运行,我就无法连接到互联网。

启动OpenVPN,路线说:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         ip-172-31-16-1. 0.0.0.0         UG    100    0        0 eth0
172.31.16.0     *               255.255.240.0   U     0      0        0 eth0

之后:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.200.4.1      128.0.0.0       UG    0      0        0 tun0
default         172.31.16.1     0.0.0.0         UG    100    0        0 eth0
10.200.4.0      *               255.255.252.0   U     0      0        0 tun0
128.0.0.0       10.200.4.1      128.0.0.0       UG    0      0        0 tun0
172.31.16.0     *               255.255.240.0   U     0      0        0 eth0
184.170.137.2   172.31.16.1     255.255.255.255 UGH   0      0        0 eth0

184.170.137.2是VPN。 OpenVPN HOWTO建议使用

iptables -t nat -A POSTROUTING -s 10.200.4.0/22 -o eth0 -j MASQUERADE

抛出

sudo: unable to resolve host ip-172-31-26-178 

(172.31.26.178是内部IP)。

如果我执行以下操作,我可以将VPN用于单个网站:

route add -net {website ip} netmask 255.255.255.255 gw 10.200.4.1 dev tun0
route del -net 0.0.0.0 netmask 128.0.0.0 dev tun0
route del -net 128.0.0.0 netmask 128.0.0.0 dev tun0 

如何更改此功能以适用于整个网络?非常感谢帮助。

1 个答案:

答案 0 :(得分:0)

这就是问题所在。与hidemyass的连接由hma-vpn.sh脚本完成,您必须更改

#!/bin/sh
cat <<EOEO >> /tmp/hma-ipcheck.txt
 *******************************************
* *
* You are now connected to HMA Pro! VPN *
* *
 *******************************************

Checking new IP address...
EOEO
nohup /tmp/hma-ipcheck.sh >/dev/null 2>&1 >
rm /tmp/hma-routeup.sh
EOF

#!/bin/sh
cat <<EOEO >> /tmp/hma-ipcheck.txt
 *******************************************
* *
* You are now connected to HMA Pro! VPN *
* *
 *******************************************

Checking new IP address...
EOEO
vpn_gw=\$(ip route | grep tun0 | grep 0.0.0.0 | cut -d" " -f3)
route del -net 0.0.0.0 gw {your-original-default-gateway}
route del -net 0.0.0.0 gw \$vpn_gw
route del -net 0.0.0.0 netmask 128.0.0.0 gw \$vpn_gw
route del -net 128.0.0.0 netmask 128.0.0.0 gw \$vpn_gw
route add default gw \$vpn_gw
echo "nameserver 208.67.222.222">/etc/resolv.conf
nohup /tmp/hma-ipcheck.sh >/dev/null 2>&1 >
rm /tmp/hma-routeup.sh
EOF`enter code here`

这会将您的默认网关更改为vpn服务器。 如果您的dns可通过vpn

访问,则可以跳过echo "nameserver 208.67.222.222">/etc/resolv.conf
相关问题