Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm facing an issue with setting up my development environment. I'm trying to server all my projects as subdomains.

Here's the structure of my LAN network:

192.168.1.15 - PC
192.168.1.16 - Laptop
192.168.1.17 - Laptop
192.168.1.20 - Dev Server

I've successfully configured Apache dynamic subdomains using mod_vhost_alias Apache module and dnsmasq DNS server.

Here's configuration of my Apache virtual host:

<VirtualHost *:80>
  VirtualDocumentRoot "/var/www/html/%1/web/"

  <Directory "/var/www/html/%1/web">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

/etc/dnsmasq.conf file

listen-address=127.0.0.1
address=/.dev/127.0.0.1

As you surely see, I'm able to access my projects located in /var/www/html/ dynamically, without creating new virtual host or editing /etc/hosts file. Everything works perfectly and really speeds up the development process. I should say, it was working before I migrated development server to separate machine.

What is the issue? How to make working this config in local network? (I don't need the server to be accessible from the Internet).

I have added an entry to Windows hosts file on my PC pointing 192.168.1.20 IP address to dev hostname however I have no idea how to make subdomains working.

share|improve this question
    
As with any migration, check the logs for errors and tell us what you see :) –  Antoine Benkemoun Nov 17 '11 at 11:36
    
While accessing from the server, everything is working perfectly. When I try to access test.dev from my PC or laptop, browser is unable to find such website. Any ideas? :) –  Jason Nov 17 '11 at 12:51
    
Add the subdomains to the hosts file on each machine or configure dnsmasq to answer those queries. See the dnsmasq man page for details on this. It could be that it is enough to add these in the hosts file of the server that runs dnsmasq. –  AndreasM Nov 17 '11 at 13:07
    
@AndreasM - Unfortunately this is not a solution for me, I thought about it before posting this question. Why? I'm often traveling and then taking the server with me. –  Jason Nov 17 '11 at 20:55

1 Answer 1

up vote 2 down vote accepted

It is probably easiest to edit your hosts file on each machine to add the sub domains that you want to resolve. The format of the hosts file is quite simple

ip.add.re.ss    hostname.tld sub1.hostname.tld sub2.hostname.tld

or ip.add.re.ss hostnname.tld ip.add.re.ss sub.hostname.tld

so you can have

192.168.1.20    mydev.lan test.mydev.lan deploy.mydev.lan

or

192.168.1.20    mydev.lan
192.168.1.20    test.mydev.lan deply.mydev.lan

The thing to note here is you get the first match on hostname is returned.

Alternatively you could allow dnsmasq to listen on the server's IP address and set it as the DNS server for your other machines.

share|improve this answer
    
Iain - Unfortunately this is not a solution for me, I thought about it before posting this question. Why? I'm often traveling and then taking the server with me. Any other thoughts? –  Jason Nov 17 '11 at 20:55
    
@Jason what is the problem then? Switch apache off while travelling or switch the firewall on, no? –  AndreasM Nov 17 '11 at 21:12
    
Just for the future, any details on Alternatively you could allow dnsmasq to listen on the server's IP address and set it as the DNS server for your other machines.? –  Jason Nov 18 '11 at 1:26
    
You have specified listen-address as 127.0.0.0 so dnsmasq is only listening on the loopback address. If you don't specify a listen-address then it will listen on all available interfaces. Similarly you can put address=/.dev/192.168.1.20 and then point the other machines at the server for dns. –  Iain Nov 18 '11 at 7:47
    
@lain - thanks for explanation! –  Jason Nov 18 '11 at 9:35

Your Answer

 
discard

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.