Simulating dns entries with /etc/hosts?

I am trying to debug a problem I’m having with my Tomcat server on a remote machine (Linode) and I need to experiment with multiple virtual hosts. However, I am not sure how to get my machine to treat certain domain names as local host. I want any request from my machine for either www.example.com and www.example.net to be routed back to localhost. But I can’t seem to find any relevant information on this. I though I had read something relevant on swerdna’s site but I can’t find it now.

Any ideas?

Thanks!

Perhaps I should elaborate on my attempts. I put the following entries in /etc/hosts:


127.0.0.1       www.example.net
127.0.0.1       www.example.com

then restarted the network:

rcnetwork restart

However, pinging either domain name still gets me the “real” server’s response, rather than localhosts.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Have you tried putting entries in your /etc/hosts file? What was the
result?

Good luck.

zak89 wrote:
> I am trying to debug a problem I’m having with my Tomcat server on a
> remote machine (Linode) and I need to experiment with multiple virtual
> hosts. However, I am not sure how to get my machine to treat certain
> domain names as local host. I want any request from my machine for
> either ‘Example Web Page’ (http://www.example.com) and ‘Example Web
> Page’ (http://www.example.net) to be routed back to localhost. But I
> can’t seem to find any relevant information on this. I though I had read
> something relevant on swerdna’s site but I can’t find it now.
>
> Any ideas?
>
>
> Thanks!
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJY5n+3s42bA80+9kRAu6lAJ9W6emh753HOwpJB6uY7D/shJ2ZMgCbB4TP
9HZAfMnU+982k39A51Wogdw=
=JGDH
-----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You probably already have a line for 127.0.0.1… have you tried just
adding these to that line?

Good luck.

zak89 wrote:
> Perhaps I should elaborate on my attempts. I put the following entries
> in /etc/hosts:
>
>
> Code:
> --------------------
>
> 127.0.0.1 www.example.net
> 127.0.0.1 www.example.com
>
> --------------------
>
>
> then restarted the network:
>
>
> Code:
> --------------------
> rcnetwork restart
> --------------------
>
>
> However, pinging either domain name still gets me the “real” server’s
> response, rather than localhosts.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJY6vi3s42bA80+9kRAsJRAJ95iKAYZjq4F27U5be4hOz1sZQv+wCePyVr
lnEhOKyXcbq/1TuOenkyYbI=
=M7gS
-----END PGP SIGNATURE-----

I could, but the comments in the file suggest that /etc/hosts is field based, so how do I let it know that the additional names are for the same field?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I’m pretty sure I’ve done it this way before, and I thought the file was
just an IP followed by any number of “names”.

Good luck.

zak89 wrote:
> I could, but the comments in the file suggest that /etc/hosts is field
> based, so how do I let it know that the additional names are for the
> same field?
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJY7kY3s42bA80+9kRAqORAJ0W1QrsuVmBqVIhMapRYVUhchpqRACeIGy7
KK++A6U/m5T1s13zDgOeIIk=
=VOu7
-----END PGP SIGNATURE-----

IMHO an IP address may only show up once in /etc/hosts. But you may add aliases to the entry:

127.0.0.1    localhost   www.example.net www.example.com

But there is also a mechanism that tells where to look first for name solving. So when the first lookup is done to dns server and an answer is found nobody looks at /etc/hosts.

Now I thought that this is configured in /etc/nsswitch…conf
The line for dns in my nsswitch.conf is:

hosts:          files mdns4_minimal [NOTFOUND=return] dns

What would mean: first look in the file (/etc/hosts in this case). This is what you want and what seems to be the default as installed. But you could check to be certain.

Ah, that makes sense.

I’ll give it a try.

Thanks!