2

The default /etc/hosts file looks like this:

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

If I want to insert a custom item, should I insert it after the first line?

127.0.0.1   localhost
127.0.0.1   website.dev
...

Or should I add it after the last line?

...
fe80::1%lo0 localhost
127.0.0.1   website.dev

I've seen both, but can anyone explain what the difference is?

1

You can add it anywhere you want in the body of the file.

Additionally the following works also:

127.0.0.1   localhost website.dev website.org

and for me even this works (but I don't think it's recommended):

127.0.0.1   localhost, website.dev, website.org

For the sake of a better overview I prefer:

127.0.0.1   localhost
127.0.0.1   website.dev
127.0.0.1   website.org
255.255.255.255 broadcasthost
...IPv6 stuff...
  • What if we move website.dev above the default localhost, will that cause trouble? – Stickers Feb 3 '16 at 19:35
  • @Pangloss No, this won't cause any trouble. – klanomath Feb 3 '16 at 19:37
1

I guess the only difference would be that if you write your own lines after the first one, they will be found earlier than if they are in the last lines. As long as you don't have a huge amount of lines in your /etc/hosts file that shouldn't really make a difference though.

I personally would add my own entries after the last line because I like to clearly separate my own stuff from the system's default stuff.

You must log in to answer this question.

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