1

I'm reading a book on Ubuntu Server and after wiring all the networking, DHCP, DNS, NTP and all, we got to the point where we need to create an apache2 web-server.

I followed all the instructions but when we got to the multiple virtual host part, I can't seem to make it work.

Having only one network interface, I opted for the named-based virtual hosts. I'm going to list all my DHCP, DNS and Apache2 configurations to make it easy for everyone to figure the problem out.

DHCP

/etc/dhcp/dhcpd.conf

default-lease-time 43200;
max-lease-time 86400;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option domain-name "local.lan";
authoritative;
subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.100 192.168.1.240;
    option routers 192.168.1.1;
    option domain-name-servers 192.168.1.1;
}

DNS

/etc/bind/named.conf.options

options {
        forwarders {
          8.8.8.8;
          8.8.4.4;
        };
        dnssec-validation auto;
        listen-on-v6 { any; };
};

/etc/bind/named.conf.local

zone "local.lan" IN {
    type master;
    file "/etc/bind/net.local.lan";
};

/etc/bind/net.local.lan

$TTL 1D
@ IN SOA local.lan. exampleemail.local.lan. (

202212152; serial

8H ; refresh
4H ; retry
4W ; expire
1D ) ; minimum
IN A 192.168.1.1
;
@ IN NS lenovo.local.lan.
lenovo     IN  A   192.168.1.1 #my server

WEBSITE

For the website configuration, I created a file called 000-virtual-hosts.conf that holds the config for the virtual hosts I want to make work.

/etc/apache2/sites-available/000-virtual-hosts.conf

<VirtualHost *:80>
        ServerName mywebsite.com
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/mywebsite_error.log
        CustomLog ${APACHE_LOG_DIR}/mywebsite_access.log combined

</VirtualHost>

<VirtualHost *:80>
        ServerName myotherwebsite.com
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/myotherwebsite_error.log
        CustomLog ${APACHE_LOG_DIR}/myotherwebsite_access.log combined

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Call me a noob, but I don't know if the reason it doesn't work is because I don't own the mywebsite.com and myotherwebsite.com domains but I thought it would follow the example in the book and the domains would be requested specifically through port 80 and add the resolve to my server IP further in this post it would be local no matter if I own the domains or not. I thought it could be the fact that they're pointing to the same /var/www/html file and that could be the problem. I enabled them before I tried to make it work, sudo a2ensite 000-virtual-hosts.conf && sudo systemctl reload apache2.

The book at one point says: "If you're using domain names with virtual hosts, then this will only work if you set up networking such that the domain name referenced in the file resolves to the IP address of your server. [...] If you're running your own DNS server, you would add the A record there." So I added this line to /etc/bind/net.local.lan and updated the serial number, otherwise the DNS wouldn't accept the new host.

mywebsite.com IN A 192.168.1.247

But I think the problem is I really don't know what I'm doing/doing wrong.

Here are the logs caught by /var/log/apache2/error.log, I don't know if those logs could include connection failures to mywebsite.com because they're supposed to be for the default .conf file but I'm sharing them in case you need them.

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Fri Dec 16 01:32:24.187718 2022] [mpm_event:notice] [pid 32022:tid 139897582640192] AH00489: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations

EDIT

I changed my /etc/bind/net.local.net

$TTL 1D
@ IN SOA local.lan. exampleemail.local.lan. (

202212154; serial

8H ; refresh
4H ; retry
4W ; expire
1D ) ; minimum
IN A 192.168.1.1
;
@ IN NS lenovo.local.lan.
lenovo     IN  A   192.168.1.1
mywebsite IN A 192.168.1.247
myotherwebsite IN A 192.168.1.247

I've made both website resolve to the same IP because in the book it says: "Any traffic coming into the server requesting "mywebsite" will be provided /var/www/mywebsite, the second example looks for traffic from "myotherwebsite" and directs hits to /var/www/myotherwebsite".

and disabled the default file in /etc/apache2/sites-enabled that was taking the IP of the server.

Now the new page shows, but it doesn't make a difference when I type mywebsite or mywebsite.local.lan it doesn't find it but IP:80 works.

I still don't know how to type mywebsite and reach the local page.

Results of the dig command

mywebsite.local.lan

; <<>> DiG 9.16.1-Ubuntu <<>> mywebsite.local.lan
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 17696
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;mywebsite.local.lan.           IN      A

;; Query time: 4 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Wed Dec 21 12:02:17 PST 2022
;; MSG SIZE  rcvd: 48

myotherwebsite.local.lan

; <<>> DiG 9.16.1-Ubuntu <<>> myotherwebsite.local.lan
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 59264
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;myotherwebsite.local.lan.      IN      A

;; Query time: 8 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Wed Dec 21 12:02:19 PST 2022
;; MSG SIZE  rcvd: 53

I get almost the same output from another computer on the network, just the udp number changes.

4
  • Is the DNS server at 192.168.1.247 or is it at 192.168.1.1? Dec 19, 2022 at 18:23
  • The DNS server is at 192.168.1.1
    – Jimmy
    Dec 19, 2022 at 18:25
  • Do the domain names resolve to the web server's IP address? Dec 19, 2022 at 18:27
  • If you're asking for example if I owned the domains and made them resolve to it from a website like godaddy, no. But in my example I've added the resolution, or at least what I think is one, to the /etc/bind/net.local.lan as you can see in the line mywebsite.com IN A 192.168.1.247 to create a "local" resolution.
    – Jimmy
    Dec 19, 2022 at 18:44

1 Answer 1

0

According to the configuration you posted, your DNS server doesn't have any records that would point mywebsite.com. or myotherwebsite.com. to the Apache webserver – it doesn't even have a matching zone configured for those names – so all it does is forward the queries to the "upstream" servers (8.8.8.8, etc).

Currently the DNS server is only set up to host one domain – you have zone "local.lan" {..}, so everything in the specified zonefile is assumed to be under the "local.lan" domain. Any "out-of-zone" records in that file would be rejected.

A zonefile entry of mywebsite.com IN A ... doesn't create a domain "mywebsite.com" – due to the missing final . it has $ORIGIN automatically appended to it, so just like the "lenovo" entry becomes "lenovo.local.lan.", the "mywebsite.com" entry becomes "mywebsite.com.local.lan." (which is why it didn't get rejected outright by BIND as an out-of-zone name).

(Because your DHCP server broadcasts option domain-name "local.lan", some client devices will try to look up "mywebsite.com.local.lan." when the user enters "http:‍//mywebsite.com/", but the majority of them won't do that – if the user input already has at least one dot, the DHCP-provided domain suffix won't be appended. Meaning, the entry in your "local.lan" zone will never be queried.)

To make BIND answer for the domain name "mywebsite.com", you literally need a zone{} entry that matches this domain, e.g. zone "com" or zone "mywebsite.com", with its own zonefile.

(Alternatively, BIND's RPZ response-policy{} mechanism could be used to spoof replies for various domains without creating individual zones for each.)

14
  • Man thank you so much, you made me understand the concept of zones and DNS a lot more now. thank you so much.
    – Jimmy
    Dec 19, 2022 at 23:14
  • I still have a problem tho, I edited my answer, I still can't reach mywwebsite whether I type mywebsite.local.lan or mywebsite.local.lan:80
    – Jimmy
    Dec 20, 2022 at 23:35
  • Then I still ask the same question: Do the domain names actually resolve to the web server's IP address? What results do you get from trying to resolve them with a DNS query tool (dig, drill, nslookup, host, etc)? Dec 21, 2022 at 5:22
  • It was my understanding that if I added the line mywebsite IN A 192.168.1.247 and modified apache's sites-available .conf file's ServerName to remove the .com from the domain mywebsite, it would resolve to the server if I typed it in a web browser. It kind of does because I disabled the default file and only have the virtual hosts enabled with different html pages and it hits one of the two new html but not by their domain name, only by typing the local IP. I tried with dig on the same laptop that the DNS server is on and it worked with the IP but not with mywebsite.
    – Jimmy
    Dec 21, 2022 at 11:18
  • What's the output of dig mywebsite.local.lan from the laptop? And is the laptop actually configured to use itself as the DNS server? Dec 21, 2022 at 11:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .