11

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.

Buck
  • 720
  • 3
    Really? http://serverfault.com/questions/118378/in-my-etc-hosts-file-on-linux-osx-how-do-i-do-a-wildcard-subdomain http://unix.stackexchange.com/questions/3352/wildcard-in-etc-hosts-file http://stackoverflow.com/questions/20446930/how-to-put-wildcard-entry-into-etc-hosts – muru Mar 07 '16 at 13:04
  • You could have made an answer and I would have upvoted you ;) – Rinzwind Mar 07 '16 at 13:05
  • Should I have clarified that I searched "askubuntu"? – Buck Mar 07 '16 at 13:08
  • explain why the negative? – Buck Mar 07 '16 at 13:12
  • here I put it back to 0 ;-) and to the 1st comment: probably, That 1st line can tick people the wrong way when they find a results within seconds ;-) – Rinzwind Mar 07 '16 at 13:35

2 Answers2

13

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

Alex Zheka
  • 103
  • 3
Rinzwind
  • 299,756
  • This was a very easy fix and very simple answer. Much better than the pages in the links. I wish I had asked this years ago. – Buck Mar 07 '16 at 13:32
  • I added the line:

    address=/.buck/192.168.129.3

    to dnsmasq-localhost.conf.

    This did the trick.

    – Buck Mar 07 '16 at 13:45
  • Thanks, I didn't mean to override your answer, just clarify the added line without editing your answer.

    WOW, I am happy.

    – Buck Mar 07 '16 at 13:46
  • Oh you are welcome to edit anything important into this answer ;-) – Rinzwind Mar 07 '16 at 14:25
  • @Buck As you've never accepted an answer on this site before: If this answer helped you, don't forget to click the grey at the left of this text, which means Yes, this answer is valid! ;-) – Fabby Mar 08 '16 at 20:26
  • Thank you, I didn't know how to do that. Thank you and Bless You! – Buck Mar 10 '16 at 10:49
  • 1
    sudo service network-manager restart : make sure to restart the network manager too :) – Josh.F Jan 04 '17 at 02:14
  • For Ubuntu 16 use this to restart network manager sudo systemctl restart NetworkManager.service – Taylan Feb 10 '17 at 06:47
  • I dont have the dnsmasq.d/ directory after the apt-get. The only thing I have under NetworkManager is dispatcher.d/hook-network-manager. Should I manually create that folder and file? (Ubuntu 16.04) – Jeff Dec 12 '17 at 20:10
  • Do I need to add something to my /etc/hosts file? – Jhourlad Estrella May 05 '18 at 05:07
  • https://askubuntu.com/questions/1029882/how-can-i-set-up-local-wildcard-127-0-0-1-domain-resolution-on-18-04-20-04 – Pawel Cioch Dec 16 '22 at 02:51
1

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.

muru
  • 197,895
  • 55
  • 485
  • 740