29

I wonder whether is safe to use lvh.me instead of localhost when developing locally, since lvh.me must be resolved and the IP may change over time.

The goal of using lvh.me is to be able to handle subdomains, since localhost does not have top level domain.

Josu Goñi
  • 1,178
  • 1
  • 10
  • 26

7 Answers7

27

Unless you are the maintainer of lvh.me, you can not be sure it will not disappear or change its RRs for lvh.me.

You can use localhost.localdomain instead of localhost, by adding the following lines in your hosts file:

127.0.0.1 localhost localhost.localdomain
::1 localhost localhost.localdomain

This is better than using lvh.me because:

  • you may not always have access to a DNS resolver, when developing
  • lvm.me does not answer with a local IPv6 address corresponding to your local host, only with the IPv4 address 127.0.0.1
  • some ISPs DNS resolvers block answers corresponding to private addresses space, for security purpose (to avoid leaking internal informations)

Since you said in a comment that you do not want to update the host file, you have no mean to be sure that lvh.me will always work for your developers. Therefore, to answer your question: it is not safe. You may register a domain for yourself, but as I said before, some resolvers will block answers corresponding to private addresses space.

Alexandre Fenyo
  • 4,526
  • 1
  • 17
  • 24
13

lvh.me was not resolving to 127.0.0.1 on June 7, 2021. Depending on DNS names you don't control comes with this kind of risk. Although the domain name was reinstated by the end of the day, this answer offers some alternatives to depending on someone else's DNS configurations.

Both Firefox and Google Chrome now treat *.localhost names like localhost. They also do the right thing with port numbers.

To test it yourself, start a local http server listening to port 8000:

python -m http.server 8000

Then try these links

This trick does not help for command line programs. For example, this command will fail to resolve the host:

curl http://example.localhost:8000

Curl itself offers a lot of other tricks that might work for you if you need custom subdomains on the command line. For example, this trick works:

curl --resolve example.localhost:127.0.0.1 \
  http://example.localhost:8000

Also worth noting that a similar service is still available.

See https://readme.localtest.me.

One last alternative is to configure your own wildcard CNAME to resolve to 127.0.0.1. For example:

*.my.example.com.   1800    IN  CNAME   my.example.com.
my.example.com.     1800    IN  A       127.0.0.1
Eric Dobbs
  • 3,844
  • 3
  • 19
  • 16
  • 2
    The original custodian of lvh.me gave up custody: "I’m not planning to renew it; it’s not something I’ve personally used in more than a decade making it a strange out of pocket expense for me." — https://twitter.com/levicook/status/1401935705199185924 – Eric Dobbs Jun 07 '21 at 19:07
  • What about transferring the session to a subdomain with the `localhost`. When I had LVH it worked fine. – jack blank Jun 08 '21 at 15:00
  • @jack-blank, I'll offer this educated guess (not sure what you mean by "transferring the session"). Short story: "yes." Longer story: web sessions depend on browser cookies for identification & browser cookies are scoped to domain names. Firefox & Chrome treat whatever.localhost like a domain name. So usual cookie rules apply. And server-side session data work as expected. – Eric Dobbs Jun 08 '21 at 20:27
  • See https://twitter.com/levicook/status/1402069015338512385 -- lvh.me went down briefly in June 2021 (the time this answer was written) but it's back up now. He got donations to keep it running. – AlexChaffee Sep 27 '21 at 18:45
  • 1
    Thanks for the update, @AlexChaffee. I've edited this answer accordingly. – Eric Dobbs Sep 30 '21 at 14:50
9

No because as of right now http://lvh.me has an expired domain.

enter image description here

bennick
  • 1,879
  • 15
  • 21
  • See twitter.com/levicook/status/1402069015338512385 -- lvh.me went down briefly in June 2021 (the time this answer was written) but it's back up now. He got donations to keep it running. – – AlexChaffee Sep 27 '21 at 18:46
1

Services like lvh.me or localtest.me are just DNS services, so the only thing you're publishing to them is the names or the hosts you're using. They could resolve to any IP at any time, but providing you use use them only for local tests with fake data, you'll be safe.

But what if they shut down the service? Again, since you should only use them for local tests, you'll get immediate feedback and can easily go back to using localhost.

jdinunzio
  • 1,506
  • 1
  • 11
  • 26
0

Quick fix if you don't want to rewrite your code is to open up hosts file

sudo nano /etc/hosts

paste in (replace yoursubdomain with what subdomain you're calling)

127.0.0.1 yoursubdomain.lvh.me

push ctrl-x then y then enter

Then you're good to go

Chris King
  • 95
  • 1
  • 10
0

It depends on what you're doing. If it's local development then most the time yes, you can always resolve it if you want to check:

For linux or osx you can run this in terminal:

dig X.nip.io

It should always return 127.0.0.1. So while it's not the "safest" way to do this (because you don't manage the DNS itself), I still use it frequently for some kind of resolving TLD when necessary. Here's some valid reputable sites that are still around as of 2022/2023:

https://nip.io/

https://sslip.io/

sMyles
  • 2,418
  • 1
  • 30
  • 44
  • This is no longer correct: nslookup on x.nip.io results in `*** Can't find x.nip.io: No answer`. But using 127.0.0.1.nip.io works. – dirkjot Jun 22 '23 at 14:44
-2

You can just point your browser at myproject.apps.localhost or www.example.net.localhost.

hurikhan77
  • 5,881
  • 3
  • 32
  • 47