Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

www and subdomains in /etc/hosts [closed]

I'm setting up Ubuntu for the first time and I'd like to use this as a server to host websites:

www.something.net
blah1.something.net
blah2.something.net

what do i need to set up as the hostname? and how does this need to be set up in /etc/hosts file?

thanks!

like image 466
user1337645 Avatar asked Oct 25 '25 04:10

user1337645


1 Answers

I think there may be some confusion between a machine hostname and hosting websites/domains on your machine.

To set the hostname you can use the hostname command. Something like the following should work on ubuntu. (You would also have to modify your DNS records so that mycomputer.domain.com resolved to your IP)

sudo hostname mycomputer.domain.com

See hostname man page for more information. You will also need to make these changes in the /etc/hostname file or else the hostname will change back when you next reboot.

To point a domain like www.something.net to a page on your machine you would need to edit the DNS records for something.net, these records could be maintained locally on the machine itself but you would have to setup a DNS server. It is quite likely that your DNS for something.net will be provided by the company you registered the domain with, in which case you would simply have to change which IP address www.something.net and something.net point to (via their website etc). Then setup a webserver to respond/serve pages for those sites.

You might find the ApacheMySQLPHP guide on the ubuntu wiki help for configuring a web server.

/etc/hosts would not really be involved unless you were making some kind of test setup/intranet system.

Hope this helps.

like image 147
Andrew Avatar answered Oct 26 '25 21:10

Andrew