[SOLVED] DNS Woes

6 posts / 0 new
Last post
#1 Sun, 01/22/2017 - 23:18
BobGeorge

[SOLVED] DNS Woes

I've created 2 virtual servers. Let's call them "website1.com" and "website2.com".

I've added "prepend domain-name-servers 127.0.0.1" to "dhclient.conf". This correctly inserts 127.0.0.1 as the "primary DNS" before the DHCP-provided DNS from my ISP, so it should look up domain names with the DNS server on localhost first, right?

In Virtualmin, I've ensured that the virtual servers have been given DNS entries.

Now, the tricky bit is that this is a development machine, so I'm behind a NAT. I've tried both "127.0.0.1" and "192.168.0.x" - the machine's NAT address - as the shared IP address. When I re-check the configuration, everything's fine except that it says that "192.168.0.x" does not actually equate to my externally visible IP address (which is true enough, as I'm behind a NAT here).

When I enter "website1.com" or "website2.com" into a browser, the websites are not appearing but it's going to the wider Internet to look up those domain names.

(I did "hack" things by adding "127.0.0.1 website1.com" to my "/etc/hosts" file, but this is no real solution because if I type "website2.com" then it changes to "website1.com" and website 1 appears. That is, "website2.com" is on 127.0.0.1 as well, and because of the "hosts" entry, that's equated to "website1.com" and that's what shows up as the default website for 127.0.0.1.)

Basically, before this, I've never touched DNS before, so I am rather clueless about how to configure this properly.

What I want is that when I type "website1.com" or "website2.com" into the browser address bar, then it'll go to my localhost DNS server and correctly pull up the right website. And for this to work whilst being behind a NAT as well, for this development machine.

But, yes, feel free to expand on this, if you want, to explain how it'll differ for the real server that this will all eventually go on (where I will have a proper static IP address and properly registered domain names and not use DHCP and so forth, but just for development and learning purposes, this is all happening behind a NAT for the time being until it's finally ready for the prime time of the wider Internet).

By the way, how exactly does Virtualmin know the difference between websites? What I mean is that, as they're on a shared IP address (127.0.0.1), when the domain names are converted to IP addresses, aren't both "website1.com" and "website2.com" converted to "127.0.0.1", so how are the virtual servers differentiated anyway?

Sun, 01/22/2017 - 23:43
unborn
unborn's picture

hi, if that server is behind NAT and you dont have real domain names, you will have to keep adding domain.com and domain1.com etc to your host file even if same ip. That is very simple and short. Otherwise you can install your local dns on your laptop which I would say dnsmasq is most simpliest way to get subdomain.domain.com and domain.com working. If you have actual real domain names and want to use them outside of your local network - then open correct ports on your router so your server can work behind NAT.

Configuring/troubleshooting Debian servers is always great fun

Mon, 01/23/2017 - 00:29 (Reply to #2)
BobGeorge

But if I add "127.0.0.1 website1.com" and "127.0.0.1 website2.com" to the "hosts" file then only "website1.com" shows up in the browser, as it's the default for the IP address.

How do I differentiate between multiple websites / virtual servers on the same IP address?

I just don't see how, with virtual servers on the same IP address, DNS is able to differentiate between them (I can't do it through "hosts" because both domain names have the same IP address, so they're just acting as aliases for the default website of 127.0.0.1).

But surely that's the whole essence of running virtual servers in the first place? To run multiple domains on the same server. I mean, that's the reason why I installed Virtualmin in the first place to be able to do this.

Mon, 01/23/2017 - 03:42
unborn
unborn's picture

Apache it self should do that, I run apache even on my computer with virtualhots but without any kind of DNS. This means when I have dev.com and dev1.com point to same ip which is in my case 127.0.0.1 apache is able to see the domain name I am requesting and points me in right direction (folder). You can use this even without dns. If its point you still to default website for ip then something is not correct. There are plenty of solved posts regards this issue, as virtualmin sometimes does have this issue, you may have look and search for a bit. I did not had this issue even so I cannot tell - sorry.

Configuring/troubleshooting Debian servers is always great fun

Mon, 01/23/2017 - 07:47
BobGeorge

I've run the "/usr/sbin/apache2 -S" command to get Apache's view of the situation and it says:

127.0.0.1:80 is a NameVirtualHost
    default server website1.com
    port 80 namevhost website1.com
    port 80 namevhost website2.com

This seems right but, still, when I browse to "website2.com", what happens is that it changes to "website1.com" in the browser address bar and "website1.com" is what appears, not "website2.com".

In the "Bind DNS Server" menu, I see two master zones for "website1.com" and "website2.com" plus "localhost" and the IP addresses "0", "127" and "255". In both cases, the "NS" record is the FQDN of my host with a "." at the end, all the "A" records are "127.0.0.1" and there's an "MX" and "SPF" record too.

I've tried pinging "website1.com" and "website2.com". They are reporting the IP address as "127.0.0.1". I've run a "traceroute" on the domain names and, again, it's just one response from "127.0.0.1". So all this is as I'd expect if the DNS server I'm running on localhost is working correctly as the primary DNS.

The virtual servers validate as OK. When I re-check the configuration in Virtualmin, everything comes back fine (save for the external IP address not being right, but I'm behind a NAT here, so it wouldn't be).

I don't know what else to look at and test. It seems to be right. It's just not working when I try the "website2.com" domain name in the browser.

Wed, 01/25/2017 - 00:42
BobGeorge

The weird thing is that I've tried "curl website2.com" and "curl website1.com" from the command line and I'm getting back the correct HTML for each website, but this just isn't working in the browser.

Okay, it was working under Firefox - which I'd never used to browse to the site before - and then I had a hunch. I cleared out Chromium's DNS and socket cache, its cache files and then it worked. My configuration was right, it's just that Chromium was unhelpfully remembering some earlier configuration in its caches somewhere and was using that, not what I'd changed it to.

As always with these things, you expect it to be something complex and advanced and difficult, but then it turns out to be something really dumb and simple.

Browser caching. Remember to flush out all the caches, folks, after you make changes like this.

(Though I still consider it a useful exercise because, in going through every little configuration detail, there were other little errors in my setup that I fixed.)