我想通过另一个VPN-Node路由所有流量,同时:
我的客户节点配置:
# 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)保持完整。
唯一的问题是,客户端将不再接受连接。我读过一些关于fwmark和sourced based policy rules的文章,但我没有明白我真正需要的是什么,以及需要输入哪些命令。
发布于 2022-05-06 18:04:00
要做到这一点:
这种方式不需要fwmark或任何附加的防火墙规则。
这是我的工作配置脚本。我试着尽可能多地评论。
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 customhttps://serverfault.com/questions/1100244
复制相似问题