My router ( connected to the internet via PPPoE. Server ( has OpenVPN client installed and all other computers get from DHCP as default gateway. My IP-phone doesn't need VPN, that's why I've set it's default gateway to manually. That works perfect.
Can I do something similar with the server to make transmission installed on it to download torrents thru I'm unfamiliar with iptables (i've just copy-pasted rules to configure NAT on the server to share VPN connection).
To make it simpler: how can I add iptables rule for forwarding all non-transit packets from server to instead of using VPN connection? Thanks in advance!


I've spent few hours and at last found the solution. Not so nite as adviced before, but still working.

route del -net netmask dev tun0

I'm just deleting default gateway route created by openvpn client. So all traffic from the maschine goes to exactly as I needed.
But dew to NAT masquerade other devices in my network remains beyond the VPN.
I've added this string to /etc/rc.local

iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
| improve this answer | |

A simple way to do this is to use a separate user to run the torrent client, then using iptables simply tag the packets and route them appropriately.

iptables -t mangle -A OUTPUT -m owner --uid-owner custom_user -j MARK --set-mark 11

Once you have done that, then you need to route packets with that mark along your non-tunneled gateway:

ip rule add fwmark 11 table 11
ip route add table 11 dev whatever_dev_here

Replace whatever_dev_here with the device name for your local connection.

| improve this answer | |
  • Thank you for the answer! I've done this, but for some reason the specified user have no internet connection at all.. is reachable, but outer addresses are not. PING www.ru ( 56(84) bytes of data. From icmp_seq=1 Destination Host Unreachable – silentfobos Aug 1 '16 at 7:17

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.