2016-02-24

Prepare your laptop for OpenShift - Local DNS resolver settings

I wanted to setup OpenShift demo on my laptop running on a virtual machine, running on IP 192.168.122.115 with Virtual Machine Manager.

OpenShift requires you to have a working DNS with wild card resolver, for example *.openshift.example.com should resolve to the IP address of the VM.

Usually you would insert required IP addresses to /etc/hosts -file, but it doesn't support wildcards.

This is where dnsmasq comes very handy, it's a simple local DNS server which can be easily configured for this kind of setup. The trick here is that dnsmasq and NetworkManager overwriting your /etc/hosts -file will cause some funny side effects every time you reconnect to a network.

Luckily NetworkManager nowadays supports dnsmasq, but needs some manual configuration in order to work perfectly for this use case:


edit file:
 /etc/NetworkManager/dnsmasq.d/local.conf
with lines similar to this:
 listen-address=127.0.0.1,192.168.122.1
 address=/.openshift.example.com/192.168.122.115
 dhcp-range=192.168.122.20,192.168.122.30,2h

As we are replacing the normal dnsmasq configuration, it's important to bind to the network interface(s) needed by libvirt, and also to provide dhcp server to your VMs.

edit file:
 /etc/NetworkManager/NetworkManager.conf 

and add dns and dhcp lines, do not touch the plugins line:
 [main]
 plugins=ifcfg-rh,ibft   # note that this is Fedora-specific line
 dns=dnsmasq
 dhcp=internal

Make sure the dnsmasq service is disable because NetworkManager will start it automatically. If it's enabled you will have problems.
 systemctl disable dnsmasq
 systemctl stop dnsmasq


That's it, you are now ready to test everyting.
 systemctl restart NetworkManager

Everything should work now. If you look into /etc/resolve it should have only local host as nameserver:
 # Generated by NetworkManager
 search redhat.com
 nameserver 127.0.0.1

And ensure your wildcard resolver works also:
 host testing.openshift.example.com
 testing.openshift.example.com has address 192.168.122.115


Even when switching wlan networks and connecting to VPN networks the resolver should work.

With this configuration dnsmasq will use the DHCP discovered DNS servers which NetworkManager gives it at the time of connection.






No comments:

Post a Comment