Using local domain name from within LAN

I’ve had this annoying problem ever since I set up my own web server at home, and that was about 5 years ago. Though the problem can be quite easily dodged in Windows and even more easily avoided in Linux, it’s been a nail in my eye for half a decade. Today I fixed it once and for all.

The problem is that I can’t use my domain name to access my server from within my LAN. Every time I type blog.fredrikbostrom.net into my browser I only get the login screen of my ADSL router. Not very helpful. So what I’ve had to do is type the local IP address instead of the domain name. This works for ssh and such, but when viewing my website wich contains references to stylesheets and other things using the domain name, it just doesn’t fly.

In Linux this is easily hacked by adding a line to the /etc/hosts file and I suspect that such a solution is possible in Windows as well. However, in my setup at home (Linux on desktop computer, Windows on laptop) this solution is only plausible for the desktop, where I in fact have adopted this method. On my laptop, on the other hand, it’s a different story since I’d have to edit the hosts file every time the computer enters or leaves the building. This is where the nail starts itching in my eye.

Ok, I’ve known the solution for a long time already: Install a DNS server on the server machine and make all my computers use my local server as primary DNS server. I’ve even tried this solution once, installing BIND9 and trying to get it configurated. Yes, trying. BIND is a monster to configurate and quite overkill for a small home network like mine, so I’ve always given up after seeing the 100+ page HOWTO.

So it wasn’t until today when the nail again started twisting around in the never healing wound that I yet again rolled up my sleeves and attacked the problem. After doing some serious Googling I found out about another DNS server called dnsmasq which according to testimonials should be “trivial to configure”, especially for home networks. This sounded good, so after a quick ‘aptitude install dnsmasq’ and some editing of the (long but if you look closer not so complicated) configuration file, I had my brand new DNS server up and running. And it worked, hooray! All requests made to anything ending with fredrikbostrom.net now goes directly to my server without taking a detour to my internet provider’s DNS servers, which caused the before mentioned problem.

So from now on I can write my own testimonial that setting up a simple DNS server for a home network using dnsmasq in fact is trivial (key evidence being that I’m writing this post using my blog’s web interface on my laptop). The only line I changed in the config file was the ‘local=/localnet/’ line to include my own domain name (i.e. ‘local=/localnet/fredrikbostrom.net/’). In other words: ipmasq FTW.

Advertisements

10 Comments

Filed under Geek speak

10 responses to “Using local domain name from within LAN

  1. hi Fredrik, i had a lot of problems setting up my space. all the web browser want to run the show. i am still trying to add music to my space. no luck so far all the programs want your life history. are you living in Finland or u.s. your english is good. i will invite you as a friend if it is ok.i invited younger people but they don’t respond. take care chuck

  2. gordon

    Hey, hope this helps or is of interest

    On most routers i have seen you can change the port that the web managment is on. So instead of port 80 (port that webpages are accessed through) you might use 8080, meaning to access your router you would need to specify the port;

    http://192.168.1.1:8080 or http://www.YourDomainName.com:8080

    Note: In some browsers you need to type the http:// part otherwise they dont know to interpret the information from that port as a webpage (IE has this issue i think?) which is a bit odd.

    From there everything works as normal, and it means that your router doesnt get in the way of any http traffic in any direction.

    Thought this might be worth considerign for home users not running DNS

    This is obviously required to have remote managment of your router on at the same time as your website (without multiple IP addresses assigned and/or headache), though i dont recommend leaving it on perminantly as it is a security risk.

  3. Fredrik

    I have just come across this article after doing a search and it seems that dnsmasq is just what I need for my home network.

    Many thanks for taking the trouble to write about it. It has certainly helped me out.

  4. This looks like the perfect solution for my network! However, I did try installing dnsmasq and editing it like you said, but it doesn’t seem to me like other computers would notice my server as a DNS server—which it didn’t.

    Should I add my server into my local list of dns servers? Should I put it at the top? I want to do this, but it’s greyed out. 😦

    Short question, should I do anything to my local machine to make this work?

  5. @Alan: Good point, I must have left out a couple of crucial details. I have a WLAN router with a DHCP server that hands out IPs and other network settings to my local network computers. The WLAN router in turn is connected to my ADSL modem which is connected to the phone line. I’ve set the router to use my server as primary DNS server and my ADSL modem as secondary DNS. The ADSL modem again is set up to use my ISP’s DNS servers only.

    The WLAN router’s (and thus the DNS server’s) settings propagate down to all clients connected to it, making them use my server as primary DNS. (Actually, the clients may be using the router as primary DNS, which in turn uses my server as primary, but the effect is the same).

    Anyhow, no changes in the network settings should be necessary on the clients as long as you’re using DHCP and have your DCHP server set up to broadcast your dnsmasq server as primary DNS. If you’re doing the network settings manually, then you’d probably have to set the primary DNS of your clients to the server’s IP address, and the secondary to either your ISP’s DNS server’s address or your WLAN router’s/ADSL modem’s IP.

    I hope this cleared things up for you.

  6. My cousin would fall in love this blog post. We were not too long ago discussing about this. lol

  7. Hello, It is great to stumble upon a good blog like this one. Would you mind if I use some of your information, and I’ll leave a link back to your site?

  8. router address

    Good write-up, but that won’t appear to be compatible with my router ip, any helpful hints?

  9. Thank you very much for this info! My own setup at home is more simple, with a modem that also acts as a router, but otherise I’ve been facing the smae issue for months. Hopefully dnsmasq will help remove the metaphorical infection in my own eye!

  10. You need to bee a part of a conest for one off the greatest websites oon the internet.
    I’m going to highly recommend this blog!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s