When I am on my local network (subnet?), I would like to go to sub1.myserver.com
and for it to work the same as going to 192.168.1.99:1234
- i.e. the goal would be to use the same domain name I also use publicly for this server while getting e.g. LAN download speeds.
My Setup:
I have multiple services running running on different ports, i.e.: 192.168.1.99:1234
and 192.168.1.99:5678
on my Debian Bookworm server.
My DNS (porkbun) has A
records for my public ip -> (sub)domain names.
And I have an nginx proxy doing proxy_pass
'es like sub1.myserver.com
-> 0.0.0.0:1234
and sub2.myserver.com
-> 0.0.0.0:5678
.
This works great and I can access my server publicly via sub1.myserver.com
.
I can also, of course, go to 192.168.1.99:1234
directly and connect to the same application via LAN.
How could I achieve re-using the same domain for local lan connections, and if not possible/not advisible, what would be the next best solution?
You have two choices;
1 - A split-DNS scenario. You host an internal DNS server that will resolve the local IP to computers that use that DNS server. The public DNS would not change, but that make the zone to be duplicated locally with the one on the internet.
2 - Some business class router can do reverse NAT scenario. Its rules on the router that if a computer go to a specified public IP from the LAN, the router rewrite the packet to go on the local LAN IP. That scenario is more transparent to the user, even if they try to ping the dns's name.