I'm using vpn but i want to have one user that could access network not through vpn but using my real ip address.

The problem is that all solutions i found by quick google'ing, for example this http://blog.sebastien.raveau.name/2009/04/per-process-routing.html require to have some manually configured route, mark traffic using iptables and then route it.

But how to make per process/user routing when i'm on wifi? I'cant have some preconfigured route because i may go somewhere and connect to another wifi network with different gateway. I really don't want to mess with terminal every time I connect to another network using gui. Writing a script that would parse route added by networkmanager and reconfigure routes also doesn't seems like right way to do it.

So what is the best way to have one user going trough specified interface (wlan0) independently of interface's route gateway settings, and all other users going to other interface( vpn's tun)?

1 Answer 1


Did it by using opposite idea - routed all except "direct" user to vpn instead instead of routing direct user to wlan interface. Because vpn network ips are static

for f in /proc/sys/net/ipv4/conf/*/rp_filter; do echo 0 > $f; done
echo 1 > /proc/sys/net/ipv4/route/flush

iptables -t mangle -A OUTPUT -m owner ! --uid-owner direct2net -j MARK --set-mark 42
iptables -t mangle -A OUTPUT -d (vpn ip) -j MARK --set-mark 0

iptables -t nat -A POSTROUTING -m mark --mark 42 -j SNAT --to-source (local ip in vpn's network)

ip rule add fwmark 42 table 42
ip route add default via (vpn network gateway) dev tun0 table 42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .