Resolve application DNS in OpenShift v2

Posted on | 360 words | ~2mins

If you followed this OpenShift howto and you installed OpenShift Origin using the Puppet modules in Vagrant, then maybe you come across with the problem how you can access your OpenShift applications outside the Vagrant virtual machine. By default OpenShift vagrant file will forward ports 80, 443, 22 and 53 to your host machine. This allows vagrant ssh to work and also allows you to access OpenShift Apache service using curl http://localhost:8080.

But as you know, when you create new application via rhc app create, then it gets its own domain name. Unfortunately this domain name is not accessible from the host and it will work only on the Vagrant machine. To be able to access your applications outside Vagrant, you need to do following:

  1. Open the Vagrantfile and change the DNS port 53 to 5350. Virtualbox will not forward the port 53, because 1) you need UDP, not TCP, 2) non-privileged users are not allowed to forward ports <1024. So the line in VagrantFile should looks like this:

    config.vm.forward_port 53, 5350, :protocol => :udp
  2. Now run vagrant reload and wait for changes to be applied. You can verify that the DNS server is working by:

    $ dig @ -p 5350
  3. When the machine is ready, start the dnsmasq on host:

    $ sudo dnsmasq --no-daemon --server="/"

    NOTE: The domain ’’ is the domain used by the OpenShift default Vagrant machine. If you use different domain name, change this.

    NOTE: If you have libvirtd installed and running, you might need to kill existing dnsmasq processes.

  4. When dnsmasq is running, add it to the /etc/resolv.conf as the very first nameserver:


    Now you can verify, if the DNS is working by:

    $ ping
  5. The last change will require modifying the Apache configuration in Vagrant machine. For that run:

    $ cd origin/
    $ vagrant ssh

    Then open the /etc/httpd/conf.d/openshift_route.include file and add these rules around line 45:

    RewriteCond %{HTTP_HOST} ^(.*):8080$ [NC]
    RewriteRule ^.*$ - [E=V_MATCH_HOST:%1,NS]

    Then reload the Apache service:

    $ service httpd reload
  6. Done! Now you can access your apps from the host machine. All you need to do is to add port 8080 into URL:

    $ curl