2

I have a server (debian) with two network interfaces that I would like to host multiple services and domains on; it is not entirely clear to me how the hosts file should be set up. Example:

eth0, bound to WAN interface 1.2.3.4:
   mail.example.com
   www.example.com
eth0:1, bound to WAN interface 1.2.3.5:
   www.other-domain.com
eth1, bound to LAN 192.168.1.123:
   some-clever-hostname

What should my hosts file look like? (including localhost,localhost.localdomain, etc.) Should I use DNS for some of these entries? Which ones?

Thanks!

EDIT: What if I was unable to utilize a DNS server, for instance in a testing environment?

mikewaters
  • 1,135
  • 1
  • 14
  • 26
  • Usually you don't put anything in the hosts file; it usually all goes in DNS. What exactly are you trying to accomplish? You stated you are hosting services for two domains, but you didn't state why this is important. – Chris S Jun 16 '10 at 16:58
  • This test is currently in a local-DNS-free environment (i.e. 3rd-party DNS is used to point The World to the two public interfaces, however, there is no local DNS server; I use a hosts file in a private git repo). – mikewaters Jun 16 '10 at 18:02
  • You don't have DNS on the lan, but do you have a dhcp server? If you haven't yet, dnsmasq is a good fit. Otherwise, avahi-autoipd, or host files. – Tobu Jun 16 '10 at 21:01

2 Answers2

1

Putting localhost in /etc/hostname and

127.0.0.1 localhost.localdomain localhost

in /etc/hosts is fine. The mappings can be set in DNS, and you can set the rest explicitly (apache will have ServerName configured inside virtual hosts, etc).

Tobu
  • 4,367
  • 1
  • 23
  • 31
0

Multi homed systems verses multi domain systems on Linux (or Windows, or any other machine using TCP/IP), two very separate things.

Multi Domain Systems:

The server itself needs only one hostname, and it works muh better if it is not the web server name. Regardless of if you are behind a NAT router, it needs to point to the public IP address that identifies the server, not the private IP address. With multiple IP addresses it needs to point to the primary IP address of the server. Then post the given hostname to be resolved in DNS. Larger companies might have a numbering system. server001, server002, server003, ect.

12.34.56.78 server001.mydomain.com server001
127.0.0.1 localhost.localdomain.local localhost

Adding .local to localhost.localdomain is not required but a prerequisite for setting up multi homed systems. I tend to add it just out of habit. Any other domain will be handled through the web server if setup correctly. Beyond web servers, so long as the DNS IP address points to the server (e-mail, ect) that all that is needed. If you are behind a NAT router, you can setup an internal hostname with .local. Most the time this is not needed but might solve some problems on more difficult systems.

12.34.56.78 server001.mydomain.com server001
10.0.0.78 server001.mydomain.local server001
127.0.0.1 localhost.localdomain.local localhost

Multi Homed Systems:

This is where you physically have multiple network cards connecting to separate networks. Most common would be a public network on one interface, a secured private network on another interface. So for example you may have web services on the public interface and a secured database on a separate server on a private interface. This will work without setting up a multi homed system, but will clear up a ton of SYN TIMEOUT connections if it comes under heavy load. So lets say we have a web server (server001) on 12.34.56.50 : 10.0.0.50 and an internal database server (server002) on 10.0.0.51 Both servers will need to map to the other in /etc/hosts using the .local directive

/etc/hosts server001

12.34.56.50 server001.mydomain.com server001
127.0.0.1 localhost.localdomain.local localhost
10.0.0.50 server.001.mydomain.local server001
10.0.0.51 server002.mydomain.local server002

/etc/hosts server002

10.0.0.1 server002.mydomain.local server002
127.0.0.1 localhost.localdomain.local localhost
10.0.0.50 server.001.mydomain.local server001