All of your rules use the in-interface=ether1-gateway selector.
I prefer this myself, because if the wan IP changes, then there’s no need to change the firewall rules.
However, for hairpin NAT, this won’t work because when LAN hosts attempt to reach the public IP address, the in-interface will be the LAN interface, not the ether1-gateway interface.
There are basically two ways to fix this:
use dst-address=x.x.x.x (public IP address of the ether1-gateway interface) instead of in-interface=ether1-gateway
use dst-address-type=local dst-address=!192.168.0.0/16
I prefer method 2 because it is more flexible and won’t need to be updated if your IP addressing changes. (of course, if your LAN uses 10.x.x.x then make the dst-address=!10.0.0.0/8 - etc)
I also have another suggestion - move the pinhole rules into their own chain.
This will make the firewall a little bit more efficient as well as making the rules easier to manage.
Step1 - insert this new rule just before the first pinhole dstnat rule:
dst-address-type=local dst-address=!192.168.0.0/16 action=jump jump-target=pinholes
Step2 - modify all of your NAT pinhole rules by changing the chain to pinholes, and removing the in-interface=ether1-gateway criteria.
Step3 - at the end of the pinholes chain, add a default return rule:
add chain=pinholes action=return
telnet 192.168.1.250 80
Trying 192.168.1.250...
Connected to 192.168.1.250.
Escape character is '^]'.
Connection closed by foreign host.
telnet publicIP 80
Trying publicIP...
telnet: Unable to connect to remote host: Connection refused
Additionally I changed my rule to forward traffic from net to server www behind microtik. So I removed from in.interface ether1-gateway and left it blank. For dest address I put my public IP and I must admit it works. Still users from net are able to connect my websites. But anyway I still stuck in the same point, no access to websites for users in the same subnet as www-server.
Your rule #2 was a bit wrong:
2 chain=srcnat action=masquerade protocol=tcp src-address=192.168.0.0/16 dst-address=public_IP dst-port=80 log=no log-prefix=“”
This is the hairpin rule - the reason it didn’t work for you is that by the time SRCNAT is being checked, the DSTNAT has already been completed, so at this point, the packet will have the web server’s private IP as the destination.
If you just have a single LAN interface, then change the above rule by removing the part highlighted in red and replacing it with out-interface=LAN
This rule is correct. If you have a dynamic public IP (or may change it from time to time for various reasons like changing your ISP) and you don’t want to have to remember to come fix this rule whenever the public IP changes, you can modify the rule like this:
Thank you Zerobyte, you are awesome !
Indeed , then I changed rule number 2 with your suggestion it started work as should.
Thank you very much for your help and lesson.
No problem. I think it helps more if people understand what’s going on when they fix something.
You may want to edit the thread’s subject to begin with [SOLVED]