Redirect from wan to lan only works for router ip

hello, I want to expose my nas service (192.168.1.8:8080) to wan (8080), then I've config following redirect rule in firewall

config redirect
        option name 'nas-service'
        option target 'DNAT'
        option dest 'lan'
        list proto 'tcp'
        option dest_port '8080'
        option src_dport '8080'
        option src 'wan'
        option dest_ip '192.168.1.8'    <------- my nas ip

after restart firewall, I tried to test it worked from outside openwrt network (say, from my phone by cell data)

wget mypublicip:8080

it seems tcp connection established but hang, and finally failed. (I've confirmed I can access nas service from within lan by 192.168.1.8:8080)

but if I changed my redirect rule to forward port of openwrt itself (router ip 192.168.1.1), every port worked

config redirect
        option name 'nas-service'
        option target 'DNAT'
        option dest 'lan'
        list proto 'tcp'
        option dest_port '8080'
        option src_dport '80'    <-----------expose openwrt web/ or 22 for ssh, all worked
        option src 'wan'
        option dest_ip '192.168.1.1'    <------- my router (openwrt) ip

could anyone help me ?
BTW, I have multi-wan and multi-lan subnet configured, does it leads problem here?

Are you certain that the return traffic is sent out of the same wan?
The redirect you have there is correct. Make sure also that the NAS uses the OpenWrt as gateway and doesn't block connections from other subnets.

1 Like

could you please explain it in more detail ? should I view iptables to confirm some sort of rules existed?

and I can confirm my nas (192.168.1.8) use openwrt (192.168.1.1) as gateway since I ran tracert from within my nas terminal shows that all traffic goes through openwrt.

I can use wget to access 192.168.1.8:8080 from openwrt terminal , doesn't the redirect connection to nas looks exactly as traffic goes from openwrt terminal ? I mean , if wget from openwrt worked, redirect rule should also work, but what makes the differences?

If you have multi-wan as you said in the first post, there is a chance that the policy for the nas is to send packets via wanA, while you are trying to access it from wanB.
How did you configure the multiwan policies?

No and no, they are different cases.

1 Like

I have
wan(pppoe1) + lan(br-lan) running as subnet 192.168.1.0/24
wan2(pppoe2) + lan2(br-lan2) running as subnet 192.168.20.0/24

and my nas connected as 192.168.1.8, I tried to access redirect port by wan(pppoe1) public ip.
BTW, I don't understand why 'wan interface' and 'wan zone ' both existed, I configure wan and wan2 in one 'wan zone'

Segregating this traffic requires policy based routing. This is achieved with mwan3, vpn-policy-routing, or rules-routes. Which one did you use?

1 Like

vpn-policy-routing, using wan(pppoe)+lan(br-lan) 192.168.1.0/24 as default gateway

Copy this into a script, fix the pppoe interface names, make it executable and run it:

#!/bin/sh
interfaces="pppoe-wan pppoe-wan2"
# When this exits, exit all background processes:
trap 'kill $(jobs -p) &> /dev/null && sleep 0.2 &&  echo ' EXIT

# Create one tcpdump output per interface and add an identifier to the beginning of each line:
for interface in $interfaces;
do tcpdump -l -i $interface $@ | sed 's/^/[Interface:'"$interface"'] /' 2>/dev/null & done;
# wait .. until CTRL+C
wait

Run it with ./filename.sh tcp port 80 or tcp port 8080 , try to access port 80 from the internet, gather the output and paste it here.

1 Like

running this script got following output (I'm using 10443 instead of 8080, already confirmed I can access 192.168.1.8:10443 within lan or from openwrt. pppoe-wan is my default wan, only it has public ip. I'm accessing this ip during test from outside openwrt by browser. pppoe-wan_chmob is my second wan , it didn't have public ip)

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on pppoe-wan, link-type LINUX_SLL (Linux cooked v1), capture size 262144 bytes
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on pppoe-wan_chmob, link-type LINUX_SLL (Linux cooked v1), capture size 262144 bytes
[Interface:pppoe-wan] 09:23:29.090173 IP 114.225.184.65.60007 > 58.214.145.175.10443: Flags [S], seq 1913519929, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:29.090464 IP 114.225.184.65.54908 > 58.214.145.175.10443: Flags [S], seq 943915569, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:29.348090 IP 114.225.184.65.54569 > 58.214.145.175.10443: Flags [S], seq 681083222, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:30.095844 IP 114.225.184.65.60007 > 58.214.145.175.10443: Flags [S], seq 1913519929, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:30.096008 IP 114.225.184.65.54908 > 58.214.145.175.10443: Flags [S], seq 943915569, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:30.356059 IP 114.225.184.65.54569 > 58.214.145.175.10443: Flags [S], seq 681083222, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:32.096843 IP 114.225.184.65.60007 > 58.214.145.175.10443: Flags [S], seq 1913519929, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:32.096949 IP 114.225.184.65.54908 > 58.214.145.175.10443: Flags [S], seq 943915569, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:32.355653 IP 114.225.184.65.54569 > 58.214.145.175.10443: Flags [S], seq 681083222, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:36.108754 IP 114.225.184.65.60007 > 58.214.145.175.10443: Flags [S], seq 1913519929, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:36.108915 IP 114.225.184.65.54908 > 58.214.145.175.10443: Flags [S], seq 943915569, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:36.369869 IP 114.225.184.65.54569 > 58.214.145.175.10443: Flags [S], seq 681083222, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:44.109914 IP 114.225.184.65.60007 > 58.214.145.175.10443: Flags [S], seq 1913519929, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:44.110067 IP 114.225.184.65.54908 > 58.214.145.175.10443: Flags [S], seq 943915569, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:23:44.375366 IP 114.225.184.65.54569 > 58.214.145.175.10443: Flags [S], seq 681083222, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:05.349768 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.58382 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 521428826, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:05.349947 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.58382: Flags [R.], seq 0, ack 521428827, win 0, length 0
[Interface:pppoe-wan] 09:24:05.352247 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61776 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 3683678926, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:05.352384 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61776: Flags [R.], seq 0, ack 3683678927, win 0, length 0
[Interface:pppoe-wan] 09:24:05.616923 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.55407 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 2599217243, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:05.617091 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.55407: Flags [R.], seq 0, ack 2599217244, win 0, length 0
[Interface:pppoe-wan] 09:24:06.663297 IP 114.225.184.65.50747 > 58.214.145.175.10443: Flags [S], seq 299534510, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:07.663032 IP 114.225.184.65.50747 > 58.214.145.175.10443: Flags [S], seq 299534510, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:09.665750 IP 114.225.184.65.50747 > 58.214.145.175.10443: Flags [S], seq 299534510, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:12.190313 IP 114.225.184.65.63500 > 58.214.145.175.10443: Flags [S], seq 1347623061, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:13.189316 IP 114.225.184.65.63500 > 58.214.145.175.10443: Flags [S], seq 1347623061, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:13.674519 IP 114.225.184.65.50747 > 58.214.145.175.10443: Flags [S], seq 299534510, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:15.203738 IP 114.225.184.65.63500 > 58.214.145.175.10443: Flags [S], seq 1347623061, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:19.214136 IP 114.225.184.65.63500 > 58.214.145.175.10443: Flags [S], seq 1347623061, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:21.689852 IP 114.225.184.65.50747 > 58.214.145.175.10443: Flags [S], seq 299534510, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:27.218247 IP 114.225.184.65.63500 > 58.214.145.175.10443: Flags [S], seq 1347623061, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:27.897056 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61074 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 1194165018, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:27.897238 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61074: Flags [R.], seq 0, ack 1194165019, win 0, length 0
[Interface:pppoe-wan] 09:24:28.812265 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61074 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 1194165018, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:28.812441 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61074: Flags [R.], seq 0, ack 1, win 0, length 0
[Interface:pppoe-wan] 09:24:29.730862 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61074 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 1194165018, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:29.731037 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61074: Flags [R.], seq 0, ack 1, win 0, length 0
[Interface:pppoe-wan] 09:24:30.658223 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61074 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 1194165018, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:30.658406 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61074: Flags [R.], seq 0, ack 1, win 0, length 0
[Interface:pppoe-wan] 09:24:31.585788 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61074 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 1194165018, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:31.585965 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.61074: Flags [R.], seq 0, ack 1, win 0, length 0
[Interface:pppoe-wan] 09:24:33.431500 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.55907 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 3314568657, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:33.431676 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.55907: Flags [R.], seq 0, ack 3314568658, win 0, length 0
[Interface:pppoe-wan] 09:24:34.348020 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.55907 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 3314568657, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:34.348192 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.55907: Flags [R.], seq 0, ack 1, win 0, length 0
[Interface:pppoe-wan] 09:24:35.263103 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.55907 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 3314568657, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:35.263285 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.55907: Flags [R.], seq 0, ack 1, win 0, length 0
[Interface:pppoe-wan] 09:24:36.182683 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.55907 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 3314568657, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0
[Interface:pppoe-wan] 09:24:36.182853 IP6 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443 > 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.55907: Flags [R.], seq 0, ack 1, win 0, length 0
[Interface:pppoe-wan] 09:24:37.112008 IP6 2002:72e1:b841:e472:b5e3:6a6a:f0b4:9691.55907 > 240e:3a0:1615:678a:d0cc:3dde:e8d8:5692.10443: Flags [S], seq 3314568657, win 64800, options [mss 1440,nop,wscale 8,nop,nop,sackOK], length 0

Is it not a problem of loopback option of the redirect rule ?

I'm not sure, Could you please explain it further ? what commands should I use to confirm this?

My rule is defined like this :


There are only sync packets, but nothing in return.
Run a tcpdump -i br-lan tcp port 8080 to verify that the OpenWrt is forwarding the packets to the nas and gets the replies.

1 Like

it given following output:

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on br-lan, link-type EN10MB (Ethernet), capture size 262144 bytes
20:48:12.593300 IP 114.225.184.65.62551 > 192.168.1.8.10443: Flags [S], seq 1242769638, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:12.594692 IP 114.225.184.65.51196 > 192.168.1.8.10443: Flags [S], seq 4160423300, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:12.821332 IP 114.225.184.65.64021 > 192.168.1.8.10443: Flags [S], seq 2891784188, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:13.594437 IP 114.225.184.65.51196 > 192.168.1.8.10443: Flags [S], seq 4160423300, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:13.594600 IP 114.225.184.65.62551 > 192.168.1.8.10443: Flags [S], seq 1242769638, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:13.824618 IP 114.225.184.65.64021 > 192.168.1.8.10443: Flags [S], seq 2891784188, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:15.600664 IP 114.225.184.65.62551 > 192.168.1.8.10443: Flags [S], seq 1242769638, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:15.600810 IP 114.225.184.65.51196 > 192.168.1.8.10443: Flags [S], seq 4160423300, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:15.830971 IP 114.225.184.65.64021 > 192.168.1.8.10443: Flags [S], seq 2891784188, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:19.602037 IP 114.225.184.65.62551 > 192.168.1.8.10443: Flags [S], seq 1242769638, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:19.602193 IP 114.225.184.65.51196 > 192.168.1.8.10443: Flags [S], seq 4160423300, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:19.839724 IP 114.225.184.65.64021 > 192.168.1.8.10443: Flags [S], seq 2891784188, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:27.613612 IP 114.225.184.65.51196 > 192.168.1.8.10443: Flags [S], seq 4160423300, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:27.613763 IP 114.225.184.65.62551 > 192.168.1.8.10443: Flags [S], seq 1242769638, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0
20:48:27.843031 IP 114.225.184.65.64021 > 192.168.1.8.10443: Flags [S], seq 2891784188, win 64240, options [mss 1452,nop,wscale 8,nop,nop,sackOK], length 0

Enable NAT Loopback options looks same as my config.

Again the server is not responding. Make sure that there is no firewall on the server blocking the incoming requests. This is not an OpenWrt problem.

I’ve ran ssh from my nas to openwrt with -L 0.0.0.0:10443:192.168.1.8:10443 to expose nas 10443 port ,and allow 10443 input traffic in openwrt ,by this way ,I can access my nas port from internet ,does that mean my nas didn’t block traffic?

I think that when you do that ssh-fu, the source IP is the one of OpenWrt, so it is like connecting from the lan.

2 Likes

You’re correct,my nas do have firewall rules which block non-lan traffic ,change it fix the problem .and this is my first time to know ssh traffic src ip is from ssh peer, Thanks for the detail help!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.