Port forwarding to VLAN

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Author Message
6c656f
DD-WRT Novice


Joined: 16 Mar 2017
Posts: 4

PostPosted: Thu Mar 16, 2017 19:17    Post subject: Port forwarding to VLAN Reply with quote
Hey,

I am currently running ASUS RT-N66U on DD-WRT v24-sp2 (05/27/13) mega with the following firewall configuration:

iptables -I FORWARD -s 192.168.1.0/24 -d 192.168.3.0/24 -j DROP
iptables -I FORWARD -s 192.168.1.0/24 -d 192.168.9.0/24 -j DROP
iptables -I FORWARD -s 192.168.3.0/24 -d 192.168.1.0/24 -j DROP
iptables -I FORWARD -s 192.168.3.0/24 -d 192.168.9.0/24 -j DROP
iptables -I FORWARD -s 192.168.9.0/24 -d 192.168.1.0/24 -j DROP
iptables -I FORWARD -s 192.168.9.0/24 -d 192.168.3.0/24 -j DROP
iptables -I INPUT -p tcp -s ! 192.168.3.0/24 --dport 22 -j DROP
iptables -I INPUT -p tcp -s ! 192.168.3.0/24 --dport 80 -j DROP
iptables -I INPUT -p tcp --dport 53 -j DROP
iptables -t nat -I POSTROUTING -o `get_wanface` -j SNAT --to `nvram get wan_ipaddr`
iptables -I FORWARD -i vlan3 -m state --state NEW -j ACCEPT
iptables -I FORWARD -i vlan9 -m state --state NEW -j ACCEPT
iptables -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

I am trying to externally forward port 2222 to 192.168.3.123:22. I have confirmed that I am capable of routing to 192.168.3.123:22 from the router without any issues, however, when I attempt to add the forwarding rule via the GUI or via iptables I am having issues. Please let me know if you require any additional details to help troubleshooting. Thanks in advance.
Sponsor
6c656f
DD-WRT Novice


Joined: 16 Mar 2017
Posts: 4

PostPosted: Thu Mar 16, 2017 20:41    Post subject: . Reply with quote
eibgrad wrote:
Try disabling NAT loopback (or what dd-wrt calls "Filter WAN NAT Redirection" in the Security->Firewall page, unchecked = enabled). See if things improve.


This was unchecked, and I checked the box and port 2222 is still filtered externally facing. Here is the new firewall configuration that I've tried with the box both unchecked and checked:

Code:
iptables -A PREROUTING  -p tcp -m tcp -d `nvram get wan_ipaddr` --dport 2222 -j DNAT --to-destination 192.168.3.123:22
iptables -A FORWARD -m state -p tcp -d 192.168.3.123 --dport 22 --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -p tcp -m tcp -s 192.168.3.123 --sport 22 -j SNAT --to-source `nvram get wan_ipaddr`
iptables -I FORWARD -s 192.168.1.0/24 -d 192.168.3.0/24 -j DROP
iptables -I FORWARD -s 192.168.1.0/24 -d 192.168.9.0/24 -j DROP
iptables -I FORWARD -s 192.168.3.0/24 -d 192.168.1.0/24 -j DROP
iptables -I FORWARD -s 192.168.3.0/24 -d 192.168.9.0/24 -j DROP
iptables -I FORWARD -s 192.168.9.0/24 -d 192.168.1.0/24 -j DROP
iptables -I FORWARD -s 192.168.9.0/24 -d 192.168.3.0/24 -j DROP
iptables -I INPUT -p tcp -s ! 192.168.3.0/24 --dport 22 -j DROP
iptables -I INPUT -p tcp -s ! 192.168.3.0/24 --dport 80 -j DROP
iptables -I INPUT -p tcp --dport 53 -j DROP
iptables -t nat -I POSTROUTING -o `get_wanface` -j SNAT --to `nvram get wan_ipaddr`
iptables -I FORWARD -i vlan3 -m state --state NEW -j ACCEPT
iptables -I FORWARD -i vlan9 -m state --state NEW -j ACCEPT
iptables -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu


Code:
root@neo:~# iptables -L -vt nat
Chain PREROUTING (policy ACCEPT 139 packets, 30177 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DNAT       tcp  --  any    any     anywhere             EXTERNAL_HOSTNAME tcp dpt:ssh to:192.168.1.1:22
    0     0 DNAT       icmp --  any    any     anywhere             EXTERNAL_HOSTNAME to:192.168.1.1
   22  2415 TRIGGER    0    --  any    any     anywhere             EXTERNAL_HOSTNAME TRIGGER type:dnat match:0 relate:0

Chain INPUT (policy ACCEPT 1589 packets, 112K bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 39 packets, 3038 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 15 packets, 4770 bytes)
 pkts bytes target     prot opt in     out     source               destination
   67 17933 SNAT       0    --  any    vlan2   anywhere             anywhere            to:EXTERNAL_IP_ADDRESS
    1  1500 SNAT       0    --  any    vlan2   192.168.1.0/24       anywhere            to:EXTERNAL_IP_ADDRESS
    0     0 SNAT       0    --  any    vlan2   192.168.3.0/24       anywhere            to:EXTERNAL_IP_ADDRESS
    0     0 SNAT       0    --  any    vlan2   192.168.9.0/24       anywhere            to:EXTERNAL_IP_ADDRESS
    0     0 SNAT       tcp  --  any    any     192.168.3.123        anywhere            tcp spt:ssh to:EXTERNAL_IP_ADDRESS

root@neo:~# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       tcp  --  anywhere             anywhere            tcp dpt:domain
DROP       tcp  -- !192.168.3.0/24       anywhere            tcp dpt:www
DROP       tcp  -- !192.168.3.0/24       anywhere            tcp dpt:ssh
ACCEPT     0    --  anywhere             anywhere            state RELATED,ESTABLISHED
DROP       udp  --  anywhere             anywhere            udp dpt:route
DROP       udp  --  anywhere             anywhere            udp dpt:route
ACCEPT     udp  --  anywhere             anywhere            udp dpt:route
ACCEPT     ipv6 --  anywhere             anywhere
ACCEPT     0    --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             neo.leo.net         tcp dpt:ssh
DROP       icmp --  anywhere             anywhere
DROP       igmp --  anywhere             anywhere
ACCEPT     0    --  anywhere             anywhere            state NEW
ACCEPT     0    --  anywhere             anywhere            state NEW
ACCEPT     0    --  anywhere             anywhere
ACCEPT     0    --  anywhere             anywhere
DROP       0    --  anywhere             anywhere

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
TCPMSS     tcp  --  anywhere             anywhere            tcp flags:SYN,RST/SYN TCPMSS clamp to PMTU
ACCEPT     0    --  anywhere             anywhere            state NEW
ACCEPT     0    --  anywhere             anywhere            state NEW
DROP       0    --  192.168.9.0/24       192.168.3.0/24
DROP       0    --  192.168.9.0/24       192.168.1.0/24
DROP       0    --  192.168.3.0/24       192.168.9.0/24
DROP       0    --  192.168.3.0/24       192.168.1.0/24
DROP       0    --  192.168.1.0/24       192.168.9.0/24
DROP       0    --  192.168.1.0/24       192.168.3.0/24
ACCEPT     gre  --  192.168.1.0/24       anywhere
ACCEPT     tcp  --  192.168.1.0/24       anywhere            tcp dpt:1723
lan2wan    0    --  anywhere             anywhere
TCPMSS     tcp  --  anywhere             anywhere            tcp flags:SYN,RST/SYN TCPMSS clamp to PMTU
ACCEPT     0    --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     0    --  anywhere             anywhere
ACCEPT     0    --  anywhere             anywhere
TRIGGER    0    --  anywhere             anywhere            TRIGGER type:in match:0 relate:0
trigger_out  0    --  anywhere             anywhere
ACCEPT     0    --  anywhere             anywhere            state NEW
DROP       0    --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             192.168.3.123       state NEW,RELATED,ESTABLISHED tcp dpt:ssh

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     0    --  anywhere             anywhere

Chain advgrp_1 (0 references)
target     prot opt source               destination

Chain advgrp_10 (0 references)
target     prot opt source               destination

Chain advgrp_2 (0 references)
target     prot opt source               destination

Chain advgrp_3 (0 references)
target     prot opt source               destination

Chain advgrp_4 (0 references)
target     prot opt source               destination

Chain advgrp_5 (0 references)
target     prot opt source               destination

Chain advgrp_6 (0 references)
target     prot opt source               destination

Chain advgrp_7 (0 references)
target     prot opt source               destination

Chain advgrp_8 (0 references)
target     prot opt source               destination

Chain advgrp_9 (0 references)
target     prot opt source               destination

Chain grp_1 (0 references)
target     prot opt source               destination

Chain grp_10 (0 references)
target     prot opt source               destination

Chain grp_2 (0 references)
target     prot opt source               destination

Chain grp_3 (0 references)
target     prot opt source               destination

Chain grp_4 (0 references)
target     prot opt source               destination

Chain grp_5 (0 references)
target     prot opt source               destination

Chain grp_6 (0 references)
target     prot opt source               destination

Chain grp_7 (0 references)
target     prot opt source               destination

Chain grp_8 (0 references)
target     prot opt source               destination

Chain grp_9 (0 references)
target     prot opt source               destination

Chain lan2wan (1 references)
target     prot opt source               destination

Chain logaccept (0 references)
target     prot opt source               destination
ACCEPT     0    --  anywhere             anywhere

Chain logdrop (0 references)
target     prot opt source               destination
DROP       0    --  anywhere             anywhere

Chain logreject (0 references)
target     prot opt source               destination
REJECT     tcp  --  anywhere             anywhere            reject-with tcp-reset

Chain trigger_out (1 references)
target     prot opt source               destination
6c656f
DD-WRT Novice


Joined: 16 Mar 2017
Posts: 4

PostPosted: Thu Mar 16, 2017 21:10    Post subject: Reply with quote
Code:
root@neo:~# iptables -t nat -vnL
Chain PREROUTING (policy ACCEPT 300 packets, 50011 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DNAT       tcp  --  *      *       0.0.0.0/0            EXTERNAL_IP       tcp dpt:22 to:192.168.1.1:22
    0     0 DNAT       icmp --  *      *       0.0.0.0/0            EXTERNAL_IP       to:192.168.1.1
  102 12706 TRIGGER    0    --  *      *       0.0.0.0/0            EXTERNAL_IP       TRIGGER type:dnat match:0 relate:0
    4   240 DNAT       tcp  --  *      *       0.0.0.0/0            EXTERNAL_IP       tcp dpt:2222 to:192.168.3.123:22

Chain INPUT (policy ACCEPT 346 packets, 24255 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 65 packets, 4552 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 12 packets, 2968 bytes)
 pkts bytes target     prot opt in     out     source               destination
  112 23344 SNAT       0    --  *      vlan2   0.0.0.0/0            0.0.0.0/0           to:EXTERNAL_IP
    0     0 SNAT       0    --  *      vlan2   192.168.1.0/24       0.0.0.0/0           to:EXTERNAL_IP
    0     0 MASQUERADE  0    --  *      *       0.0.0.0/0            0.0.0.0/0           mark match 0x80000000/0x80000000
    0     0 SNAT       0    --  *      vlan2   192.168.3.0/24       0.0.0.0/0           to:EXTERNAL_IP
    0     0 SNAT       0    --  *      vlan2   192.168.9.0/24       0.0.0.0/0           to:EXTERNAL_IP
    0     0 SNAT       tcp  --  *      *       192.168.3.123        0.0.0.0/0           tcp spt:22 to:EXTERNAL_IP


Code:
root@neo:~# iptables -vnL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:53
    0     0 DROP       tcp  --  *      *      !192.168.3.0/24       0.0.0.0/0           tcp dpt:80
    0     0 DROP       tcp  --  *      *      !192.168.3.0/24       0.0.0.0/0           tcp dpt:22
 1688  152K ACCEPT     0    --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
    0     0 DROP       udp  --  vlan2  *       0.0.0.0/0            0.0.0.0/0           udp dpt:520
    0     0 DROP       udp  --  br0    *       0.0.0.0/0            0.0.0.0/0           udp dpt:520
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:520
    0     0 ACCEPT     41   --  *      *       0.0.0.0/0            0.0.0.0/0
   35  3178 ACCEPT     0    --  br0    *       0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     tcp  --  vlan2  *       0.0.0.0/0            0.0.0.0/0           tcp dpt:22
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            192.168.1.1         tcp dpt:22
    0     0 DROP       icmp --  vlan2  *       0.0.0.0/0            0.0.0.0/0
    7   228 DROP       2    --  *      *       0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     0    --  lo     *       0.0.0.0/0            0.0.0.0/0           state NEW
    0     0 ACCEPT     0    --  br0    *       0.0.0.0/0            0.0.0.0/0           state NEW
  161 10547 ACCEPT     0    --  vlan3  *       0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     0    --  vlan9  *       0.0.0.0/0            0.0.0.0/0
  295 26674 DROP       0    --  *      *       0.0.0.0/0            0.0.0.0/0

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
   92  5664 TCPMSS     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x02 TCPMSS clamp to PMTU
    0     0 ACCEPT     0    --  vlan9  *       0.0.0.0/0            0.0.0.0/0           state NEW
  154 39766 ACCEPT     0    --  vlan3  *       0.0.0.0/0            0.0.0.0/0           state NEW
    0     0 DROP       0    --  *      *       192.168.9.0/24       192.168.3.0/24
    0     0 DROP       0    --  *      *       192.168.9.0/24       192.168.1.0/24
    0     0 DROP       0    --  *      *       192.168.3.0/24       192.168.9.0/24
    0     0 DROP       0    --  *      *       192.168.3.0/24       192.168.1.0/24
    0     0 DROP       0    --  *      *       192.168.1.0/24       192.168.9.0/24
    0     0 DROP       0    --  *      *       192.168.1.0/24       192.168.3.0/24
    0     0 ACCEPT     47   --  *      vlan2   192.168.1.0/24       0.0.0.0/0
    0     0 ACCEPT     tcp  --  *      vlan2   192.168.1.0/24       0.0.0.0/0           tcp dpt:1723
18849   15M lan2wan    0    --  *      *       0.0.0.0/0            0.0.0.0/0
   33  1952 TCPMSS     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x02 TCPMSS clamp to PMTU
18742   15M ACCEPT     0    --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
   28  8793 ACCEPT     0    --  br0    br0     0.0.0.0/0            0.0.0.0/0
   25  2200 ACCEPT     0    --  br0    vlan2   0.0.0.0/0            0.0.0.0/0
    0     0 TRIGGER    0    --  vlan2  br0     0.0.0.0/0            0.0.0.0/0           TRIGGER type:in match:0 relate:0
    0     0 trigger_out  0    --  br0    *       0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     0    --  br0    *       0.0.0.0/0            0.0.0.0/0           state NEW
   54  2560 DROP       0    --  *      *       0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            192.168.3.123       state NEW,RELATED,ESTABLISHED tcp dpt:22

Chain OUTPUT (policy ACCEPT 1918 packets, 915K bytes)
 pkts bytes target     prot opt in     out     source               destination
   32  5279 ACCEPT     0    --  *      br0     0.0.0.0/0            0.0.0.0/0

Chain advgrp_1 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain advgrp_10 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain advgrp_2 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain advgrp_3 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain advgrp_4 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain advgrp_5 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain advgrp_6 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain advgrp_7 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain advgrp_8 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain advgrp_9 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain grp_1 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain grp_10 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain grp_2 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain grp_3 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain grp_4 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain grp_5 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain grp_6 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain grp_7 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain grp_8 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain grp_9 (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain lan2wan (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain logaccept (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     0    --  *      *       0.0.0.0/0            0.0.0.0/0

Chain logdrop (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       0    --  *      *       0.0.0.0/0            0.0.0.0/0

Chain logreject (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 REJECT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with tcp-reset

Chain trigger_out (1 references)
 pkts bytes target     prot opt in     out     source               destination
6c656f
DD-WRT Novice


Joined: 16 Mar 2017
Posts: 4

PostPosted: Thu Mar 16, 2017 22:30    Post subject: Reply with quote
eibgrad wrote:
Here's your problem.

54 2560 DROP 0 -- * * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT tcp -- * * 0.0.0.0/0 192.168.3.123 state NEW,RELATED,ESTABLISHED tcp dpt:22

This is the danger in appending (-A) rules rather than inserting (-I) them. Since the last rule in the FORWARD table is an unconditional DROP, your forwarding rule for the port forward is unreachable.


Awesome, learned something new, thank you very much for the very prompt help!
Display posts from previous:    Page 1 of 1
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