Use /etc/hosts to direct wildcard domain name

29,137

Solution 1

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

Solution 2

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.

Share:
29,137

Related videos on Youtube

Buck
Author by

Buck

Hacking at Ubuntu to build a Portable USB VM Server My current learning task for my Winter/Spring goal is to set my laptop up as a VirtualBox server serving Lubuntu and Windows 7, then get it to work from a USB Live stick. =========================================================================================== My goal for the Winter/Spring seasons of 2018 are to set up my laptop as a VM server serving Windows 7 and various other operating systems that I can access remotely from any home computer or from my laptop away from home (assuming I get a new laptop, LOL) I am hoping that the server can be configured on a USB stick and that I can use an external USB drive for the VM images. My fallible theory is that I can move it to whatever computer I want to use it from. (I believe it won't work as every computer in the house is a different brand.) ========================================================================================== I started with Ubuntu 8 back about the time Vista was becoming infamous. I upgraded to 9 and 10 and then stayed with LTS versions until version 16.04 LTS kept crashing on my SSD. I went back to Windows 8.1 which I upgraded to 10 in August of '16. This year, '18, I am hoping to set up a 'buntu based VM server. My skill level is adequate for the most part, but I probably only teeter on the edge of becoming a power user as I only use CLI when and as I am instructed. I do as much as I can through the GUI. This January of '18, I broke the screen on my laptop and attached it to an external monitor. I have installed Lubuntu 16.04 LTS but plan to install 18.04 as soon as possible. It is currently the only OS on the system, so I have it installed in BIOS mode rather than EFI, which I hope to avoid if possible.

Updated on September 18, 2022

Comments

  • Buck
    Buck over 1 year

    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
    Buck about 8 years
    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
    Buck about 8 years
    I added the line: address=/.buck/192.168.129.3 to dnsmasq-localhost.conf. This did the trick.
  • Buck
    Buck about 8 years
    Thanks, I didn't mean to override your answer, just clarify the added line without editing your answer. WOW, I am happy.
  • Rinzwind
    Rinzwind about 8 years
    Oh you are welcome to edit anything important into this answer ;-)
  • Fabby
    Fabby about 8 years
    @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! ;-)
  • Buck
    Buck about 8 years
    Thank you, I didn't know how to do that. Thank you and Bless You!
  • Josh.F
    Josh.F over 7 years
    sudo service network-manager restart : make sure to restart the network manager too :)
  • Taylan
    Taylan over 7 years
    For Ubuntu 16 use this to restart network manager sudo systemctl restart NetworkManager.service
  • muru
    muru almost 7 years
    If you have an addition to that answer, suggest an edit: askubuntu.com/posts/743051/edit
  • Jeff
    Jeff over 6 years
    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)
  • George Dimitriadis
    George Dimitriadis about 6 years
    Also "above answer" can become irrelevant after a while
  • peter
    peter about 6 years
    Do I need to add something to my /etc/hosts file?