首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在接收传入的广域网连接时,通过VPN节点路由所有流量

在接收传入的广域网连接时,通过VPN节点路由所有流量
EN

Server Fault用户
提问于 2022-05-05 13:40:24
回答 1查看 237关注 0票数 0

我想通过另一个VPN-Node路由所有流量,同时:

  • 保持与VPN-服务器活动的连接(已经工作)
  • 还在接受那个客户端的广域网连接。

我的客户节点配置:

代码语言:javascript
复制
# 35.1.1.1: WAN IP of VPN-Server
# 192.168.8.1: WAN Gateway of Client
# 10.25.0.1: Internal VPN Server IP (not used below)
# 10.25.0.3: VPN Gatway for the Client (The gatway itself is also an Client)

ip route add 35.1.1.1/32 via 192.168.8.1   # protect route to VPN-Server
ip route del default via 192.168.8.1       # remove original default route
ip route add default via 10.25.0.3         # redirect to another VPN Node

当运行这些命令时,网关工作--来自客户端节点的每个流量都通过VPN网关(10.25.0.3)路由,同时保持到服务器的连接(35.1.1.1/10.25.0.1)保持完整。

唯一的问题是,客户端将不再接受连接。我读过一些关于fwmarksourced based policy rules的文章,但我没有明白我真正需要的是什么,以及需要输入哪些命令。

EN

回答 1

Server Fault用户

回答已采纳

发布于 2022-05-06 18:04:00

要做到这一点:

  • 禁用反向路径滤波
  • 将VPN网关添加为0.0.0.0/1128.0.0.0/1的对子,而不是简单的0.0.0.0/0。见这里
  • 添加自定义路由表。见这里

这种方式不需要fwmark或任何附加的防火墙规则。

这是我的工作配置脚本。我试着尽可能多地评论。

代码语言:javascript
复制
INTERFACE=tun0 # the VPN interface
#REMOTEADDRESS=35.1.1.1 # Real IP of VPN server
REMOTEADDRESS=`dig +short ` # Enter the hostname of the VPN srever or replace the expression via IP, see above

VPN_GATEWAY=10.25.0.3
#ORIGINAL_GATEWAY="via 192.168.8.1 dev eth0"
ORIGINAL_GATEWAY=`ip route show | grep ^default | cut -d ' ' -f 2-5`
ORIGINAL_NAMESERVER=`cat /etc/resolv.conf | grep ^nameserver | cut -d ' ' -f 2`

# Disable Reverse Path filtering
echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter # ETH device
echo 0 > /proc/sys/net/ipv4/conf/tun0/rp_filter # VPN device

ip route add $REMOTEADDRESS $ORIGINAL_GATEWAY # protect route to VPN-Server
ip route add $ORIGINAL_NAMESERVER $ORIGINAL_GATEWAY # OPTIONAL: protect route to DNS. Required for Google Cloud.
ip route add $VPN_GATEWAY dev $INTERFACE
ip route add 0.0.0.0/1 via $VPN_GATEWAY dev $INTERFACE
ip route add 128.0.0.0/1 via $VPN_GATEWAY dev $INTERFACE

# Add custom routing table
echo 200 custom >> /etc/iproute2/rt_tables
ip rule add from 192.168.8.100 table custom prio 1 # Real Client IP
ip route del default via 192.168.8.1 # Real Gateway
ip route add default via 192.168.8.1 dev eth0 table custom
票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1100244

复制
相关文章

相似问题

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