0

I've come to a confusion regarding the /etc/hosts file. Both of these version work:

1

192.168.2.1 example.com example

2

192.168.2.1 example.com

Which one is the correct one?

3
  • 1
    More information is needed. What exactly are you trying to do here?
    – Techie Joe
    Jun 27, 2014 at 5:54
  • I'm trying to correctly configure my hosts file
    – Ryan
    Jun 27, 2014 at 5:58
  • 1
    is it for a website? Are you using it to test a website without DNS records being live? Just to be safe just assign one FQDN per line. If you have foo.com at 1.1.1.1 you'd put an entry for 1.1.1.1 www.foo.com on one line and 1.1.1.1 foo.com on another line.
    – Techie Joe
    Jun 27, 2014 at 6:00

1 Answer 1

2

They are both correct (for the syntax) but it depends on what you want.

The second one add an alias to 192.168.2.1 with the name example meaning both example.com and example will resolve to that IP.

From the doc

This manual page describes the format of the /etc/hosts file. This file is a simple text file that associates IP addresses with hostnames, one line per IP address. For each host a single line should be present with the following information:

    IP_address canonical_hostname [aliases...]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.