Community discussions

MikroTik App
 
kmandymac
just joined
Topic Author
Posts: 1
Joined: Mon Jan 03, 2022 8:38 pm

Simple hairpin NAT not working

Mon Jan 03, 2022 9:18 pm

Device: hAP ac^2
RouterOS: 7.1.1
Subnet: 192.168.1.0/24
Router IP: 192.168.1.1
Server IP: 192.168.1.41

I am trying to configure a hairpin NAT for ports 22, 80, 443 to my server.
Port forwarding works fine if accessing by the domain name from the Internet, so ISP and the domain provider are not to blame.
I am monitoring all packages on the said ports on the server via TCPDump.
When trying to access the server by the domain name from my home network, THERE ARE NO INCOMING PACKAGES ON THE SERVER.
If I disable the masquerade rule, connections time out.
If I enable it, the clients will try to connect to ports 22, 80, and 443 of the Mikrotik router, not to those of the server.
How do I fix it?

Dump of my firewall config:
# jan/05/1970 23:27:32 by RouterOS 7.1.1
# software id = 4ZQL-60G6
#
# model = RBD52G-5HacD2HnD
# serial number = C6140C174DF0
/ip firewall filter
add action=accept chain=input comment="defconf: accept SSH" dst-port=22 \
protocol=tcp src-address=0.0.0.0
add action=accept chain=forward comment="defconf: accept qBitTorrent TCP" \
dst-port=12750 protocol=tcp src-address=0.0.0.0
add action=accept chain=forward comment="defconf: accept qBitTorrent UDP" \
dst-port=12750 protocol=udp src-address=0.0.0.0
add action=accept chain=forward comment="defconf: accept HTTP" dst-port=80 \
protocol=tcp src-address=0.0.0.0
add action=accept chain=forward comment="defconf: accept SSL" dst-port=443 \
protocol=tcp src-address=0.0.0.0
add action=drop chain=input comment="defconf: drop all not coming from LAN" \
in-interface-list=!LAN
add action=accept chain=input comment=\
"defconf: accept established,related,untracked" connection-state=\
established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
invalid
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input comment=\
"defconf: accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
add action=accept chain=forward comment="defconf: accept in ipsec policy" \
ipsec-policy=in,ipsec
add action=accept chain=forward comment="defconf: accept out ipsec policy" \
ipsec-policy=out,ipsec
add action=fasttrack-connection chain=forward comment="defconf: fasttrack" \
connection-state=established,related hw-offload=yes
add action=accept chain=forward comment=\
"defconf: accept established,related, untracked" connection-state=\
established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
connection-state=invalid
add action=drop chain=forward comment=\
"defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat \
connection-state=new in-interface-list=WAN
/ip firewall nat
add action=netmap chain=dstnat dst-port=22 in-interface=ether1 protocol=tcp \
to-addresses=192.168.1.41 to-ports=22
add action=netmap chain=dstnat dst-port=80 in-interface=ether1 protocol=tcp \
to-addresses=192.168.1.41 to-ports=80
add action=netmap chain=dstnat dst-port=443 in-interface=ether1 protocol=tcp \
to-addresses=192.168.1.41 to-ports=443
add action=src-nat chain=srcnat dst-address=192.168.1.41 dst-port=22 \
protocol=tcp src-address=192.168.1.0/24 to-addresses=192.168.1.1
add action=src-nat chain=srcnat dst-address=192.168.1.41 dst-port=80 \
protocol=tcp src-address=192.168.1.0/24 to-addresses=192.168.1.1
add action=src-nat chain=srcnat dst-address=192.168.1.41 dst-port=443 \
protocol=tcp src-address=192.168.1.0/24 to-addresses=192.168.1.1
add action=masquerade chain=srcnat comment="defconf: masquerade" \
ipsec-policy=out,none out-interface-list=WAN
/ip firewall service-port
set ftp disabled=yes
set tftp disabled=yes
set irc disabled=yes
set h323 disabled=yes
set sip disabled=yes
set pptp disabled=yes
set udplite disabled=yes
set dccp disabled=yes
set sctp disabled=yes

P.S.: I absolutely need to access the server from within my home network by its domain name and not by its local IP. It runs an app that I use all the time which only works if you access it by HTTPS.
 
Sob
Forum Guru
Forum Guru
Posts: 9121
Joined: Mon Apr 20, 2009 9:11 pm

Re: Simple hairpin NAT not working

Thu Jan 06, 2022 6:19 pm

Your dstnat rules are wrong, you can't have in-interface=ether1, because connections from LAN come from different interface. You also don't need that many srcnat rules. More info: viewtopic.php?t=179343

Who is online

Users browsing this forum: akakua, Bing [Bot], Google [Bot], GoogleOther [Bot], shahzaddj1 and 203 guests