localhost为什么有时候不等于127.0.0.1?

玩儿netstat命令时发现的,man netstat发现参数-n:
Show numerical addresses instead of trying to determine symbolic host
于是乎,netstat不加参数的时候Active Internet connections那里一大票都是localhost

加了-n参数就变成具体ip地址了,而且很显然的大部分不是127.0.0.1。。。

到底localhost是正确的还是那些IP地址是正确的?我倾向于IP地址是正确的,但为什么netstat会解析成localhost呢?

阅读 7.7k
2 个回答

/etc/hosts文件里面一般有一条:
127.0.0.1 localhost
所以locahost是hosts文件里面定义的吧。

netstat的原理不清楚,如果是通过hosts文件确定localhost的ip,应该就是127.0.0.1啊。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题