dnsmasq local name resolution with NetworkManager

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
#       OPTIONS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka), 
#      REVISION:  ---

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

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

bash – expand shell variables ( bash bug resolved )

As you would have noticed in the recent versions of bash, expansion does not work properly when expanding directory names. So, for something like this

cd $varname

if you press tab, then variable name does not expand properly.

If this is something that is bothering you then you can now add the following in your bashrc and revert to older behaviour:

shopt -s direxpand

Hope this helps you.

ShellCheck – check basic POSIX shell script errors

Here is description of the tool:

Description : The goals of ShellCheck are:
: * To point out and clarify typical beginner’s syntax issues,
:   that causes a shell to give cryptic error messages.
: * To point out and clarify typical intermediate level semantic
:   problems, that causes a shell to behave strangely and
:   counter-intuitively.
: * To point out subtle caveats, corner cases and pitfalls, that may
:   cause an advanced user’s otherwise working script to fail under
:   future circumstances.

To install

dnf install ShellCheck

And just run the tool on the script to get the common errors.