My problem is simple. On my MacBook I have named (BIND9) running so that I can have my own zone files that are checked *before* talking to my ISP's nameservers. Why? So that I can have *.webdev map to 127.0.0.1 to make starting new web development projects easier on my mac.
For example on my MacBook swiftmailer.webdev resolves to 127.0.0.1 and an Apache VirtualHost has some clever rewrite rules to know where to expects the document root for this project. I can create a new project called "otherproject" by simply creating a directory at the correct part of my filesystem and then opening "otherproject.webdev" in my browser. Easy.
This works really well, here's the zone file:
[text]$TTL 86400$ORIGIN webdev.@ 1D IN SOA @ root ( 42 ; serial (d. adams) 3H ; refresh 15M ; retry 1W ; expiry 1D ) ; minimum 1D IN NS @ 1D IN A 127.0.0.1 * IN A 127.0.0.1[/text]
Today I installed VirtualBox (a virtual machine) and I've got a Windows XP installation running in it. All good so far!
The Windows Virtual machine is correctly using my DNS to lookup *.webdev domains with one major flaw.... the returned IP of 127.0.0.1 points to the windows installation, not to my mac. Hmmf.
I want swiftmailer.webdev and other.webdev to point to the *host machine*, i.e. my mac. The solution of course is NOT to use 127.0.0.1 as the A record, it is to use the public IP address 10.x.x.x. This works.
The problem with using the 10.x.x.x address is that it's dynamically assigned and being on my MacBook, I move around a lot.
What I was hoping I'd be able to do is this. Since my MacBook always has the name "chrisbook.local" on the network, I wanted to CNAME using that instead:
[text]$TTL 86400$ORIGIN webdev.@ 1D IN SOA @ root ( 42 ; serial (d. adams) 3H ; refresh 15M ; retry 1W ; expiry 1D ) ; minimum 1D IN NS @ 1D IN CNAME chrisbook.local. * IN CNAME chrisbook.local.[/text]
While I can ping chrisbook.local and see my 10.x.x.x IP address comes back correctly, I can't ping swiftmailer.webdev (unknown hostname). Clearly whatever name finding protocol is being used on to create the hostname for the mac isn't valid for use with named/BIND.
Does anyone have any ideas how I can get the zone to return the current public IP address all the time? I'll drop the TTL to just a few seconds too. Stumped.
Zone file that returns CNAME for $HOSTNAME?
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Zone file that returns CNAME for $HOSTNAME?
How do you set up the virtualbox network (guest/host OS) - is it bridged, NATed or you assign it its own IP address?
There are 10 types of people in this world, those who understand binary and those who don't
Re: Zone file that returns CNAME for $HOSTNAME?
I suppose that you have this setup:
host OS:
Ethernet IP 10.*.*.* DHCP
Virtual Ethernet adapter IP 192.168.0.1
guest OS:
Ethernet IP 192.168.0.2
This is for SNATed guest OS.
I doubt you have used bridge between guest/host OS.
So, if you set up your DNS (host OS) to use virtual ethernet adapter IP (192.168.0.1) and set it as a primary DNS for your guest OS then you may try to use 192.168.0.1 for both OS. if it doesn't work for your host OS then you can try to use Views in your BIND config, so different IPs will be resolved for your host and guest OS (because they use different source IP).
host OS:
Ethernet IP 10.*.*.* DHCP
Virtual Ethernet adapter IP 192.168.0.1
guest OS:
Ethernet IP 192.168.0.2
This is for SNATed guest OS.
I doubt you have used bridge between guest/host OS.
So, if you set up your DNS (host OS) to use virtual ethernet adapter IP (192.168.0.1) and set it as a primary DNS for your guest OS then you may try to use 192.168.0.1 for both OS. if it doesn't work for your host OS then you can try to use Views in your BIND config, so different IPs will be resolved for your host and guest OS (because they use different source IP).
There are 10 types of people in this world, those who understand binary and those who don't
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Zone file that returns CNAME for $HOSTNAME?
Ah yes of course. If I can make sure that the bridge IP address is always the same then I can just use that
Thanks. At the moment VirtualBox creates the bridge and I'm not sure how it assigns an IP. I'll look into it.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Zone file that returns CNAME for $HOSTNAME?
Here's what I did:
a) Configure VirtualBox to use NAT instead of binding directly to my network interface. VirtualBox now gets a 10.x.x.x IP and uses my mac as a gateway.
b) Assign an IP alias to my primary network interface on the mac, in the 10.x.x.x range (ifconfig en1 alias 10.0.0.254)
c) Change my zone file to always return that 10.0.0.254 address
Works like a charm. On my mac 10.0.0.254 is my own IP so I see the correct site. On the windows installation 10.0.0.254 points to the host (my mac).
a) Configure VirtualBox to use NAT instead of binding directly to my network interface. VirtualBox now gets a 10.x.x.x IP and uses my mac as a gateway.
b) Assign an IP alias to my primary network interface on the mac, in the 10.x.x.x range (ifconfig en1 alias 10.0.0.254)
c) Change my zone file to always return that 10.0.0.254 address
Works like a charm. On my mac 10.0.0.254 is my own IP so I see the correct site. On the windows installation 10.0.0.254 points to the host (my mac).