Can I map a hostname *and* a port with /etc/hosts?

Carson picture Carson · May 24, 2012 · Viewed 149.4k times · Source

Can I map an IP address like 127.0.0.1 to a domain name and a port?

For example, I would like to map 127.0.0.1 to api.example.com:8000

Answer

mata picture mata · May 24, 2012

No, that's not possible. The port is not part of the hostname, so it has no meaning in the hosts-file.