0

I have no idea where to start from so sorry in advance if this topic has already been discussed.

I usually develop web sites using my laptop as a development server, and recently I needed to test a web site using various mobile devices that can connect via wifi. Having no real AP, I set up a ad-hoc network using my laptop's wireless card and the devices can correctly browse the Internet and access the laptop's web server. The setup is as follows:

  • subnet: 192.168.1.0/24
  • gateway to the Internet (wired adsl router/modem): 192.168.1.1
  • laptop: 192.168.1.64 (eth0, wired if connected to the gateway) and 192.168.1.32 (eth1, wifi if somewhat bridged to eth0)
  • mobile devices (same for all, I only use one of them at any time for simplicity): 192.168.1.11 with default gw 192.168.1.1

Now, if I open either 192.168.1.32 or 192.168.1.64 from the mobile devices, I correctly get the default host of my Apache configuration. However I usually work with virtual hosts for many practical reasons, one of which being Drupal's peculiar implementation of multi-sites. For those who don't know how this works, Drupal takes the request's hostname and searches into its sites/ subdirectories for an appropriate configuration file. So, for example, suppose I request www.example.com, then Drupal would search for a config file in the following directories:

sites/www.example.com/
sites/example.com/
sites/com/
sites/default/

So I decided to adopt the following style of virtual hosts: if the website I'm working on will be accessible using www.example.com I set up a sites/www.example.com/ directory and create a virtual host for local.www.example.com so Drupal have no trouble finding it. I've been told this is suboptimal from a dns point of view since I'd have to create an authoritative entry for example.com and turn Bind on only when I'm supposed to access the local copy, which is weird. However, if this is the only path I can follow, I still have some problems with Bind's configuration, as I couldn't find any guide that tells me in a clear, noob-friendly way, how to set up such an entry. On the other hand, I was wondering if I could set up an authoritative entry for local, so I could access www.example.com.local and tell in some way (which I don't even know if this is possible) Apache to put www.example.com instead of www.example.com.local in the relevant environment variable.

Anyway, I have a last problem, sort of: when I launch Bind in debug mode with high verbosity, and make 192.168.1.32 as the primary dns for the devices, the output doesn't say anything about requests being made from the devices to Bind, so I'm not even sure it comes into play.

As you can see, I'm a complete noob at these matters, but I'm eager to learn, so any help/pointer will be appreciated.

Morpheu5
  • 259
  • 4
  • 18
  • What kind of mobile devices? Do you have access to system configuration? I usually handle this by editing /etc/hosts (or equivalent) on my desktop, laptop, and virtual machine. I use the convention d.example.com for my names so they don't conflict with anything "real". Bind is wide and deep, but if you have to go this way, I would suggest investigating an application or service that does the DNS work for you, like simpledns.com or maybe gotdns.com, then it would be a matter of configuring the devices to use a specific DNS server. – bogeymin Jan 29 '11 at 11:53
  • You can safely assume I don't have access to the configurations of the devices, as they are an iPod touch and various smartphones, like Symbian, Blackberry and so on... so you can easily see that /etc/hosts is not an option (which, however, I locally use in the laptop itself, and it works... for the laptop only) – Morpheu5 Jan 29 '11 at 21:53
  • It is possible to edit /etc/hosts on an iPod or iPhone. Also, I think you should tone down your responses a little if you want help. Making us all feel like idiots is not going to get you the help you need. – bogeymin Feb 04 '11 at 12:34
  • First of all, it is true you can edit the hosts file on the iPod/iPhone... after jailbreaking it, which is a thing I didn't do and I do not intend to do. Second, while it is technically possible to do that, I'm not working on iPhones only, I come across all kind of devices, and frankly the burden of researching the ad-hoc solution for all of them greatly surpasses that of setting up a local dns -- not to mention that I can at any time find one device that can't be configured. Third, I never treated anyone like an idiot and you definitely misread my words and are overreacting. – Morpheu5 Feb 06 '11 at 17:23
  • @morpheu5 - you should post your answer as an actual answer and mark it as such – Ben Pilbrow Feb 06 '11 at 17:33
  • Ops, sorry, didn't see that. I'll do it right away, thanks. – Morpheu5 Feb 06 '11 at 17:34
  • No worries. :-) – Ben Pilbrow Feb 06 '11 at 17:36

3 Answers3

1

sorry for the delay, I finally found a solution after lots of experiments. First of all, here's the zone file I use for the local. domain:

$TTL 1800

@       IN      SOA     local. root.porto.local. (
                        2010061500      ; serial
                        7200            ; refresh
                        3600            ; retry
                        604800          ; expire
                        1800            ; default_ttl
)

                NS      porto.local.

$ORIGIN local.

porto   IN      A       192.168.1.32
www             IN      A       192.168.1.32

to which I can add lines like

www.example.com IN      A       192.168.1.32

which results in the ability to query for www.example.com.local, and that's one thing.

In order to take into account of Drupal's weird behaviour, I actually found a solution that doesn't prevent me from working with the real remote www.example.com while working on a local copy, except that I had to set a zone for local.www.example.com and the host line for www which results in the odd and long www.local.www.example.com... frankly a bit too much to keep my mental health. I'll go for the local. way and s/.local// the database dump I'm going to deploy to the production server.

Thanks to everyone that replied.

Morpheu5
  • 259
  • 4
  • 18
1

One other solution is to setup a little proxy on your desktop machine (where you develop and host your sites with your multiple virtual hosts). For example, on Windows you could use Fiddler. If you are running Mac OS X or Linux, you can give a try to Charles (but it's not free).

Under Fiddler, you have to activate the option "Allow remote computers to connect" on the "Connections" tab of the options window.

Then you have to configure your mobile device to use the proxy. This can easily be done in the WiFi settings of the mobile device.

I expect that when you create your VirtualHost on your local web server you also edit your hosts file so that you can browse your sites locally. Now, you would like your mobile device to do the same.

This is where the proxy comes into place. The proxy is able to read your local hosts file (C:\Windows\System32\drivers\etc\hosts or /etc/hosts) so this means that your mobile device will be automatically routed to your local web server.

What is also interesting with this solution, is that you can simulate slow traffic networks and clearly see what your mobile device actually downloads (quite useful when using media queries and responsive images).

I found this article that very well explains how to do it : Testing a Mac OS X web site using a local hostname on a mobile device

0

Well honestly you may have overcomplicated your situation, you don't really need bind as you can just enter 192.168.1.32 example.com into your host file. If you want to learn how to use bind though try seeing what happens when you lookup that domain in NSlookup and see what it tells you, that can help a lot.

Jacob
  • 9,204
  • 4
  • 45
  • 56
  • See, if I could do something like that, I'd already have done it. Infact I did exactly that in the laptop, and it works... for the laptop. As I don't have access to the other devices' configuration, I can't apply the same principle. I'm left with needing some kind of dsn or something like that. – Morpheu5 Jan 29 '11 at 21:55
  • try seeing what happens when you lookup that domain in NSlookup and see what it tells you, that can help a lot – Jacob Jan 29 '11 at 21:58
  • I can only do this with the laptop, which has the entry configured in /etc/hosts... obviously it'll resolve to 127.0.0.1 or something like that. I have no way to use nslookup on, say, an ipod touch, a symbian or a blackberry device, in general. Especially the ipod, I guess. – Morpheu5 Jan 29 '11 at 22:01
  • Well, you could drop the hosts line and ask it to query it's self. – Jacob Jan 29 '11 at 22:16