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 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:
with lines similar to this:

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:

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

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

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

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.