What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Port based selective routing

canufrank

Occasional Visitor
I have a machine behind my router that is routed through the VPN tunnel. I would like certain traffic to use the WAN, but am failing to implement the solutions I've seen outlined in various threads. As a precursor, some threads utilize --dports while others use --sports in their listing.

In its simplest form, my script looks like
Code:
TAGMARK=16;   MYNAS=192.168.0.46;   PORTDIR=sports

ip rule add from $MYNAS  fwmark $TAGMARK table main prio 999
iptables -t mangle -I PREROUTING -i br0 -s $MYNAS -p tcp -m multiport --$PORTDIR 80,443 -j MARK --set-mark $TAGMARK

However, if I run { curl checkip.dyndns.com; } on MYNAS, I get the external (public) IP of the VPN tunnel.
Code:
curl checkip.dyndns.com
<html><head><title>Current IP Check</title></head><body>Current IP Address: 172.98.67.46</body></html>

So, trash that rule, add with --dports and flush cache. Now curl times out on MYNAS:
Code:
curl checkip.dyndns.com
curl: (7) Failed to connect to checkip.dyndns.com port 80: Connection timed out

So, I think that's telling me that dports is the correct syntax. It also tells me that I'm missing something. By default the 2nd rule in filter/FORWARD is
Code:
iptables -L FORWARD 2 -vn
Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target  prot opt in    out  source     destination
11187 3840K ACCEPT  all  --  *     *    0.0.0.0/0  0.0.0.0/0  state RELATED,ESTABLISHED
    0    0  ACCEPT  all  --  tun11 *    0.0.0.0/0  0.0.0.0/0
(The INPUT chain has the same rule in position 1.) So, I don't know where this traffic is being stopped.
 
Last edited:

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top