Skip to content

Setting up bind on vm (reference)

Dustin Wheeler edited this page Apr 2, 2014 · 1 revision

Here's the process for enabling the dynamic DNS stuff to work from vagrant to upstream localhost

Setting up bind on the vagrant box

  1. Install bind on the vagrant box: # yum install bind
  2. Add the following to your /etc/named.conf:
zone "vagrant.dev" IN {
        type master;
        file "vagrant.dev.zone";
};
  1. Write the following file to /var/named/vagrant.dev.zone:
$TTL 1D
@   IN  SOA ns1.vagrant.dev. root.vagrant.dev. (
            2014022001  ; serial
            8H          ; refresh
            4H          ; retry
            4W          ; expire
            1D)         ; minimum TTL
; Nameservers
	IN  NS  ns1.vagrant.dev.
        IN  NS  ns2.vagrant.dev.

; Resolve nameservers to IPs
ns1     IN  A   127.0.0.1
ns2     IN  A   127.0.0.1

; A records
@	IN  A   127.0.0.1
*	IN  A   127.0.0.1
  1. Reown the file: # chown root:named /var/named/vagrant.dev.zone
  2. Generate the key file: # rndc-confgen -a -r /dev/urandom
  3. Start up bind: # /etc/init.d/named start
  4. Add nameserver 127.0.0.1 as the first nameserver in /etc/resolv.conf

Using the DNS server on your vagrant box from your host box

On your localhost:

  1. Start up the port forwarding: ssh -C -D 1080 -p 2222 vagrant@127.0.0.1
  2. Configure your browser to use SOCKS5

If all went well, you should be able to resolve anything.you.want.vagrant.dev correctly to your vagrant box in your browser. Note that unless you modify your system proxy to utilize the SOCKS5 proxy, you will not be able to resolve it outside your browser (IE, on command line).

SOCKS5 configuration firefox

SOCKS5 configuration can be done in firefox under network settings for all platforms. Set the server to 127.0.0.1 and the port to 1080.

SOCKS5 configuration chrome - linux

SOCKS5 configuration on chrome in linux (and maybe mac?) is done by running the following in a bash terminal:

export SOCKS_VERSION=5
export SOCKS_SERVER=127.0.0.1:1080

and then launching chromium from the same terminal.

SOCKS5 configuration chrome - windows

SOCKS5 configuration in Chrome on Windows is not possible on a limited user account due Chrome using the system level proxy settings, which cannot be changed by a limited user.

Setting up apache to use the dynamic names

To have apache automatically resolve the subdomain to a folder under your document root, append the following to your /etc/httpd/conf/httpd.conf on your vagrant box:

<VirtualHost *:80>
    VirtualDocumentRoot "/var/www/html/%1"
    ServerName *.vagrant.dev
    UseCanonicalName Off
</VirtualHost>

Then make sure that NameVirtualHost *:80 is not commented out above, and restart the apache server with # /etc/init.d/httpd restart

Requests to blah.vagrant.dev should pull up your files under /var/www/html/blah/

Note that enabling this functionality will make requests to vagrant.dev resolve to the /var/www/html/vagrant/ directory instead of the normal /var/www/html directory.