首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用iptables转发IPsec虚拟专用网

如何用iptables转发IPsec虚拟专用网
EN

Server Fault用户
提问于 2018-06-30 16:52:27
回答 2查看 14.1K关注 0票数 1

你好,我有一些关于如何使用iptables转发IPsec数据的问题。以下是我想做的事:

Server1(eth0/10.81.1.2)- (eth0/10.66.2.3)Server2(eth1/WAN )-广域网

注: Server1和Server2的内部网络可以连接。

我尝试在Server1上设置这些:

代码语言:javascript
复制
iptables -t nat -A PREROUTING -p udp --dport 4500 -j DNAT --to-destination 10.66.2.3
iptables -t nat -A PREROUTING -p udp --dport 500 -j DNAT --to-destination 10.66.2.3
iptables -t nat -A PREROUTING -p udp --dport 1701 -j DNAT --to-destination 10.66.2.3
iptables -t nat -A POSTROUTING -p udp -d 10.66.2.3 --dport 4500 -j SNAT --to-source 10.81.1.2
iptables -t nat -A POSTROUTING -p udp -d 10.66.2.3 --dport 500 -j SNAT --to-source 10.81.1.2
iptables -t nat -A POSTROUTING -p udp -d 10.66.2.3 --dport 1701 -j SNAT --to-source 10.81.1.2
iptables -A FORWARD -p esp -j ACCEPT
iptables -A FORWARD -p ah -j ACCEPT

但是现在我不能使用Server1 1‘S广域网IP连接到广域网计算机上的Server2 (IPsec VPN可以通过广域网直接连接到广域网计算机上的Server2 )。

我可能被误认为是某些部分,我如何设置使用Server1连接到Server2来访问广域网?

EN

回答 2

Server Fault用户

发布于 2019-10-03 13:02:58

我建议你这么做

eth0是您的“公共接口”

代码语言:javascript
复制
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

主动路由

代码语言:javascript
复制
/bin/echo 1 >  /proc/sys/net/ipv4/ip_forward

将nat设置为将请求重定向到内部ipsec服务器

代码语言:javascript
复制
/sbin/iptables -t nat -A PREROUTING -i eth0 -p utp --dport 1701 -j DNAT --to-destination 10.66.2.3:1701
/sbin/iptables -t nat -A PREROUTING -i eth0 -p utp --dport 500 -j DNAT --to-destination 10.66.2.3:500
/sbin/iptables -t nat -A PREROUTING -i eth0 -p utp --dport 4500 -j DNAT --to-destination 10.66.2.3:4500
票数 1
EN

Server Fault用户

发布于 2018-07-11 18:33:17

你的iptables设置看起来不错。您是否启用了server1上的ip转发?(默认情况下已禁用)

代码语言:javascript
复制
echo 1 > /proc/sys/net/ipv4/ip_forward
票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/918970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档