3

So, I want to route certain traffic via a VPN connection and the rest via my normal Internet connection. I want to run several different programs and most of them don't support binding to a specific network interface (tun0 in my case).

I've managed to send a specific user's traffic via the VPN following the answers given here: iptables - Target to route packet to specific interface?

But unfortunately, when I run a server that connects to the Internet and has a web interface running on a local IP (127.0.0.1/192.168.0.*), all the Internet traffic correctly goes via tun0, but I'm unable to connect to the web interface from a local IP as a different user.

When I log in as the VPN-ified user, I can access services running on local IPs, but other users/machines can't access any servers I start.

Can anyone point me in the right direction?

1

first add a firewall rules:

iptables -t mangle -A OUTPUT -m owner --uid USER -j MARK --set-mark 1
iptables -t nat -A POSTROUTING -m mark --mark 1 -j MASQUERADE

then add a routing rule:

ip rule add fwmark 0x1 table 100

and then add routes to your new routing table:

ip route add SOMEROUTE via SOMEGATEWAY table 100
| improve this answer | |
0

You have to set up a static route for the network that is on the other side of the VPN. Usually everything gets routed over the default route unless you specify an explicit route.

Say for example the network behind the VPN would be 10.10.42.0/24 then you add an static route with

ip route add 10.10.42.0/24 dev tun0

This sends all the traffic for this subnet over tun0

| improve this answer | |
  • 1
    Thanks, but I don't think that's the problem: all connections initiated by the user account tied to the VPN work perfectly. Internet works, LAN servers are accessible. What I can't do is start a server as that user and access the server as another user/from the LAN. – wbg Jul 4 '13 at 20:31

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.