1

I have a 4G router with a OpenVPN connection to a VPS.

When I send all the Internet traffic through the VPS, the throughput speed is too low to be usable, but when I do not route anything through the VPN, my ISP limits the number of DNS requests. So I would like to pass only the port 53 by the VPN and the rest of the traffic by the 4G connection directly.

I think there might be a way to do this using IPTABLES but I can't find it... Any help would be appreciated, thanks !

1 Answer 1

0

"Plain normal" routing is done via destination address. You could decide to use only google DNS:

  • IPv4 : 8.8.8.8, 8.8.4.4
  • IPv6 : 2001:4860:4860::8888, 2001:4860:4860::8844

And then for example issue the following commands for ipv4:

ip route add 8.8.8.8/32 via 172.16.1.1 dev tun0
ip route add 8.8.4.4/32 via 172.16.1.1 dev tun0

Regardless of the destination port, network traffic to 8.8.8.8 and 8.8.4.4 will be sent via your VPN, assuming 172.16.1.1 is your tunnel gateway, and tun0 your tunnel device.

Please note that issuing route commands for ipv6 is a little trickier, but you may not need that.

Alternatively, it's possible to use policy routing (ip rule add) to route based of firewall marks (fwmark in iptables). But this is a bit more complex to setup, and this may cause a workload overhead to your router.

4
  • Thanks for the help. I added the route like you suggested but now I don't have name resolution. When I traceroute to 8.8.8.8 from the client I get traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 38 byte packets 1 172.27.224.1 75.842 ms 2 * 3 * 4 * 5 * 172.27.224.1 being the VPN server address. I tried adding the same kind of route on the server but the result is the same... Any idea ? Thanks
    – Julien L.
    Mar 7, 2018 at 10:13
  • Nevermind... I added this line in my OpenVPN server config file route 8.8.8.8 255.255.255.255 and it works like a charm. Many thanks !
    – Julien L.
    Mar 7, 2018 at 11:15
  • Your welcome. Don't forget to vote up :) Mar 7, 2018 at 12:06
  • Can't, I don't have enough reputation points :(
    – Julien L.
    Mar 9, 2018 at 7:40

You must log in to answer this question.

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