DNS magic

Before my old server died and I had to start over, I would have to access it via http://debby.local (debby was its hostname) when at home on the same network as it, and http://codinghobbit.no-ip.org when elsewhere. This wouldn’t have been much of an issue, except WordPress has the annoying “feature” where all links are absolute, i.e. http://codinghobbit.no-ip.org/link/to/stuff instead of /link/to/stuff. I had to install a plugin to convert all absolute URLs to relative URLs, and it worked okay. Another annoyance was that when giving people links to pages on my site, I would have to change the debby.local to codinghobbit.no-ip.org and vice-versa when clicking links to my site from other places. With the change of server, I figured it was time to fix the issue and do things right. First, I just added an entry to the hosts file on my laptop, which worked fine, but only for that computer. I wanted a more general solution that would work for anything connected to the network. I set up my little server to also act as a DNS server using dnsmasq, which reads the hosts file and uses that as it’s configuration. I then set the servers main and primary DNS to be 8.8.8.8 and 8.8.4.4, google’s DNS servers. The next step was to set the router to use my server as it’s DNS server, instead of whatever the ISP provided. Once I had everything set up, it all worked perfectly. Now I can use the same address no matter where I’m connecting from, and WordPress’s absolute URLs work fine.

EDIT: While this worked fine for codinghobbit.no-ip.org, where I didn’t have any subdomains, it doesn’t work now as I want to be able to add subdomains and such to my site. I now have just added address=/ivoah.net/192.168.1.32 to my dnsmasq.conf, which works beautifully

Leave a Reply