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?
Putting
localhost
in/etc/hostname
andin
/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).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.
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.
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
/etc/hosts server002