I have the following setup:
+-----------+      +---------+      +----------+
|WORKSTATION|------|  LINUX  |------| GATEWAY  |
+-----------+      +---------+      +----------+
                   |   VPN   |

WORKSTATION has a default route of LINUX has a default route of

I am trying to use the gateway as the default route, but route port 80 traffic via the VPN. Based on what I read at http://www.linuxhorizon.ro/iproute2.html I have tried this:

echo "1 VPN" >> /etc/iproute2/rt_tables
sysctl net.ipv4.conf.eth0.rp_filter = 0
sysctl net.ipv4.conf.tun0.rp_filter = 0
sysctl net.ipv4.conf.all.rp_filter = 0

iptables -A PREROUTING -t mangle -i eth0 -p tcp --dport 80 -j MARK --set-mark 0x1
ip route add default via dev tun0 table VPN
ip rule add from all fwmark 0x1 table VPN

When I run "tcpdump -i eth0 port 80" on LINUX, and open a webpage on WORKSTATION, I don't see the traffic go through LINUX at all. When I run a ping from WORKSTATION, I get this back from some packets:

92 bytes from Redirect Host(New addr:
Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst
 4  5  00 0054 de91   0 0000  3f  01 4ed3

Is this why my routing is not working ? Do I need to put GATEWAY and LINUX on different subnets to prevent WORKSTATION being redirected to GATEWAY ? Do I need to use NAT at all, or can I do this with routing alone (which is what I want) ?

2 Answers 2


"LINUX" is telling "WORKSTATION" to use "GATEWAY" instead of itself because they appear to be on the same subnet. This can only work if you've set up bridging on "LINUX" (see brctl(8)), and if you did then "WORKSTATION" should use "GATEWAY" in its default route.

Make sure you use a subnet per broadcast domain, broadcast packets are never routed so you need a different subnet on all 3 interfaces of "LINUX" (you could use /30s but I recommend sticking to /24s for growth). or have it bridge them. You should probably also configure a separate subnet for the VPN itself.

Next, add the VPN subnet to the VPN table, e.g.:

ip route add dev tun0 scope link table VPN proto static

In order to use this table, add a routing rule like so:

ip rule add fwmark 1 lookup VPN priority 500

And see if you can route packets via both "VPN" and "GATEWAY" before you add any fwmark rules, just in case.

And I don't think disabling the reverse path filter is beneficial.


I see this question is pretty old, but thought I would add a quick note in case it helps someone with the same problem. While it is probably best to separate the devices in to different network segments as Henk recommends, if that is not possible there is a workaround.

The Redirect that is happening where Linux ( tells the workstation ( to use the gateway ( can be disabled by making the following change to your /etc/sysctl.conf file on the Linux server:

net.ipv4.conf.all.send_redirects = 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.