如何通过 ipsec / xl2ptd vpn 访问远程局域网机器(可能与 iptables 相关)

如何通过 ipsec / xl2ptd vpn 访问远程局域网机器(可能与 iptables 相关)

我正在尝试为我们的办公室设置 IPSEC / XL2TPD VPN,但连接到 VPN 后在访问远程本地机器时遇到了一些问题。

我可以连接,并且可以通过 VPN 浏览互联网网站,但正如所说,我无法连接甚至 ping 本地网站。

我的网络设置如下:

互联网 > eth0 > 路由器 / VPN > eth2 > LAN

以下是 VPN 背后的一些跟踪路由:

traceroute to google.com (173.194.78.94), 64 hops max, 52 byte packets
 1  192.168.1.80 (192.168.1.80)  74.738 ms  71.476 ms  70.123 ms
 2  10.35.192.1 (10.35.192.1)  77.832 ms  77.578 ms  77.865 ms
 3  10.47.243.137 (10.47.243.137)  78.837 ms  85.409 ms  76.032 ms
 4  10.47.242.129 (10.47.242.129)  78.069 ms  80.054 ms  77.778 ms
 5  10.254.4.2 (10.254.4.2)  86.174 ms
    10.254.4.6 (10.254.4.6)  85.687 ms
    10.254.4.2 (10.254.4.2)  85.664 ms

traceroute to 192.168.1.3 (192.168.1.3), 64 hops max, 52 byte packets
 1  * * *
 2  *traceroute: sendto: No route to host
traceroute: wrote 192.168.1.3 52 chars, ret=-1
 *traceroute: sendto: Host is down
traceroute: wrote 192.168.1.3 52 chars, ret=-1
 *
traceroute: sendto: Host is down
 3 traceroute: wrote 192.168.1.3 52 chars, ret=-1
 *traceroute: sendto: Host is down
traceroute: wrote 192.168.1.3 52 chars, ret=-1

这些是我的 iptables 规则:

iptables -A INPUT -i lo -j ACCEPT

iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

# allow lan to router traffic
iptables -A INPUT -s 192.168.1.0/24 -i eth2 -j ACCEPT

# ssh
iptables -A INPUT -p tcp --dport ssh -j ACCEPT

# vpn
iptables -A INPUT -p 50 -j ACCEPT
iptables -A INPUT -p ah -j ACCEPT
iptables -A INPUT -p udp --dport 500 -j ACCEPT
iptables -A INPUT -p udp --dport 4500 -j ACCEPT
iptables -A INPUT -p udp --dport 1701 -j ACCEPT

# dns
iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 53 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -p udp --dport 53 -j ACCEPT

iptables -t nat -A POSTROUTING -j MASQUERADE

# logging
iptables -I INPUT 5 -m limit --limit 1/min -j LOG --log-prefix "iptables denied: " --log-level 7

# block all other traffic
iptables -A INPUT -j DROP

以下是一些防火墙日志行:

Dec  6 11:11:57 router kernel: [8725820.003323] iptables denied: IN=ppp0 OUT= MAC= SRC=192.168.1.81 DST=192.168.1.3 LEN=60 TOS=0x00 PREC=0x00 TTL=255 ID=62174 PROTO=UDP SPT=61910 DPT=53 LEN=40 
Dec  6 11:12:29 router kernel: [8725852.035826] iptables denied: IN=ppp0 OUT= MAC= SRC=192.168.1.81 DST=224.0.0.1 LEN=44 TOS=0x00 PREC=0x00 TTL=1 ID=15344 PROTO=UDP SPT=56329 DPT=8612 LEN=24 
Dec  6 11:12:36 router kernel: [8725859.121606] iptables denied: IN=ppp0 OUT= MAC= SRC=192.168.1.81 DST=224.0.0.1 LEN=44 TOS=0x00 PREC=0x00 TTL=1 ID=11767 PROTO=UDP SPT=63962 DPT=8612 LEN=24 
Dec  6 11:12:44 router kernel: [8725866.203656] iptables denied: IN=ppp0 OUT= MAC= SRC=192.168.1.81 DST=224.0.0.1 LEN=44 TOS=0x00 PREC=0x00 TTL=1 ID=11679 PROTO=UDP SPT=57101 DPT=8612 LEN=24 
Dec  6 11:12:51 router kernel: [8725873.285979] iptables denied: IN=ppp0 OUT= MAC= SRC=192.168.1.81 DST=224.0.0.1 LEN=44 TOS=0x00 PREC=0x00 TTL=1 ID=39165 PROTO=UDP SPT=62625 DPT=8612 LEN=24 

我很确定问题应该与 iptables 有关,但是在尝试了很多不同的配置之后,我还是无法找到正确的配置。

任何帮助都将不胜感激 ;)。诚挚的问候,西蒙。

编辑:

这是我的路线表:

default         62.43.193.33.st 0.0.0.0         UG    100    0        0 eth0
62.43.193.32    *               255.255.255.224 U     0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth2
192.168.1.81    *               255.255.255.255 UH    0      0        0 ppp0

答案1

你很可能遇到了同样的问题邮政

您的情况如下:

VPN 客户端可以访问 VPN 服务器并通过 VPN 隧道连接到互联网,但无法访问服务器 LAN 或任何其他 VPN 客户端 IP。

由于您有 iptables NAT 规则,因此隧道连接到互联网是可行的。其余您需要应用以下内容在 VPN 服务器上

启用 tcp/ip 转发

Linux TCP/IP 堆栈默认不转发数据包(无论是在接口之间还是在 IP 网络之间重新路由)。必须启用它

echo 1 > /proc/sys/net/ipv4/ip_forward

如果没有该规则,VPN 服务器将在本地接受 VPN 客户端数据包,并根据 NAT 规则路由客户端数据包,但不会将流量路由到本地网络。

iptables 目录

Iptables 默认阻止所有流量。您需要制定规则来允许流量通过(转发)。

$IPTABLES -A FORWARD -s 192.168.1.0/24 -d 192.168.1.0/24 -j ACCEPT

PS:每个 vpn 连接都是一个单独的(虚拟)接口(nic),为了允许数据包在它们之间流动/路由,您需要向前在 iptables 中。

/etc/l2tpd.conf

当 vpn 客户端需要互相通信时,vpn 服务器充当路由点,并且需要在同一个网络上。

local ip 192.168.1.1
ip range 192.168.1.2 - 192.168.1.254

根据您的网络设置修改上述内容。如果您的 vpn 服务器有 192.168.1.x ip,请将其用作“本地 ip”。

修改 Iptables 脚本

如果您无法物理访问 vpn 服务器,请务必小心。

(此脚本需要在 WAN 接口上进行反欺骗,但让我们首先关注从 VPN 到 LAN 的流量。)

# Reset/Flush iptables
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# NAT
# -- iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
#
# Updated NAT rule
#   External interface  = eth0
#   External IP     = 123.123.123.123
#   Internal LAN        = 192.168.1.0/24
#   To support dynamic interface : "-j SNAT" replace "-j MASQUERADE" 
#   NO NAT if destination is LAN 
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 ! -d 192.168.1.0/24 -j SNAT --to-source 123.123.123.123

# New(1) - lo
# -- iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i lo   -m state --state NEW  -j ACCEPT
iptables -A OUTPUT -o lo   -m state --state NEW  -j ACCEPT

# -- iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

# New(2) Allow inter-192.168.1.x routing
iptables -A INPUT  -s 192.168.1.0/24   -m state --state NEW  -j ACCEPT
iptables -A OUTPUT  -s 192.168.1.0/24   -m state --state NEW  -j ACCEPT
iptables -A FORWARD  -s 192.168.1.0/24   -m state --state NEW  -j ACCEPT

# -- allow lan to router traffic - Shadowed by New(2)
# -- This rule maybe your source of trouble too, it only accept 192.168.1.x from eth2
# -- iptables -A INPUT -s 192.168.1.0/24 -i eth2 -j ACCEPT

# ssh
iptables -A INPUT -p tcp --dport ssh -j ACCEPT

# vpn
iptables -A INPUT -p 50 -j ACCEPT
iptables -A INPUT -p ah -j ACCEPT
iptables -A INPUT -p udp --dport 500 -j ACCEPT
iptables -A INPUT -p udp --dport 4500 -j ACCEPT
iptables -A INPUT -p udp --dport 1701 -j ACCEPT

# dns - Shadowed by New(2)
# -- iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 53 -j ACCEPT
# -- iptables -A INPUT -s 192.168.1.0/24 -p udp --dport 53 -j ACCEPT

# logging
iptables -I INPUT 5 -m limit --limit 1/min -j LOG --log-prefix "iptables denied: " --log-level 7

# block all other traffic
iptables -A INPUT -j DROP

答案2

嗯,部分答案似乎是:iptables -A OUTPUT -p tcp --dport dns -j ACCEPT

... 类似于您描述中的“-A INPUT”的语句

好的,我一开始就应该意识到这一点:您正在运行 NAT,所以......

iptables -A 转发 -i eth1 -o ppp0 -j 接受
iptables -A 转发 -o eth1 -i ppp0 -j 接受
sysctl -w net.ipv4.ip_forward=1
iptables -A 转发 -i ppp0 -o eth1 -p tcp --dport 80 -d xxxx -j 接受
iptables -A 转发 -i ppp0 -o eth1 -p tcp --dport 53 -d yyyy -j 接受
iptables -t 过滤器 -P 转发 丢弃

相关内容