dnsmasq local name resolution with NetworkManager

2015-08-27 169 words 1 min read

Network Manager suports starting dnsmasq which helps you have a local cache for DNS thus getting faster resolution for the DNS queries.

Dnsmasq with netowrkmanager

So, one thing that I have been thinking about is having a local name resolution for the VMs. So, I wanted something like this to work:

vm1 => 172.17.42,1

vm2 => 172.17.42,2

and so on …

To achieve this and reverse dns to work, we will add the entries in file “/etc/NetworkManager/dnsmasq.d/hostnames“. Just one more problem, adding so many entries manually? So, to help you with that, I created this small script:

#!/bin/bash -
#===============================================================================
#
#          FILE: add-dnsmasq.sh
#
#         USAGE: ./add-dnsmasq.sh
#
#   DESCRIPTION:
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka), 
#  ORGANIZATION: 
#      REVISION:  ---
#===============================================================================

IPPRE='172.17.42.'
for i in {1..250}
do
    echo "address=/vm$i/$IPPRE$i" >> /etc/NetworkManager/dnsmasq.d/hostnames
    echo "ptr-record=vm$i,$IPPRE$i" >> /etc/NetworkManager/dnsmasq.d/hostnames
done

Just run this script to add all the entries and restart dnsmasq by killing the already running instance. 🙂


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it