0

I'm just running a website on my local network, and I want to change the hostname (because it's run on <HOSTNAME>.local), but I only want to change the hostname for the local domain name, not for everything. Is there a way to only change it for the local website domain without local dns? Thanks in advance!

2 Answers 2

2

Hostname has nothing to do with Apache2,

Apache listen to what is coming in to the IP address that it has on its interface.

Depending on the http(s) request it send the request to the correct virtual host in apache2.

And the key value is ServerName, see example below and if you omit the ServerName it will be the same as wildcard.

The first virtual host is listening to two IP adr. and the name www.example.org, the second example is listening on just oneIP adr. and the name www.example.net

Example:

<VirtualHost 172.20.30.40 172.20.30.50>
    DocumentRoot "/www/example2"
    **ServerName www.example.org**
    # ...
</VirtualHost>

<VirtualHost 172.20.30.40>
    DocumentRoot "/www/example3"
    **ServerName www.example.net**
    ServerAlias *.example.net
    # ...
</VirtualHost>

So to simplify it, it is apache2 who decide where the incoming http(s) traffic should be directed, not the system hostname!

And it is the DNS or hostfile on the local computer that directs where a http(s) traffic should be sent.

1

Hostname is global. You can't have two names at the same time.
The host name is (user) set on /etc/hostname and also /etc/hosts (with localhost as alias).
The current active name is stored at kernel level on /proc/sys/kernel/hostname.
You can force your dhclient to publish a different name editing /etc/dhcp/dhclient.conf and adding the following:

send host-name "<YOUR HOST NAME>";
1
  • "You can't have two names at the same time" -> This is context dependent. In terms of local DNS, you can have multiple hostnames associated with the system (or a remote one) by adding aliases to /etc/hosts (see man 5 hosts). This only works locally, but for development that's fine. Apache can then be configured to respond differently depending on the hostname in the request ("virtual hosts"): httpd.apache.org/docs/2.4/vhosts You can thus set an arbitrary hostname that will resolve to 127.0.0.1 and be recognized by apache. None of this requires changes to /etc/hostname. Commented Sep 16, 2020 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.