5

By default 127.0.0.1 has the localhost alias.

  1. I found several approaches to changing it to a different string, but what is the standard, effective and safe best-practice way of doing it?
  2. Can I give the same IP, but with a different port, a specific/different alias e.g. when I type marius to get responses from the server listening to http://127.0.0.1:3000?
5
  • What software is running behind that port? Most software allows you to change the listening port.
    – Lekensteyn
    Feb 14, 2011 at 20:54
  • I'm running WEBrick, the rails embedded web server. But I wanted to also be able to have Apache responding at :8080. Would changing the IP (e.g. 127.0.0.2), and then give that one another alias be a better approach? Feb 14, 2011 at 21:18
  • Don't remove the localhost alias. It's likely some applications rely on it. Instead, add more aliases like Josh Taylor shows.
    – djeikyb
    Feb 14, 2011 at 21:58
  • In the apache config, you can configure virtual hosts (httpd.apache.org/docs/1.3/vhosts) to respond to different domains/aliases. I am sure you know this but there is no way through which you can run two processes listening on the same port. Feb 15, 2011 at 16:46
  • @Khaja Good remark. And yes, the question was intended with at least 2 different ports (or 2 different IPs if not) to differentiate between the aliases. Feb 15, 2011 at 20:02

1 Answer 1

6

The only way I know of is to edit your /etc/hosts file.

So for example you could have this:

127.0.0.1 localhost marius

I'm not totally sure on changing port though, as you shouldn't use ports in the hosts file.

2
  • why shouldn't you use ports in the hosts file? Feb 14, 2011 at 20:43
  • 1
    The hostfile is used for resolving host names (DNS). For port forwarding, you'll need a solution like IPTables.
    – Lekensteyn
    Feb 14, 2011 at 20:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .