How to change localhost domain name

can anyone know how to change domain name of localhost im using apache2 webserver on my localhost i want change domain name localhost to any custom domain

Hi @Vector,

You shouldn’t.

More specifically, localhost should always be present, on every machine. Because localhost is the hostname that points to your local machine. On every machine. Always.

What you’re looking for is Virtual hosts combined with DNS. Which can be a bit more trricky than just a hostname change.

But anyway, your hostname can be set with:


More specifically:

sudo hostnamectl set-hostname <hostname>

Where <hostname> is the hostname you wish to assign to your computer.


I think you rather want to use virtual hosts.

1 Like

Thanks for the link.