There is more than one localhost
Well, technically I lied. Of course, localhost
maps to just 127.0.0.1
but that is not the only address that points to your local machine. There are actually 16.7 million (2^24) addresses, as the loopback network range is 127.0.0.0/8
.
I find it particularly useful to have different loopback addresses per project, while keeping their ports consistent. For example:
Project A development environment
127.0.0.2:3000
http server127.0.0.2:5432
postgres127.0.0.2:6379
redis
Project B development environment
127.0.0.3:3000
http server127.0.0.3:5432
postgres127.0.0.3:6379
redis
It’s also worth mentioning that the zeroes can be omitted, like this
127.0.1.1 --> 127.1.1
127.0.0.1 --> 127.1
That’s normally a thing you see with IPv6 addresses, where the loopback range is ::1/128
(just one address).
0000:0000:0000:0000:0000:0000:0000:0001 --> ::1
Update: There is a recent proposal (2024-12-29) that aims to narrow 127.0.0.0/8
down to 127.0.0.0/16
. Even if that goes through, you still have 65536 addresses (2^16) to play with, which is plenty.