How to make “localhost” slightly less local
brycewray.com
brycewray.com
Your personal computer will have ethernet and/or wifi, and those are entirely separate network interfaces, but it will also have a loopback interface (which is a dummy software-only interface that just connects back to your computer). The "localhost" hostname points at 127.0.0.1, and that IP is bound to the loopback interface, so all connections through localhost won't even hit the network, they'll just be looped back in (hence the name).
What all those -H/--host/--bind options do is tell your service which of those network interfaces to bind to. Instead of specifying an IP (and, therefore, an interface) to bind on, you can use 0.0.0.0 as a catch-all "meta-IP" that will tell your service to listen on all interfaces.
My personal preference (though it does require a bit more setup ahead of time) is to keep all these (HTTP) services listening on localhost, and then configure one single NGINX instance that binds on the external interface and proxies each individual service.
AFAIK, 127.0.0.1 localhost as a HOSTS file entry is merely a convention. For example, the name "localhost" can point to any address in the 127.x.x.x address space or any address in general. Similarly, a loopback interface can be assigned any 127.x.x.x address. The convention is to assign 127.0.0.1.
One of the nice things about NetBSD (IMO) is that when compiling one's own system, a loopback is not necessarily automatically created. It may be left up to the user to create one and assign it with an address. This can teach the user what software depends on the presence of a loopback interface that is assigned "127.0.0.1".
Also, that comment was already a bit muc, and I opted to simplify a bit.
Like next.js's "Production Server"[1] uses Node's builtin server, which doesn't natively let you listen on more than one IP. And because next.js hardcodes 0.0.0.0, it doesn't also listen on the IPv6 equivalent if available, which breaks some clients when using "localhost" as the hostname (BusyBox wget as a notable example I found).
Honestly, I don't think it's too unreasonable to argue that if a client has IPv6 connectivity and a hostname has a valid AAAA record, the connection should be established over IPv6. Browsers tend to have fallbacks to IPv4, but outside browsers you'll be surprised how little actual system software cares about DNS fallback.
Reading the BusyBox source code (https://elixir.bootlin.com/busybox/latest/source/libbb/xconn...) it seems like it will pass AF_UNSPEC to str2sockaddr, which is packed into `addrinfo hint` and then passed on to getaddrinfo(). Only when IPv6 support is disabled or ENABLE_FEATURE_PREFER_IPV4_ADDRESS is enabled will busybox shuffle around the DNS results to return an IPv4 address.
If your service isn't available on IPv6 yet your hostname has a valid IPv6 record, it's your task to indicate this to the software (using the -4 flag, for example) or to configure it to retry.
EDIT: post is now available also on dev.to[0].
[0]: https://dev.to/brycewray/let-all-your-devices-see-your-site-...
On Linux I have my VMs run avahi (the Linux mDNS service), and I access my VMs using vmname.local instead of using hardcoded IP addresses.
https://issuetracker.google.com/issues/140786115?pli=1
I would have sworn I saw that the latest pixel / android versions could, but now I'm not finding one way or the other. Given the issue above is still open, I am assuming not.
Just install cloudflared.
I suppose latency is important if you use ngrok for something other than development. I use ngrok exclusively for development, so that's where my comment comes from.
I enjoy the ease of use that the special privileges localhost was given in browsers, but I'm 100% sure it's a pitfall for starting developers. It's still confusing to me that someone capable of developing a website needs an explainer on how basic computer networking works, but I guess other people learn about computers top-down rather than bottom-up. I have no idea what all of these servers are (most of them seem Javascript based?) but I'd expect someone knowing how to deal with a piece of complex server software like that to at least know where to find their machine's IP address!
With IPv4 you can do it with a port forward, but the IP listed isn't the same as the IP you'll actually receive the connection on. You can get your external IP relatively easily with `curl ifconfig.co`.
If firewalls or port forwards aren't available to you, pick any of the popular port forwarding methods (here's a list: https://github.com/anderspitman/awesome-tunneling). I'm a big fan of just SSH-ing into an internet connected machine myself (`ssh -R 0.0.0.0:3000:127.0.0.1:3000 server.on.the.inter.net` will expose localhost:3000 on server.on.the.inter.net:3000 and encrypt the traffic between you and the server as an added bonus!) but there are plenty of paid and sketchy alternatives if you don't have a server to SSH into.
I don't know if they are or not. I am just a regular person with a home computer. I know how to set up a run a basic localhost server, but I don't really know about the other stuff you're talking about.
If you're thinking of diving deeper into development, I'd recommend you take the time to learn about computer networking. It's not a necessity if your end goal is to stuff HTML/CSS/JS files into a server somewhere, but it'd make your life a lot easier down the line.
https://minecraft.fandom.com/wiki/Tutorials/Setting_up_a_ser...
- https://www.wikihow.com/Portforward-Minecraft
- https://www.technewstoday.com/port-forward-minecraft/
- https://www.youtube.com/watch?v=X75GbRaGzu8
Most of the guide you linked is related to setting up Java and configuring Minecraft itself, you only need the port forwarding bit.
> hostname -I
$ hostname -I
hostname: invalid option -- 'I'
Usage: hostname [-v] {hostname|-F file} set hostname (from file)
domainname [-v] {nisdomain|-F file} set NIS domainname (from file)
hostname [-v] [-d|-f|-s|-a|-i|-y|-n] display formatted name
hostname [-v] display hostname[0]: https://www.tecmint.com/hostname-command-examples-for-linux/
Note: This won't only make your localhost service slightly less local, but also publicly accessible.
Example: `expose 80`