Adding a host to hosts file [closed]

二次信任 提交于 2021-02-10 13:20:07

问题


I'm trying to learn about hosts & apache a little bit. One of the things I'm trying to do myself is to add a line to /etc/hosts so that way I can access localhost in the browser

Currently, hosts contains this:

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0 localhost

Questions: 1. What does the ::1, and fe80::1%lo8 mean? 2. Are they essential to the accessing of 127.0.0.1 via typing 'localhost' in your browser? 3. What would I do to create an additional link to 127.0.0.1 typing something else in the browser, like "local", so that way both "localhost" and "local" work?


回答1:


Kristian, I'm not sure what those symbols mean (::1 for example), but creating host file entries is as easy as typing an IP address and then the list of domains to match.

For example:

127.0.0.1 local localhost

will match both 'local' and 'localhost' to 127.0.0.1. You could have also done the following:

127.0.0.1 local
127.0.0.1 localhost

One entry per line - use a '#' at the beginning of each line if you want to comment that line out.




回答2:


The ::1 and fe80 relate to IPv6 references to localhost.

To additional aliases like local, just chain them along in a space-separated list:

127.0.0.1 localhost local mylocalmachine someothername


来源:https://stackoverflow.com/questions/5613581/adding-a-host-to-hosts-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!