I'd like to use a real URL instead of localhost for local development (so I can make my development environment more similar to production, not have to remember which port is associated with which service, and have valid certs).

I added an A record to my DNS records for my domain (*.myname.example.com ->, but I'm getting a "refused to connect" error; do I need to change something on my machine (e.g. I tried adding the same mapping to /etc/hosts)? I similarly tried an A record to and a CNAME to penguin.linux.test (this resolves to on my host, see below for my setup which has this /etc/hosts rule by default).

For more context (i.e. why editing /etc/hosts is insufficient), I can't actually edit /etc/hosts on my machine, only on the VM my code is running in. More specifically, my stack is below.

  • ChromeOS host
  • Crostini Arch linux container
  • Traefik docker container that routes subdomains to the appropriate services

To resolve any ambiguity about the root of the problem being more fundamental, this works perfectly well if I set my DNS rules to an A record that points to my external IP address (when I'm on a network that allows port forwarding, which isn't always the case, another reason I'm trying to use localhost/

  • 1
    A perfect answer exists on StackOverflow: stackoverflow.com/questions/16229126/…
    – Kinnectus
    Oct 4, 2019 at 15:53
  • @Kinnectus Thank you for that suggestion, but unfortunately I already saw that and several other similar answers and they are not relevant to my purposes. See my edited post for clarification about why that is the case. Oct 4, 2019 at 17:01
  • If you're running VMs then you could probably run a DNS server in a new VM that you configure your dev domains to your docker and other platform IPs and then configure your OS to use your new DNS to resolve your dev domains before going out to your default gateway
    – Kinnectus
    Oct 4, 2019 at 17:09
  • 1
    Hi, can you confirm that: 1 - you did change the A record to as @farhan-k said; 2 - you can resolve with nslookup or ping the host.myname.example.com as; and 3 - when you use localhost it effectively works. Thanks Oct 4, 2019 at 18:22
  • My setup is nonstandard: I'm trying to access a container from the host, the container's IP is dynamic, and I can't manually edit /etc/hosts. The host's /etc/hosts file, however, is dynamically updated to reflect the container's IP address (at penguin.linux.test). I have confirmed that if I manually add an A record in cloudflare *.myname.example.com -> 100.xxx.xxx.xxx (container's local IP) it all works. However, if I replace that A record with a CNAME *.myname.example.com -> penguin.linux.test it fails (** server can't find test.myname.example.com: NXDOMAIN from nslookup). Oct 12, 2019 at 0:29

2 Answers 2


You’re probably mistaking with is a loopback address which localhost usually resolves to (this is set by default in the hosts file). is a non-routable meta address.

  • See my edit for some clarifications, but I tried that as well without success. Thanks for the info though, I never really understood the difference (and I'm still a bit fuzzy on it tbh, but have some more context at least). Oct 4, 2019 at 17:09
  • @Californian Sorry I might not be understanding the question properly. Can you have a look at Jorge Valentini's comment and provide some of that information. It might help to diagnose the problem.
    – Farhan.K
    Oct 4, 2019 at 20:59

Some admin, make their web application resolve to localhost and your computer when making the request could store the information

Example: www.example.com can have the web Admin

     app.example.com in the A record

And your machine would also store the above. Only that the localhost is now your machine rather than app.example.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.