Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a server connected to the router which has ubuntu 12.04. It is has apache/mysql/php all installed ready to go. the folder structure is like this:

/var/www -- this isnt the root
-/public - this is the root
-/vhosts - all subdomains go here

I have a folder in vhosts named mysite. I went into /etc/apache2/sites-available and created a file and here are the contents -> (vhost file). and I also added an entry in /etc/hosts file containing: and I also did

sudo a2ensite mysite

i tried accessing the site from a computer via and our public ip into the server but i was not able to view it. the public directory in the structure above does display on all computers when i try our public ip. but for anything added in vhosts the site wont show. there is no domain attached its just our ip. I tried changing the port from 80 to say 9999 in the mysite file in sites-available and tried myip:9999 but that didnt work either. what am I doing wrong?

edit: i forgot to mention that the server is dmzed on the router.

share|improve this question
Self hosting a single website is quite involved, host several is even more so. It's not as straight forward as setting up the web-server and typing in your domain name. You need a local DNS (domain name server) that will forward requests (lan and wan) for to the local address. Your network firewall/router could also provide this service, but I would suggest using something more suited for the task. The firewall/router provided by the ISP is probably not the right tool for the job. This is a gross oversimplification, but you should get the idea... – Anthony Oct 21 '12 at 13:39
so the hosts file on the webserver works only for the server itself? is there a way to broadcast it? back in the days where dns server didnt exist the internet was ran by it. Otherwise i would have to get another computer and set it up as a dns server ran locally. – Sarmen B. Oct 22 '12 at 20:31
The basic rundown... Joe user on the internet clicks a link for your site. His computer contacts a DNS to find the numeric address of that url. He then contacts your external IP. Your firewall/router/DNS has to forward that request to the correct machine on the lan, or port on the webserver. OR Jane user on your lan types in the url to the site. Your local DNS redirects that request to the correct port and lan ip. Again very over-simplified explanation, but hopefully its easily understood. Someone please correct me if I'm wrong. – Anthony Oct 22 '12 at 21:20
up vote 1 down vote accepted

Reachable on a few local machines

If you want to work on just a couple of local machines, you can always edit their /etc/hosts files. Windows also have hosts files that you can edit, which are located in C:\Windows\System32\drivers\etc\hosts.

In the hosts file on the computer you want to set up being able to reach, just add this to the bottom of it (both Windows and Linux):


Where you replace SERVERIP with the local IP address of your server running Apache.

Reachable on the entire local network

If you want it to work on your local network, you'll ned a DNS server and configure the networks DHCP server so your local machines do all their DNS queries through your server.

First, let's install bind.

sudo apt-get install bind9

Then we'll ned to start configuring bind and adding a DNS zone, in this case the Start by editing your /etc/bind/named.conf.local file and add the following block to it:

zone "" {
    type master;
    file "/etc/bind/zones/;

Then, create the direcotyr /etc/bind/zones.

sudo mkdir /etc/bind/zones

Now, let's add the zone file for the domain. Create and edit the file /etc/bind/zones/ and add the following to it:

$ORIGIN . ; -*- zone -*-
$TTL 600    ; 10 minutes          IN SOA  YOURSERVERNAME. (
                    2012102300 ; serial
                    6H         ; refresh
                    30M        ; retry
                    4W         ; expire
                    10M        ; minimum (10 minutes)
                NS  YOURSERVERNAME.
                A   YOURSERVERIP

www         A   YOURSERVERIP

Now take a closer look here. You need to change the two occurances of YOURSERVERNAME and the two occurances of YOURSERVERIP references to the ones that matches your server. For example server01.local and To find out your server name, type hostname -f in a terminal window on your server.

If you're gonna change anything in this zone file (like adding subdomains later or something), you must remember to update the serial number. In this case it's 2012102300. The value must be set to a higher value, e.g. 2012102301.

Restart the bind service with sudo service bind9 restart and the DNS server should be up and running for your domain. You should probably test this by running dig @localhost from the server itself before you jump on to the next step. You can also test it from a client computer on the network with dig @YOURSERVERIP, where YOURSERVERIP is the IP address for your server.

Now, the last thing you need to do, is update your DHCP servers configuration and set your local server as the (secondary, if possible) DNS server. This, unfortunatley, I can't help you with that easily.

Reachable on the internet

Since there is no top level domain name called .dev, it is necessary for ICANN to create this. At this point their gTLD application system is closed, but maybe it will be possible to apply for the .dev TLD some time in the future. Note that they probably want a bunch load of money for it.

share|improve this answer
thanks for your input ill try it tomorrow. So then is it ok for a computer to be both a server and a dns server at the same time? – Sarmen B. Oct 26 '12 at 3:19
@SarmenB. Yup. That isn't a problem. It's only different software that enables your computer to serve web pages and reply to DNS queries. – carestad Oct 27 '12 at 18:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.