23

I have a single IP (81.174.66.48) and I would like to use /etc/hosts to associate multiple domains with that IP. Currently my hosts file looks like this:

81.174.66.48 nerto.it  nerto

I would like eventlog.it and eventlog.in to also be resolved to 81.174.66.48. I tried making my hosts file look like this, but it didn't work the way I expected:

81.174.66.48 nerto.it  nerto
81.174.66.48 eventlog.it  nerto
81.174.66.48 eventlog.in  nerto

What it the proper setting to have in my /etc/hosts file so that nerto, nerto.it, eventlog.it, and eventlog.in all resolve locally to 81.174.66.48?

jj33
  • 11,038
  • 1
  • 36
  • 50
Luca Romagnoli
  • 347
  • 1
  • 2
  • 5

1 Answers1

42

Put all names for the same IP into a single line.

Assuming the 4 hostnames you want to access the IP via are nerto, nerto.it, eventlog.in, and eventlog.it, this should work:

81.174.66.48 nerto.it eventlog.in eventlog.it nerto
mit
  • 1,844
  • 6
  • 29
  • 42
Jez
  • 1,333
  • 2
  • 11
  • 23
  • Is it possible todo the opposite? To add the same domain to multiple IP addresses in the hosts file. – Bert Jan 11 '18 at 15:36
  • 1
    @Bert though I see why you might wanna do that, it would not make any sense. How would your computer know which IP to choose? – Darlan Alves Sep 28 '19 at 09:31