How would I set a custom "domain name" of sorts for a LAN server?
Say I have a LAN server running on my local network. Just for the sake of it, let's say it's Node.js running on a Windows 10 PC hooked up to a network called "someNetwork".
Now this Windows 10 PC has a fixed IP address on someNetwork which is 192.168.0.15
, and the Node.js server itself runs on port 8080
. K, so I can access this server from another PC (assuming that PC is connected to someNetwork) by simply typing 192.168.0.15:8080
in the address bar of any browser... Alright, everything's good so far.
Now for the question: I want said server to be accessible via a custom "domain name" of sorts. (I don't think that "domain name" is the proper term). So, for example, I'd want people connected to someNetwork to be able to access my server by typing something like myserver.net
or something similar, and have my router automatically send them to 192.168.0.15:8080
without them having to remember that specific number. Is this possible? If so, how would I do it?
I found another question very similar to this one, but it was asked almost 10 years ago and I doubt that any of the information there is still viable. I hope this fits here well!
Send them to the address? Yes, that's called DNS, and it really works with the same kind of domain names that you already have elsewhere.
Send them to the address:port? No, there's nothing for that. Your server will always need to listen on port 80 for HTTP – use a reverse proxy to forward the requests to Node or such.
I personally own many internet servers + domain names, I'm not asking how to set them up. This question is asking specifically about LAN servers and networking.
At its core, DNS works in a LAN in the same way that it does on the internet. You could in fact take a purchased domain, such as myserver.net
, point it to 192.168.0.15
, and it should work.
(Though if it doesn't, that's not because the theory is wrong but because of "DNS rebinding attack prevention" in your router. Unfortunately, malware authors have abused this in the past.)
When home routers provide local hostnames such as "myserver.lan" or "myserver.home", they actually do so by running a real DNS server (often 'dnsmasq') – it hosts a local zone directly on the router (populated from DHCP leases), while proxying all other requests to the ISP's nameserver.
To publish a made-up domain on the LAN, you would need to do the same. Set up a DNS server on your network, tell computers to use it as their only DNS server (e.g. through DHCP), then configure the server to answer for that domain.
(Some DNS software such as unbound or dnsmasq don't host full zones but instead support overrides for individual names, e.g. local-data: myserver.net
in Unbound. It depends on what name you want to use and whether it needs to coexist with a "real" DNS name.)
There are a few mechanisms which allow computers resolve hostnames in LAN without using a DNS server – primarily mDNS and LLMNR – but those don't work with just any name; they only handle bare names (such as "myserver") and those with the .local suffix. Anything else (including your usual TLDs) will never go through these mechanisms.