Resolve domain name with local DNS

In my local network, I have an Ubuntu server which host a web application. In my local network, this web application is accessible from 192.168.0.100 . What I am trying to do is to connect this web application with a domain name. What I have done till now:


  • I added an A record to the domain name pointing my public IP (I have static public IP)


  • In Mikrotik, I opened the ports 80, 443 (in IP/Firewall/Nat)


  • In Ubuntu server, I added a virtual host for my domain and installed Let’s Encrypt certificate

And all works fine! The https : //mydomain.com shows my web application. The only problem is that this configuration I have done, is working only outside local network. When I am connected in the local network, mydomain.com can’t be resolved successfully. I tried and I added a static DNS entry in IP/DNS/ :

But the problem wasn’t resolved. The only solution I found is to add a record in hosts file in my Windows PC, but I would like to avoid this solution.

Can I configure somehow the Mikrotik, to add a rule (??) for this specific domain? Thanks!

You just need Hairpin NAT…

https://help.mikrotik.com/docs/display/ROS/NAT#NAT-HairpinNAT

I’m sure this is possible with DNS and without hairpin NAT. At work we have some hosts that are resolved from our internal DNS server to their internal IP addresses, whereas on the Internet they resolve to their external (NAT) address.

Is your Mikrotik configured as a DNS server, and used as primary resolver by your internal devices?

That means your PC doesn’t use your mikrotik as DNS server.

Using a static DNS entry with Mikrotik as DNS server would work as well…
However reading about Hairping NAT will help you understand why it doesn’t work right now…

Thanks for your replies! In IP/DNS, I have :

DNS Mikrotik.jpg
How can I set Mikrotik as DNS resolver? Also, should I set mikrotik as DNS resolver ? :slight_smile:

Also, I tried to implement Haripin Nat (very nice article, I knew something more today :slight_smile: :slight_smile: ) In the article says that I should execute


/ip firewall nat
add action=masquerade chain=srcnat dst-address=192.168.0.100 out-interface=LAN protocol=tcp src-address=192.168.0.0/24

however, the parameter out-interface=LAN what does it mean, because in my case I don’t have such interface. I that option I have:

Mikrotik-outinterfaces.jpg

Whether or not your devices use the Mikrotik as their DNS server depends on how they’re configured. Easiest way to configured this is normally to configure your DHCP server to give out your preferred DNS server. If you’re using your Mikrotik as DHCP server as well, then this is configured in Winbox under IP / DHCP Server / Network. Set DNS Server to be the IP address of the Mikrotik

And your second question, yes it’s a good idea at least in my opinion. Apart from being able to configure local names like we’re discussing here there is also the benefit that the Mikrotik caches the names it resolves, so regularly used names don’t need to be looked up from the Internet.

however, the parameter out-interface=LAN what does it mean, because in my case I don’t have such interface. I that option I have:

It means that the out interface is your Lan Network…
Masquerade is a unique subversion of action=srcnat, https://wiki.mikrotik.com/wiki/Manual:IP/Firewall/NAT#Masquerade
src-nat happens at the postrouting Chain, so it applies to packets as they leave the network interface, thats why we use out-interface=LAN, so that we masquerade the packets leaving the Lan interface, meaning they will leave with the LANs interface IP address…

So when you try to reach your Server, the Server will actually see the LANs Interface IP address and not the Clients IP…

I’m resurrecting this discussion because I have a similar problem… I have to access my domain with public ip from inside my lan, ngenix redirects https calls to my server: 10.0.0.100

From the outside everything works fine, from inside my network it doesn’t :frowning:

Any suggestions?
router.png

Again and again … It’s called Harpin NAT
http://forum.mikrotik.com/t/loopback-nat-or-hairpin-on-mikroitk/162786/9
http://forum.mikrotik.com/t/forward-internal-traffic-to-internal-webpage/160853/3
http://forum.mikrotik.com/t/cannot-access-wan-ip-from-lan/161858/2

or https://forum.mikrotik.com/search.php?keywords=mikrotik+harpin

https://forum.mikrotik.com/viewtopic.php?t=179343