Community discussions

MikroTik App
 
Shy
Member Candidate
Member Candidate
Topic Author
Posts: 243
Joined: Sat Jun 13, 2020 8:17 am

Hairpin NAT

Tue Jul 07, 2020 3:24 pm

hello
I do have 2 web services that I would like to be avaialble locally with the external IP
i read that its possible by running the following procedure
https://wiki.mikrotik.com/wiki/Hairpin_NAT

I do have dynamic IP on the WAN interface, what should be the right firewall nat rules that I should assign?

i understand that i will need two rules one for chain dstnat with the external ip address that will go through the ether1 (wan) interface and one for accessing dst-address locally
is it right?

tnx in advance
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 22135
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Hairpin NAT

Tue Jul 07, 2020 3:42 pm

viewtopic.php?f=2&t=162869&p=802503#p802503

The basics for loopback or hairpin nat with dynamic wanip are.
1. add extra masquerade rule (also needed for fixed/static wanip)
2. modify dstnat rule according to method desired (no change required for fixed/static wanip)
3. ensure fw forward chain rules allow dstnat (also needed for fixed/statck wanip)
 
Shy
Member Candidate
Member Candidate
Topic Author
Posts: 243
Joined: Sat Jun 13, 2020 8:17 am

Re: Hairpin NAT

Tue Jul 07, 2020 11:24 pm

is it enough?
/ip firewall nat
add chain=dstnat dst-address=x.x.x.x protocol=tcp dst-port=xxxx \
  action=dst-nat to-address=x.x.x.x
add chain=srcnat out-interface=ether1 action=masquerade

/ip firewall nat
add chain=dstnat dst-address=x.x.x.x protocol=tcp dst-port=x.x.x.x \
  action=dst-nat to-address=x.x.x.x
add chain=srcnat out-interface=ether1 action=masquerade
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 3042
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: Hairpin NAT

Tue Jul 07, 2020 11:36 pm

If you have 2 servers which both serve web services on the same port then there is no way for router to decide what server send incoming connection traffic to.
Harpin just lets to access local resource via external IP from LAN but the problem is the same: which server should receive packets send to service visible at external_public_ip:80 address?
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 22135
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Hairpin NAT

Wed Jul 08, 2020 12:19 am

Not even close.
Unless you know what you are actually putting down in the config, probably best to read and learn more prior to doing so.
Did you read my post or check out the Youtube video link for example..............
 
Shy
Member Candidate
Member Candidate
Topic Author
Posts: 243
Joined: Sat Jun 13, 2020 8:17 am

Re: Hairpin NAT

Wed Jul 08, 2020 3:08 pm

If you have 2 servers which both serve web services on the same port then there is no way for router to decide what server send incoming connection traffic to.
Harpin just lets to access local resource via external IP from LAN but the problem is the same: which server should receive packets send to service visible at external_public_ip:80 address?
i didnt say on the same port...
 
Shy
Member Candidate
Member Candidate
Topic Author
Posts: 243
Joined: Sat Jun 13, 2020 8:17 am

Re: Hairpin NAT

Wed Jul 08, 2020 3:10 pm

Not even close.
Unless you know what you are actually putting down in the config, probably best to read and learn more prior to doing so.
Did you read my post or check out the Youtube video link for example..............
Yes I did, what is wrong in what I wrote?
 
Shy
Member Candidate
Member Candidate
Topic Author
Posts: 243
Joined: Sat Jun 13, 2020 8:17 am

Re: Hairpin NAT

Sun Jul 12, 2020 8:38 pm

Who can help? :)
 
Shy
Member Candidate
Member Candidate
Topic Author
Posts: 243
Joined: Sat Jun 13, 2020 8:17 am

Re: Hairpin NAT  [SOLVED]

Thu Jul 16, 2020 9:30 am

Found the solution - thanks to @jhgorse
viewtopic.php?t=107851#p547024
thank you