pptpd VPN:连接后无法上网

Tra*_*ent 5 vpn networking internet pptpd ip

我已按照本教程中的说明设置了一个 vpn 服务器,以便我可以连接到该服务器并从另一个位置虚拟上网。离windows很远,我可以连接到它,但没有互联网访问。

我在conf文件中使用的ip地址和教程中的完全一样

localip 192.168.0.1
remoteip 192.168.0.100-200
Run Code Online (Sandbox Code Playgroud)

DNS 也是 8.8.8.8。

(你需要知道的关于我所做的一切都已经在那个链接中了)

你认为可能是什么问题?

小智 10

如果您设置 VPN 服务器的主要目的是访问网站,那么流量必须从 VPN 服务器的公共网络接口转发出去。因此,请通过编辑 sysctl.conf 文件来启用端口转发。我假设 /etc/sysctl.conf 文件中注释了“net.ipv4.ip_forward”:

nano /etc/sysctl.conf
Run Code Online (Sandbox Code Playgroud)

添加或查找并注释掉以下行

net.ipv4.ip_forward=1
Run Code Online (Sandbox Code Playgroud)

保存,关闭文件并运行以下命令使更改生效。

sysctl -p
Run Code Online (Sandbox Code Playgroud)

以下 iptables 防火墙规则允许端口 1723、GRE 和执行 NAT

iptables -I INPUT -p tcp --dport 1723 -m state --state NEW -j ACCEPT
iptables -I INPUT -p gre -j ACCEPT
iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
Run Code Online (Sandbox Code Playgroud)

在最后一条规则中替换“eth0? 与连接到您的 VPN 服务器上的互联网的接口。最后需要以下规则来确保网站正确加载

iptables -I FORWARD -p tcp --tcp-flags SYN,RST SYN -s 172.20.1.0/24 -j TCPMSS  --clamp-mss-to-pmtu
Run Code Online (Sandbox Code Playgroud)

将 172.20.1.0/24 替换为 /etc/pptpd.conf 中“remoteip”选项中使用的 IP 地址范围,此防火墙规则用于确保使用正确的 MTU 值来防止碎片。

希望它能有所帮助。