Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm working on setting up a home intranet for me and my roommates. My idea is that we'll be able to store things like past utility bills in a place that's more accessible than a drawer in the kitchen etc. Anyway, I have Apache 2 running on a Raspberry Pi, on my LAN, and if I use its IP address, I can access pages being served on the Pi. Since I'm doing this project more to learn about networking as to provide a service to my apartment, I thought it would be cool if my network could provide hostname resolution for my LAN. So rather than point my browser to 192.168.1.151, the Pi's IP address, I could point it to oberon (its hostname) and view the web pages served by the Pi.

Now I knew I was not the first person to want to do this, so I started by Googling. This question, also on Unix & Linux, has helped me immensely: How to make a machine accessible from the LAN using its hostname. At this point, I've tried everything in the verified answer. I thought about using the hosts file, but that would mean I would have to tell my roommates to configure their machines, which I don't want to them to have to do. I tried to reserve a DHCP lease for the Pi on my router (a NETGEAR WNR1000v2 (aka an N150)), and while the reservation worked, hostname resolution does not. This kind of frustrates me because I told my router the IP of the Pi and its hostname, yet it still does not provide this information to clients on my LAN.

With these two methods not working, I decided to install dnsmasq on the Pi. It seemed simple to configure and I would be happy to learn a new tool. I installed and have it running just fine (it seems). I can dig or nslookup the Pi's nicknames (which I set in /etc/hosts to oberon and homenet) and get the correct results. I can do the same for internet names like yahoo.com and get correct answers because I set up Google's 8.8.8.8 and 8.8.4.4 as backup servers in /etc/dnsmasq.conf. See this:

me@oberon~$ dig oberon

; <<>> DiG 9.8.4-rpz2+rl005.12-P1 <<>> oberon
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10787
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;oberon.                                IN      A

;; ANSWER SECTION:
oberon.                 0       IN      A       192.168.1.151

;; Query time: 10 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sun Oct  6 18:59:18 2013
;; MSG SIZE  rcvd: 40

Note that the SERVER is 127.0.0.1: oberon is looking up its own IP address on itself. This is what I expected to see. Output is the same if I do dig oberon @localhost. Because of this output, I'm thinking that dnsmasq is working fine. So to bring it to the next level, I want all clients on my LAN to be able to be able to type oberon in their browser and be taken to oberon's index page. For this I know I need to configure my router (apologies if this veers away from strictly Unix & Linux territory).

I have a Netgear WNR1000v2 that I am fairly familiar with. I have configured port forwarding so I can SSH into the Pi, and I've poked around in other settings as well. I know that before I started this project, I was getting my DNS servers from my ISP, but now I want to use those DNS servers primarily but also use 192.168.1.151 as a last check. So I changed my router's DNS config to the following:

My router's new DNS config. Trust me when I say the first two entries are provided by my ISP

So with this config, I expected to be able to do nslookup oberon on my (Windows) desktop and get a result of 192.168.1.151. But this does not happen. This is what does happen:

C:\Users\me>nslookup oberon
Server:  UnKnown
Address:  fe80::226:f2ff:fefa:bea

*** UnKnown can't find oberon: Non-existent domain

Resetting or dnsflushing the network adapter on my Windows machine does not change anything.

Now here's why I'm kind of tearing my hair out here:

C:\Users\me>nslookup oberon 192.168.1.151
Server:  oberon.lan
Address:  192.168.1.151

Name:    oberon
Address:  192.168.1.151

Clearly, dnsmasq is working just fine. If I tell my Windows box to use 192.168.1.151 to resolve the name oberon, everything is fine (the .lan domain was part of the configuration of dnsmasq, so I expected to see it there). If I could just get my router to tell my Windows machine to use 192.168.1.151 when it makes DNS queries, I should be good!

So it seems to me that the problem is in my router, but I just can't figure out what to do beyond changing the DNS servers to include 192.168.1.151 like I already have. Can anyone help me here? I will try to provide any further information desired.

share|improve this question
    
Try putting the pi as first DNS server, does it work then? –  terdon Oct 7 '13 at 0:30
1  
The router is the right place to do this. If for some reason you don't manage to get your router to serve a name for the Pi, running dnsmasq on the Pi and having the router serve the Pi as the DNS server would work. It looks like your problem is configuring your router properly. –  Gilles Oct 7 '13 at 0:58
    
Are you rewnewing the DHCP lease on the client after updating the DNS settings on the router? The DNS configuration is sent in the DHCP lease, so it has to get a new lease to get the new settings. As an alternate solution, you might also look into mDNS/zeroconf/avahi. –  Patrick Oct 7 '13 at 4:39
add comment

1 Answer 1

Your problem lies in your misunderstanding of the way those DNS servers are used, I don't know the exact details of the method windows uses to choose which DNS server to query but I'm betting its primary > secondary > tertiary /always/. And even if it wasn't and was round-robin, you're still going to be querying an unhelpful server 2 of the 3 times.

What will happen is the primary server will be queried. If that times out, which may be a second or two, the next server will be queried. DNS isn't a "consensus" system, if one of the remote servers is being queried, it will eventually discover the result that your hostname authoritatively does NOT exist, from its perspective as an internet DNS server.

You need your own LAN dns as the primary DNS server. The others would make suitable backup servers but I'd consider just dropping that entirely.

Also of note, your reverse dns (IP to name lookup) resolves to "hostname.lan" but your forward resolution tests are with just hostname. You should also have forward resolution for hostname.lan set up somewhere. While there can be many "name to address" forward lookups for a host, there is an expectation that there is a reverse lookup of the IP to a name, that in turn has a matching name to that IP record. It's not always critical and just makes log files whine sometimes, but some things are more sensitive to this than other things.

Also, dont forget to remove any hosts file bodgery you have put in place once you get it all working (i dont know if thats relevant to dnsmasq, never used it, I have a similar but more complicated configuration in place using ISC-BIND name server, which you can configure forwarding to other servers like you are using, or simply use it as a non-forwarding DNS server that does the full name resolution its self - which is what I have set up).

Needless to say, as you first speculated you are very very far from alone in making this set up, almost every reasonably-developed corporate LAN and a great many over-developed home LANs will have this sort of setup in place.

share|improve this answer
    
Thanks for your help iain! I understand what you're saying about how DNS is not a consensus system, so I set the Pi to the primary DNS server in my router. I then renewed the DHCP lease on my Windows machine. However, nslookup oberon still does not work. One thing I didn't mention in the text of my original post was that when nslookup fails, it says that the server it used was an fe80 IPv6 address -- which I know is a reserved link-local address. But I don't know what that means for DNS. Is my Windows box querying itself? dnsflush does not change this behavior. –  c.anna Oct 9 '13 at 0:21
    
And for what its worth, LAN hostname resolution doesn't work on my iOS devices either. I haven't mentioned them yet because I have a lot more introspective power with Windows, but if my problems were really arising strictly from Windows I would not expect these devices to have the same problem. –  c.anna Oct 9 '13 at 0:24
    
Also, to allay your concerns about the .lan domain, I configured dnsmasq to automatically expand simple hostnames to add .lan. Running nslookup oberon.lan 192.168.1.151 returns the expected result of Name: oberon.lan Address: 192.168.1.151 –  c.anna Oct 9 '13 at 0:26
    
I wonder if there's a "windowsism" at work or something, naming your hosts directly under the top level domain ('oberon.') is kinda odd, oberon.lan makes much more sense. One thing to be aware of is that domain suffixes and 'search domains' are often appended to a name to resolve it, e.g. "oberon" could be being resolved and found as "oberon.lan" if lan is in the search domains. However the above queries dont seem to show this being the case, the dig specifically has the terminating period on the hostnames, but be very aware of that when testing! –  iain Oct 9 '13 at 0:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.