OpenVPN不能连接上网的解决方案

2018-10-25  本文已影响1217人  破旧的大卡车

首先, 我是利用aykutcan一键安装脚本来安装的, 后来由于ip变了, 导致不能通过vpn上网. 下面记录下修复过程.

根据官方说明, 我们检查/etc/openvpn/server.conf是否有如下几行:

push "redirect-gateway def1"
push "dhcp-option DNS 10.8.0.1"

然后, 还需要添加iptables:

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

例如, 我的server.conf配置是

port 1194
proto udp
dev tun
sndbuf 0
rcvbuf 0
ca ca.crt
cert server.crt
key server.key
dh dh.pem
tls-auth ta.key 0
topology subnet
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 74.82.42.42"
push "dhcp-option DNS 4.2.2.1"
push "dhcp-option DNS 8.8.4.4"
keepalive 10 120
cipher AES-128-CBC
comp-lzo
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
crl-verify crl.pem

然后, 将上面的iptables写入到/etc/rc.local开头, 使得每次重启生效:

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to ReplaceWithYourVPS_IP

然后就ok啦.

上一篇下一篇

猜你喜欢

热点阅读