How can I set up a 'local' domain so that everyone on my local network can view a locally hosted site?
I want to set up MediaWiki on one of my home machines, and then have all requests made on the local network for 'wiki.home' or 'wiki.local' point to that box. I know that this can be done by editing each /etc/hosts file individually, but I want something more automated so that, for example, if a friend or family member comes to my house, they don't need to mess around with the hosts file in order to view the site.
Is there a simple way to do this? I have the wiki up and running, and I've been looking into dnsmasq, but I can't figure out how to set the DNS up properly. Since I want an automated solution, I feel like I need to change the DNS settings on my router, but if I change the DNS settings there, how can I still resolve external hosts?
Configuration Details
Router: Netgear WNR2000v2. The router gives me the option to manually specify DNS servers, which I'm assuming I will have to point to my Ubuntu box if I want to get this up and running.
MediaWiki and dnsmasq host: Runs Ubuntu 12.04. I've had some difficulty with the dnsmasq config (mostly due to my inexperience). For example, I'm not sure, but I think during installation, Ubuntu modified my DNS settings so that
/etc/resolv.conf
now had127.0.0.1
as the only DNS server. At that point, I could resolve the local hosts, but nothing else. I've solved this temporarily by modifying/etc/resolv.conf
and adding192.168.1.1
as the secondary nameserver, but the concern here is that192.168.1.1
will be using the Ubuntu box for DNS. Am I missing something obvious here?-
dnsmasq settings: uncommented the following lines:
domain-needed bogus-priv local=/local/ domain=local
Solution 1:
With standard DNS, you would run a DNS server that is authoritative for the local domain (home.
or local.
, although it's better to avoid the latter – see note below), but also acts as a resolver for all other domains.
dnsmasq can be used for this purpose – it has recursive mode enabled by default and your configuration looks fine; all that's needed is to tell it which nameservers to use for non-local domains. Normally those would be read from system's /etc/resolv.conf
file; however, since you want the local domain to work on the DNS server computer too, you will need to create a dedicated copy of resolv.conf which would be used only by dnsmasq, while the original resolv.conf would point to nameserver 127.0.0.1
.
# cp /etc/resolv.conf /etc/dnsmasq-resolv.conf
# echo "nameserver 127.0.0.1" > /etc/resolv.conf
# dnsmasq -r /etc/dnsmasq-resolv.conf
Note: These instructions are very basic, and should be adapted to the Linux distro in use. In particular, check the Debian and Ubuntu guides on dnsmasq.
After this, the router needs to be configured to use this computer as the DNS server; all DNS queries by computers in your network would then be handled by dnsmasq.
(Full-featured DNS servers, such as bind9, can perform recursive queries themselves – configuring upstream nameservers becomes entirely optional. This is how your ISP's nameservers work, for example. However, hosting your own domain with bind9 is fairly complicated at first, in comparison with the simple dnsmasq.)
Note: If you have Avahi (aka Bonjour) configured on any computer in the network (which Ubuntu has, by default), it's best if you avoid local.
in DNS and choose something like home.
instead, as names in the form of name.local
are already handled by Avahi.
(Although Avahi normally only responds to current-hostname.local
, it is actually possible to publish additional entries such as wiki.local
; they will, however, need additional IP addresses to be added due to the way mDNS works. Because of this, using Avahi instead of centralized DNS does not offer any more advantages, so I'm not suggesting it.)
Solution 2:
I found the Avahi daemon to be the easiest way to do this. Note: if you are using Windows machines to connect to the .local domain, you need to make sure those machines have either iTunes or another Bonjour client installed on them.
Check out this link for more info: http://www.howtogeek.com/167190/how-and-why-to-assign-the-.local-domain-to-your-raspberry-pi/
Although that link is specific to the Raspberry Pi, it should work on Ubuntu machines the same way. For other Linux distros that don't use apt-get
, just adjust apt-get
to your appropriate package manager - e.g. yum
for Fedora and CentOS)
Here are the exact commands I ran to get this going on my Raspberry Pi media server:
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install avahi-daemon
From there it automatically begins using your computer's hostname plus the .local
extension as it's domain name. So if your machine's hostname is mediaserver
, then you can access it on the network by typing mediaserver.local
into the URL bar of any machine that has Bonjour/Avahi on it (i.e. all Macs, plus Windows machines with iTunes installed).
Solution 3:
Local name resolution is a simple feature and it's been part of most routers that I used. It's also implemented in DD-WRT firmware. Netgear doesn't care for this feature that is constantly requested.
So, the answer that is much simpler than the others posted here - avoid the trouble and change your Netgerat router to something that supports local name resolution. Or, if that's not an option, and you feel the strength and got the time, flash DD-WRT on it.