Use /etc/hosts to direct wildcard domain name
I searched this term and didn't find my answer: "wildcard domain name in hosts"
I have a HostGator account where I create secret domains so I can build and test websites. In order to use them, I add the domain to my /etc/hosts file like:
192.168.129.3 ts.buck
192.168.129.3 www.ts.buck
I tried using the *
192.168.129.3 *.buck
but it doesn't work.
This is on my desktop, I don't have a server here. It is also for internal use only, not for the rest of the world to see or access.
It would be nice to have a simple way to use my own TLD for building test sites.
You need to set up a DNS server. (install dnsmasq (is light) or bind (is rather heavy)). To install ...
sudo apt-get install dnsmasq
In /etc/NetworkManager/dnsmasq.d/dnsmasq-localhost.conf
add
address=/localhost.com/127.0.0.1
restart
sudo /etc/init.d/dnsmasq restart
Important note.
If dnsmasq
service failed to start, please check your service logs by running systemctl status dnsmasq.service
command.
Then, If you will see the following message in the logs Failed to create listening socket for port 53: Address already in use
- you may resolve this error as described here
Just a quick addition to the above answer, make sure that your local domain name DOES NOT end with .local
, it looks like this is a reserved name so in your /etc/dnsmasq.conf
:
address=/somesite.local/127.0.0.1
WILL NOT WORK
address=/somesite.loc/127.0.0.1
will work.