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

Configuring a route table to route only one (or range of ip) via a VPN connection

· 52CE 我爱测

This is my home network configuration: Devices/Pc/Smartphone ---> DD-WRT Router ---> Internet Router ---> Internet/World DD WRT router ip: 192.168.1.1 (default gw is 192.168.1.254) Internet Router ip: 192.168.1.254 Devices ip goi…

问题原文

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

This is my home network configuration:

Devices/Pc/Smartphone ---> DD-WRT Router ---> Internet Router ---> Internet/World

  • DD WRT router ip: 192.168.1.1 (default gw is 192.168.1.254)

  • Internet Router ip: 192.168.1.254

  • Devices ip going from 192.168.1.2 to 192.168.1.253

I would like to configure the DD WRT flashed router with a PPTP VPN client running. The PPTP VPN virtual device is called ppp0.

then :

  • All ip ranging from 192.168.1.40 to 192.168.1.50 pass through Vpn (so, pass through ppp0 inteface and ppp0 gateway)
  • All others ip uses default lan gateway (so, not uses vpn)

When i start VPN client on DD WRT, my route table is

0.0.0.0 via 192.168.1.254 dev eth0 
default via 192.168.120.10 dev ppp0  scope link 
8.8.8.8 via 192.168.1.254 dev eth0 
62.101.93.101 via 192.168.1.254 dev eth0 
127.0.0.0/8 dev lo  scope link 
169.254.0.0/16 dev br0  proto kernel  scope link  src 169.254.255.1 
192.168.1.0/24 dev br0  proto kernel  scope link  src 192.168.1.1 
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.132 
192.168.1.254 via 192.168.1.254 dev eth0 
192.168.120.10 dev ppp0  scope link 

Now, i think i've to replace

  • default via 192.168.120.10 dev ppp0

with

  • default via 192.168.1.254 dev eth0

so ALL ip go through standard internet gateway (no PPTP vpn)... then add a rule like

  • 192.168.1.40 via 192.168.120.10 dev ppp0

to allow ONLY ip 192.168.1.40 to exit using PPTP.

But..it isn't working!

So my final question is:

  • How to configure my router route all IP through default internet gateway (192.168.1.254) AND only One Ip (or a range of ip) to exit using pptp vpn connection ?

Thanks a lot!

已采纳解答

原帖链接 · Olivier S · CC BY-SA 3.0

A network route does not take into account the source ip address, only the destination ip address. This is like saying "if someone wants to go to network 1.2.3.4, use the 192.168.1.xx as the gateway".

What you want to do is saying: " Traffic coming from this ip address goes to internet via this specific gateway ".

This is slightly more complicated. The standard solution for this in Linux is to use the features of the iproute2 package.

  1. Create a new default route on an alternative table ip route add table 55 default via 192.168.20.10 dev ppp0
  2. Mark traffic you want to route iptables -t mangle -I PREROUTING 1 -s 192.168.1.40 -j MARK --set-mark 55
  3. Create a rule so that traffic marked as 55 is routed via table 55 ip rule add fwmark 55 table 55

At this point if you run a tcpdump on interface ppp0 and send some traffic from your 192.168.1.40 device you should see some traffic.

Now you will probably have 2 problems:

  1. NAT : it is likely that you have to add a nat rule so that traffic going out via the ppp0 interface is natted with the interface ip address
  2. fragmentation : your ppp0 interface has probably a MTU which is smaller than the mtu of your eth0 interface, so you have to install a TCPMSS rule to clamp the traffic to something between 1300 and 1400

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

资料来源与适用范围

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

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

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