PPTP VPN 不适用于 Linux 路由器

Jez*_*Jez 4 routing debian iptables linux-mint pptp

原来的:

我刚刚为我的路由器从旧的 Linux 安装(Debian 挤压)切换到新的(Linux Mint 17.3)(我使用的是完整的台式电脑,并安装了 Linux 作为我的路由器)。Linux PC 直接连接到我的 DSL 调制解调器并协商 PPPoE 连接,然后为我的所有其他设备路由互联网连接。

据我所知,我的设置与之前的 Debian 安装相同。我有一个简单的rc.local脚本来设置 iptables,它在新机器上是一样的,并且正在运行(我通过/etc/rc.local从根控制台运行来确保这一点)。我还在新盒子上设置了 DNS。

大多数东西都是一样的,但我有一个问题:我的 Windows 机器上的 VPN 不再设法连接。查看Wireshark,我注意到最初的PPTP数据包似乎成功发送和接收,但随后有一个“Set-Link-Info”数据包从我的Windows box发送,然后Windows box开始设置“PPP LCP Configuration Request” "包。此时,它没有收到任何响应。Wireshark 捕获我的旧 Debian 设置显示,当时它得到了响应,最终导致“PPP LCP 配置确认”。

我真的不知道还有什么要检查的。我不明白为什么 PPTP 连接在我的新设置中卡在这里。关于如何排除故障的任何想法?

注意:这/etc/rc.local是设置我的整个 iptables 配置的我(在两次安装中都相同):

#!/bin/sh -e

echo "*** Running rc.local ***"

# First up, make sure 'net.ipv4.ip_forward=1' exists, uncommented, in /etc/sysctl.conf (just do this manually)
echo "MAKE SURE net.ipv4.ip_forward=1 EXISTS, UNCOMMENTED, IN /etc/sysctl.conf OR NAT WILL NOT WORK!!!"
echo ""

# Firewall variables
#WAN_IFACE="eth0"         # At the time of writing, this is the NIC built into the mobo
WAN_IFACE="ppp0"         # Virtual PPP interface when using PPPoE
LAN_IFACE="eth1"         # At the time of writing, this is the extension NIC card
LAN_IP="192.168.1.1/24"  # Class-C internal network

# Setup iptables... flush existing rules
iptables -F
iptables -t nat -F
set +e
# Set +e here to continue on error; iptables may give an error if this chain doesn't currently exist and we try to delete it
iptables -X LOGGING
set -e

# Set default policies for chains
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

# Allow all local loopback access
iptables -A INPUT -i lo -p all -j ACCEPT
iptables -A OUTPUT -o lo -p all -j ACCEPT

# Allow incoming traffic for established connections
iptables -A INPUT -i $WAN_IFACE -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i $WAN_IFACE -p udp -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i $LAN_IFACE -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i $LAN_IFACE -p udp -m state --state RELATED,ESTABLISHED -j ACCEPT

# Allow incoming ICMP traffic
iptables -A INPUT -p icmp -j ACCEPT

###
# Uncomment lines in this section to allow unsolicited incoming traffic on ports
## Open common service ports
## SSH
#iptables -A INPUT -i $WAN_IFACE -p tcp --destination-port 22 -j ACCEPT
## HTTP (8080 + 8081)
#iptables -A INPUT -i $WAN_IFACE -p tcp --destination-port 8080 -j ACCEPT
#iptables -A INPUT -i $WAN_IFACE -p tcp --destination-port 8081 -j ACCEPT
iptables -A INPUT -i eth1 -p tcp --destination-port 8080 -j ACCEPT
iptables -A INPUT -i eth1 -p tcp --destination-port 8081 -j ACCEPT
# DNS
iptables -A INPUT -i eth1 -p tcp --destination-port 53 -j ACCEPT
iptables -A INPUT -i eth1 -p udp --destination-port 53 -j ACCEPT
# Local Samba connections
iptables -A INPUT -p tcp --syn -s $LAN_IP --destination-port 139 -j ACCEPT
iptables -A INPUT -p tcp --syn -s $LAN_IP --destination-port 445 -j ACCEPT
###

# NAT setup - allow the NAT masquerading
iptables -t nat -A POSTROUTING -o $WAN_IFACE -j MASQUERADE

# Allow forwarding of packets between the Internet and local network interface(s)
iptables -A FORWARD -i $WAN_IFACE -o $LAN_IFACE -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $LAN_IFACE -o $WAN_IFACE -j ACCEPT

# Logging setup
iptables -N LOGGING
iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix="IPTables-Dropped: " --log-level 4
iptables -A LOGGING -j DROP

# Logging; uncomment the below to log dropped input packets to syslog (verbose; only use for debugging!)
echo "Uncomment the necessary lines in rc.local to enable iptables logging..."
#iptables -A INPUT -j LOGGING

echo "*** Finished running rc.local ***"

exit 0
Run Code Online (Sandbox Code Playgroud)

更新:

我一直在对此进行更多调查,Wireshark 对我的 Linux 路由器发出的内容的分析揭示了一个非常显着的差异。这是两个屏幕截图,第一个来自我的旧 Debian 机器,其路由有效,第二个来自我的新 Mint 机器,但它没有:

Debian 上的 Wireshark 挤压

Linux Mint 17.3 上的 Wireshark

我用红色和蓝色条纹替换了 IP 地址,以指示我的 Linux 路由器的公共 IP 地址,以及我们与之通信的远程地址,以便通过 PPTP 协议建立 VPN 连接。此外,我的 Windows 机器在本地网络上的 IP 地址以绿色标出。

需要注意的是 PPTP 协议完成后会发生什么,我们切换到 PPP LCP 数据包。在 Debian 机器上,它会继续将这些数据包的源地址转换为我的公共 IP 地址,然后再将它们发送到公共互联网。但是在我的 Linux Mint 机器上,发送的数据包的源地址仍然保留为我试图建立连接的 Windows 机器的本地网络地址。它使用本地 C 类源地址将数据包发送到互联网 - 当然它们不会被路由!

问题是,是什么导致 NAT 在我的 Linux Mint 机器上出现故障,而在 Debian 机器上没有发生?iptables是一样的,/etc/network/interfaces都是一样的。我不知道......但也许这个发现会帮助这里的人帮助我解决这个问题。:-)

der*_*ert 5

为了使 NAT 工作,您需要加载特定于协议的帮助程序模块。默认情况下,您只会加载 TCP 和 UDP 的内容。

这就是为什么您会看到 PPTP 流量(实际上是 PPP over GRE)在没有 NAT 的情况下逃逸的原因。该模块是nf_nat_proto_gre,至少从 Linux 4.4 开始。

类似的故事适用于连接跟踪(没​​有它,GRE 数据包不会被视为已建立或相关连接的一部分)。那是nf_conntrack_proto_gre

事实证明,PPTP 也需要特殊处理(我猜它在 PPP 协商中嵌入了 IP 地址,但我还没有检查过)。nf_nat_pptpPPTP 连接的特殊处理和跟踪由nf_conntrack_pptp.

Amodprobe ip_nat_pptp应该让你的 VPN 工作。模块之间的依赖关系将最终加载所有四个。要使其在整个启动过程中继续工作,请添加nf_nat_pptp/etc/modules.

(不,我不知道这是在哪里记录的,抱歉!)


Mir*_*nov 5

derobert 的回答是正确的。但是对于较新的内核版本,还有另一个问题——出于安全原因,net.netfilter.nf_conntrack_helper 的默认值更改为 0。

见相关:

简单的解决方法是再次将其设为 1。在/etc/sysctl.conf底部添加

net.netfilter.nf_conntrack_helper = 1
Run Code Online (Sandbox Code Playgroud)

然后重新启动或运行 sysctl -p

  • 当然,任何 sysctl.conf 更改,都不需要重新启动,只需发出 `sysctl -p`。 (2认同)