Skip to content
Advertisement

How to make an alias for localhost that has a tld?

I was wondering how I would make an alias for localhost that has a tld. For example, foo.test wold connect to 127.0.0.1. I tried just adding a second line to /etc/hosts that also pointed to 127.0.0.1, but that didn’t seem to work. Although, I didn’t reboot, so that might be why.

The end goal is to have it so that I can test that a request is being sent to a specific subdomain in the Rocket framework for Rust. IE: foo.bar.test instead of baz.bar.test or just bar.test.

Advertisement

Answer

The man page for /etc/hosts says:

IP CANONICAL ALIAS ...
127.0.0.1 foo.test localhost

Should be good

But is the host really handling traffic from this IP address ?

Alternatively, the interface specific line can include the aliases

10.0.0.1 foo.bar.test foo
10.0.0.2 baz.bar.test baz
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement