大网数据广告活动
服务器运维问答

NATting through different gateway than default gateway?

· 52CE 我爱测

I have a bit of a tricky setup on my Synology NAS: There is a VPN tunnel up and running which also acts as default gateway (tun0, GW: 10.129.15.229). This is intended and should stay like this so that everything that is initiated…

问题原文

原帖链接 · Tobias · CC BY-SA 3.0

I have a bit of a tricky setup on my Synology NAS:

  1. There is a VPN tunnel up and running which also acts as default gateway (tun0, GW: 10.129.15.229). This is intended and should stay like this so that everything that is initiated on the NAS is going through the VPN.

  2. I now want to use NAT on my local network (initiated by other computers in the private net 192.168.2.0/24, using the local gateway 192.168.2.1).

Just switching on NAT using iptables rules like this modprobe iptable_nat iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -j SNAT --to-source 192.168.2.20

Seems to interfere with the default GW named in 1 (nothing happens/does not work).

Any ideas how I can set this up? Can I mark the packages with iptables somehow and then set up a route to 192.168.2.1 explicitly for those marked packages?

Many thanks!

已采纳解答

原帖链接 · Tobias · CC BY-SA 3.0

It worked out like that:

iptables --append FORWARD --in-interface eth1 -j ACCEPT
iptables --append FORWARD --in-interface eth0 -j ACCEPT
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --table nat --append POSTROUTING --out-interface tun0 -j MASQUERADE

echo 10 vpn >> /etc/iproute2/rt_tables
ip rule add from 192.168.2.0/24 lookup vpn
ip route add default via 192.168.2.1 table vpn

192.168.2.1 is the local gateway I want to route through, 192.168.2.X my local net.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-07-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。