Happy New Year my friends. Hope you all had a wonderful year and you are confident to face 2020! This year I am taking couple of challenges unlike previous years where I made “NEW YEAR” resolutions. Keep me in your prayers so that I win those challenges.
Currently I am developing a SaaS application where user can publish their site in sub-domain. So, for test this feature in development mode, I need to enable wildcard sub-domain facility in my localhost. I am using Ubuntu 18.04 and a virtual host name [mylocalhost.tapan] for the application. Here is what I need to do for enable the sub-domain for that [mylocalhost.tapan] host name.
It’s a little bit long since
systemd-resolved does not play very well with
NetworkManager when configured with
Yet I still recommend starting
NetworkManager, because network connectivity changes (WIFI, wired, …) will be handled transparently.
Enable dnsmasq in NetworkManager
Edit the file
/etc/NetworkManager/NetworkManager.conf, and add the line
dns=dnsmasq to the
[main] section, it will look like this :
Let NetworkManager manage
sudo rm /etc/resolv.conf ;
sudo ln -s /var/run/NetworkManager/resolv.conf /etc/resolv.conf
echo 'address=/.mylocalhost.tapan/127.0.0.1' | sudo tee /etc/NetworkManager/dnsmasq.d/mylocalhost.tapan-wildcard.conf
NetworkManager and testing
NetworkManager should be reloaded for the changes to take effect.
sudo systemctl reload NetworkManager
Then we can verify that we can reach some usual site :
dig google.com +short
And lastly verify that the
mylocalhost.tapan and subdomains are resolved as
dig mylocalhost.tapan google.mylocalhost.tapan a.b.c.d.mylocalhost.tapan +short
I hope this will help you many like me who are searching for a local way of testing sub-domain facility of any application.
Thanks and happy coding!