How to enable NAT loopback on R7000 v3.0-r47381

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Goto page Previous  1, 2
Author Message
Alozaros
DD-WRT Guru


Joined: 16 Nov 2015
Posts: 6435
Location: UK, London, just across the river..

PostPosted: Mon Sep 20, 2021 7:44    Post subject: Reply with quote
eibgrad wrote:
gavsiu wrote:
Code:
root@Router-Gateway:~# iptables -t mangle -A PREROUTING -i ! vlan2 -d $(nvram get wan_ipaddr) -j MARK --set-mark 0x80000000/0x80000000
Bad argument `vlan2'
Try `iptables -h' or 'iptables --help' for more information.


FYI. iptables no longer accepts placing the negation (!) after the option and before the argument. It must now be before the option.

Code:
root@Router-Gateway:~# iptables -t mangle -A PREROUTING ! -i vlan2 -d $(nvram get wan_ipaddr) -j MARK --set-mark 0x80000000/0x80000000


Note, I'm NOT commenting on the efficacy of the rule. Just pointing out the syntax error.


im sorry to high-jack the thread, but just wonder how this rule will be spelled correctly:

iptables -t mangle -I PREROUTING -p tcp -m conntrack --ctstate NEW -m tcpmss ! --mss 536:65535 -j DROP

is it going to be
iptables -t mangle -I PREROUTING -p tcp -m conntrack --ctstate NEW ! -m tcpmss --mss 536:65535 -j DROP

_________________
Atheros
TP-Link WR740Nv1 ---DD-WRT 55630 WAP
TP-Link WR1043NDv2 -DD-WRT 55723 Gateway/DoT,Forced DNS,Ad-Block,Firewall,x4VLAN,VPN
TP-Link WR1043NDv2 -Gargoyle OS 1.15.x AP,DNS,QoS,Quotas
Qualcomm-Atheros
Netgear XR500 --DD-WRT 55779 Gateway/DoH,Forced DNS,AP Isolation,4VLAN,Ad-Block,Firewall,Vanilla
Netgear R7800 --DD-WRT 55779 Gateway/DoT,AD-Block,Forced DNS,AP&Net Isolation,x3VLAN,Firewall,Vanilla
Netgear R9000 --DD-WRT 55779 Gateway/DoT,AD-Block,AP Isolation,Firewall,Forced DNS,x2VLAN,Vanilla
Broadcom
Netgear R7000 --DD-WRT 55460 Gateway/SmartDNS/DoH,AD-Block,Firewall,Forced DNS,x3VLAN,VPN
NOT USING 5Ghz ANYWHERE
------------------------------------------------------
Stubby DNS over TLS I DNSCrypt v2 by mac913
Sponsor
eibgrad
DD-WRT Guru


Joined: 18 Sep 2010
Posts: 9157

PostPosted: Mon Sep 20, 2021 16:26    Post subject: Reply with quote
Alozaros wrote:
eibgrad wrote:
gavsiu wrote:
Code:
root@Router-Gateway:~# iptables -t mangle -A PREROUTING -i ! vlan2 -d $(nvram get wan_ipaddr) -j MARK --set-mark 0x80000000/0x80000000
Bad argument `vlan2'
Try `iptables -h' or 'iptables --help' for more information.


FYI. iptables no longer accepts placing the negation (!) after the option and before the argument. It must now be before the option.

Code:
root@Router-Gateway:~# iptables -t mangle -A PREROUTING ! -i vlan2 -d $(nvram get wan_ipaddr) -j MARK --set-mark 0x80000000/0x80000000


Note, I'm NOT commenting on the efficacy of the rule. Just pointing out the syntax error.


im sorry to high-jack the thread, but just wonder how this rule will be spelled correctly:

iptables -t mangle -I PREROUTING -p tcp -m conntrack --ctstate NEW -m tcpmss ! --mss 536:65535 -j DROP

is it going to be
iptables -t mangle -I PREROUTING -p tcp -m conntrack --ctstate NEW ! -m tcpmss --mss 536:65535 -j DROP


You don't want to negate the loading of the module (! -m tcpmss). You negate one or more of the options (e.g., ! --mss).

_________________
ddwrt-ovpn-split-basic.sh (UPDATED!) * ddwrt-ovpn-split-advanced.sh (UPDATED!) * ddwrt-ovpn-client-killswitch.sh * ddwrt-ovpn-client-watchdog.sh * ddwrt-ovpn-remote-access.sh * ddwrt-ovpn-client-backup.sh * ddwrt-mount-usb-drives.sh * ddwrt-blacklist-domains.sh * ddwrt-wol-port-forward.sh * ddwrt-dns-monitor.sh (NEW!)
eibgrad
DD-WRT Guru


Joined: 18 Sep 2010
Posts: 9157

PostPosted: Mon Sep 20, 2021 16:31    Post subject: Reply with quote
Btw, the last line in the OP's dump of the POSTROUTING chain of the nat table *is* the NAT loopback, and shows hits (29 in fact).

Code:
Chain POSTROUTING (policy ACCEPT 43 packets, 2159 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1     4905 1085K SNAT       all  --  *      vlan2   192.168.1.0/24       0.0.0.0/0            to:EXTERNAL.IP
2     4161  300K SNAT       all  --  *      vlan2   0.0.0.0/0            0.0.0.0/0            to:EXTERNAL.IP
3        0     0 RETURN     all  --  *      wl1.1   0.0.0.0/0            0.0.0.0/0            PKTTYPE = broadcast
4        0     0 MASQUERADE  all  --  *      wl1.1   0.0.0.0/0            0.0.0.0/0           
5        0     0 RETURN     all  --  *      br0     0.0.0.0/0            0.0.0.0/0            PKTTYPE = broadcast
6       29  6564 MASQUERADE  all  --  *      br0     192.168.1.0/24       192.168.1.0/24


All that NAT loopback does is force the replies from the target to be returned to the router (thanks to the MASQUERADE) rather than directly back to the client's LAN ip, thus given the router the opportunity to undo the DNAT that forced the reference of the external WAN ip over to the internal LAN ip of the target.

I have no idea why everyone is trying to configure NAT loopback alternatives. If it's not working, there must be some other issue, perhaps w/ that particular service being targeted.

_________________
ddwrt-ovpn-split-basic.sh (UPDATED!) * ddwrt-ovpn-split-advanced.sh (UPDATED!) * ddwrt-ovpn-client-killswitch.sh * ddwrt-ovpn-client-watchdog.sh * ddwrt-ovpn-remote-access.sh * ddwrt-ovpn-client-backup.sh * ddwrt-mount-usb-drives.sh * ddwrt-blacklist-domains.sh * ddwrt-wol-port-forward.sh * ddwrt-dns-monitor.sh (NEW!)


Last edited by eibgrad on Mon Oct 04, 2021 16:48; edited 1 time in total
gavsiu
DD-WRT Novice


Joined: 19 Jan 2014
Posts: 24

PostPosted: Mon Sep 20, 2021 18:07    Post subject: Reply with quote
Per Yngve Berg wrote:
Add the address=


That domain shall now resolve to the internal address.


Seems to be working this time. Then again, I'm on a newer build than initially.

Android app and Chromium on laptop works. For some reason Firefox won't connect.

Edit: Disabled DNS over HTTPS in Firefox and now it works.
joecoolio
DD-WRT Novice


Joined: 03 Aug 2020
Posts: 13

PostPosted: Mon Oct 04, 2021 16:09    Post subject: Reply with quote
eibgrad wrote:
I have no idea why everyone is trying to configure NAT loopback alternatives. If it's not working, there must be some other issue, perhaps w/ that particular service being targeted.


I'm on build 47495 on an Asus RT-AC3200 and I'm seeing the same thing as OP - nat loopback seems completely disabled even though the 'filter wan nat redirection' box is off.

Honestly, I'm pretty far outside of my networking ability so what do I need to do to track this down? I've got this which appears to be correct by your previous comment:

Code:
Chain POSTROUTING (policy ACCEPT 673 packets, 51290 bytes)
 pkts bytes target     prot opt in     out     source               destination
    1   659 MASQUERADE  all  --  any    tun1    anywhere             anywhere
  753 59802 SNAT       all  --  any    vlan2   10.10.10.0/24        anywhere             to:PUBLIC.IP
    0     0 RETURN     all  --  any    br0     anywhere             anywhere             PKTTYPE = broadcast
    5   276 MASQUERADE  all  --  any    br0     10.10.10.0/24        10.10.10.0/24
gavsiu
DD-WRT Novice


Joined: 19 Jan 2014
Posts: 24

PostPosted: Mon Oct 04, 2021 16:56    Post subject: Reply with quote
I'm on 47495 now and it still works. Use Dnsmasq, not iptables for this.
eibgrad
DD-WRT Guru


Joined: 18 Sep 2010
Posts: 9157

PostPosted: Mon Oct 04, 2021 17:04    Post subject: Reply with quote
joecoolio wrote:
5 276 MASQUERADE all -- any br0 10.10.10.0/24 10.10.10.0/24


The above line is NAT loopback. And it *is* working since it shows hits (5).

FYI, I explain how NAT loopback actually works in the following link (it's specifically regarding tomato, but conceptually it's the same for all third-party firmware).

https://www.linksysinfo.org/index.php?threads/redirect-outbound-wan-to-an-internal-ip-lan.73267/post-284824

I have no doubt you're having problems. But based strictly on that rule, and the fact its being hit, tells me it's NOT NAT loopback itself that's the problem. Maybe the targeted device's firewall is specifically rejecting the router's LAN ip (10.10.10.1) for some reason. NAT loopback *assumes* that's not likely to happen. Or perhaps 10.10.10.1 is being routed elsewhere on the target device.

_________________
ddwrt-ovpn-split-basic.sh (UPDATED!) * ddwrt-ovpn-split-advanced.sh (UPDATED!) * ddwrt-ovpn-client-killswitch.sh * ddwrt-ovpn-client-watchdog.sh * ddwrt-ovpn-remote-access.sh * ddwrt-ovpn-client-backup.sh * ddwrt-mount-usb-drives.sh * ddwrt-blacklist-domains.sh * ddwrt-wol-port-forward.sh * ddwrt-dns-monitor.sh (NEW!)
joecoolio
DD-WRT Novice


Joined: 03 Aug 2020
Posts: 13

PostPosted: Mon Oct 04, 2021 18:15    Post subject: Reply with quote
eibgrad wrote:

https://www.linksysinfo.org/index.php?threads/redirect-outbound-wan-to-an-internal-ip-lan.73267/post-284824

I have no doubt you're having problems. But based strictly on that rule, and the fact its being hit, tells me it's NOT NAT loopback itself that's the problem. Maybe the targeted device's firewall is specifically rejecting the router's LAN ip (10.10.10.1) for some reason. NAT loopback *assumes* that's not likely to happen. Or perhaps 10.10.10.1 is being routed elsewhere on the target device.


Thanks for that link, you taught me something new!

My problem is twofold: First, none of my exposed services are accessible from internal IPs if I use the domain name. For example I ssh to hostname:22, it works from outside but not inside. That I can fix with a dnsmasq 'address=' setup.

But my second problem is that plex is screwed up. I have a server @ 10.10.10.10:32400 and my client is 10.10.10.150. Even though I'm on the same network, I'm not able to directly connect to the plex server. I cannot put a hostname setting in to fix this because it appears that plex is using IPs.

Anyway, back to my problem, here are my DNAT/SNAT settings:

Chain PREROUTING (policy ACCEPT 21180 packets, 26M bytes)
pkts bytes target prot opt in out source destination
6 264 DNAT icmp -- any any anywhere EXTERNAL_IP to:10.10.10.1 (router)
12 676 DNAT tcp -- any any anywhere EXTERNAL_IP tcp dpt:ssh to:10.10.10.10:22
3 180 DNAT tcp -- any any anywhere EXTERNAL_IP tcp dpt:32400 to:10.10.10.10:32400
518 47816 TRIGGER all -- any any anywhere EXTERNAL_IP TRIGGER type:dnat match:0 relate:0

target prot opt in out source destination
753 59802 SNAT all -- any vlan2 10.10.10.0/24 anywhere to:EXTERNAL_IP
0 0 RETURN all -- any br0 anywhere anywhere PKTTYPE = broadcast
5 276 MASQUERADE all -- any br0 10.10.10.0/24 10.10.10.0/24


If I understand this correctly then that is all setup correctly. However, I cannot ssh from 10.10.10.150 --> 10.10.10.1 (router) but I can go directly to 10.10.10.10 (server).

Could it be that SFE is screwing this up? I've got it set to SFE = CTF and flow acceleration = CTF+FA. There's literally nothing else that I can find that might be the problem and like you said, there are hits to that rule even though it's not working correctly. I've read elsewhere that CTF can affect NAT though again that's beyond my skillset Smile
kernel-panic69
DD-WRT Guru


Joined: 08 May 2018
Posts: 14207
Location: Texas, USA

PostPosted: Mon Oct 04, 2021 18:24    Post subject: Reply with quote
There seems to be an issue with CTF and port forwarding, which could be affecting this. It is discussed in the forum somewhere...
_________________
"Life is but a fleeting moment, a vapor that vanishes quickly; All is vanity"
Contribute To DD-WRT
Pogo - A minimal level of ability is expected and needed...
DD-WRT Releases 2023 (PolitePol)
DD-WRT Releases 2023 (RSS Everything)

----------------------
Linux User #377467 counter.li.org / linuxcounter.net
joecoolio
DD-WRT Novice


Joined: 03 Aug 2020
Posts: 13

PostPosted: Mon Oct 04, 2021 19:20    Post subject: Reply with quote
I'm watching my pre- and post-routing rules to try to see exactly what's happening. When I try to access https://server-ip:32400, my DNAT rule and MASQ rule each increment but the SNAT doesn't. I get no response back, so something but be interfering with the SNAT side of things.

When I can handle a minute of downtime, I'm going to try various values values of SFE/flow acceleration and see if that's actually the cause.
joecoolio
DD-WRT Novice


Joined: 03 Aug 2020
Posts: 13

PostPosted: Wed Oct 06, 2021 2:07    Post subject: Reply with quote
I turned off CTF today and my port forwards/nat loopback started working without any other changes. Digging through the forums, I found that other folks have problems with port forwards even from the WAN side but mine only broke on the LAN. Very strange. I'll have to try all the other options and combinations to see if any of the accelerations work or not.
apacheguy
DD-WRT User


Joined: 26 Jun 2008
Posts: 88

PostPosted: Tue Nov 08, 2022 15:28    Post subject: Reply with quote
I got NAT loopback to work on Tomato, which also uses CTF, by using the below commands. However, these same commands don’t work on my dd-wrt setup.

Code:
 iptables -t mangle -I FORWARD -s 192.168.1.0/24 -d 192.168.2.0/24 -o br0 -j MARK --set-xmark 0x1/0x7
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -d 192.168.2.0/24 -o br0 -j SNAT --to-source 192.168.1.1
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1856
Location: Hung Hom, Hong Kong

PostPosted: Tue Nov 08, 2022 15:33    Post subject: Reply with quote
apacheguy wrote:
I got NAT loopback to work on Tomato, which also uses CTF, by using the below commands. However, these same commands don’t work on my dd-wrt setup.

Code:
 iptables -t mangle -I FORWARD -s 192.168.1.0/24 -d 192.168.2.0/24 -o br0 -j MARK --set-xmark 0x1/0x7
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -d 192.168.2.0/24 -o br0 -j SNAT --to-source 192.168.1.1

To make iptables work with bridged interfaces, I suspect you need to enable bridge interface support in iptables at DD-WRT compile time. In the meantime, you might consider using ebtables instead.

DD-WRT :: View topic - /proc/sys/net/bridge/bridge-nf-call-iptables
https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=333134

DD-WRT :: View topic - iptables option --physdev not enabled
https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=333135

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
apacheguy
DD-WRT User


Joined: 26 Jun 2008
Posts: 88

PostPosted: Wed Nov 09, 2022 3:36    Post subject: Reply with quote
The interesting thing is that NAT loopback works on the wireguard interface (oet1) even with CTF enabled.
Goto page Previous  1, 2 Display posts from previous:    Page 2 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum