2

My router (192.168.1.1) connected to the internet via PPPoE. Server (192.168.1.20) has OpenVPN client installed and all other computers get 192.168.1.20 from DHCP as default gateway. My IP-phone doesn't need VPN, that's why I've set it's default gateway to 192.168.1.1 manually. That works perfect.
Can I do something similar with the server to make transmission installed on it to download torrents thru 192.168.1.1? 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 192.168.1.1 instead of using VPN connection? Thanks in advance!

2

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

route del -net 0.0.0.0 netmask 128.0.0.0 dev tun0

I'm just deleting default gateway route created by openvpn client. So all traffic from the maschine goes to 192.168.1.1 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
1

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 0.0.0.0/0 table 11 dev whatever_dev_here

Replace whatever_dev_here with the device name for your local connection.

  • Thank you for the answer! I've done this, but for some reason the specified user have no internet connection at all.. 192.168.1.1 is reachable, but outer addresses are not. PING www.ru (217.112.35.75) 56(84) bytes of data. From 10.107.1.6 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.