2

I have four network card on my server, I have assigned each with an specific IP now I want to set an different hostname for all the interface?

What is the difference between setting the hostname in file /etc/sysconfig/network or /etc/hosts?

4

The entry in /etc/sysconfig/network is where RHEL (and derivatives such as CentOS) set the hostname/nodename that you'll see reflected on for instance the prompt of your shell, in system and log messages etc. That is the hostname that will be returned by the gethostname(2) and uname system calls.

A system only has one hostname/nodename, but it can have many interfaces.

You can point unlimited hostnames (or rather DNS names) to each interface, each ip-address. A many-to-one relationship.

The reverse mapping from ip-address to DNS name is one-to-one. A reverse DNS lookup (using a PTR record or the same using /etc/hosts) will only return one name.

The /etc/hosts file is simply a local lookup table mapping ip-adresses to hostnames and the reverse. If you have a functional DNS server that will often be easier to maintain that rather then keeping many hosts files on different systems in sync.

Some network services will start slowly, fail and/or give warnings if they can not resolve the hostname to an ip-address. (i.e. when being started in single user mode or when DNS fails to respond) so it is not uncommon to see /etc/hosts contains a reference to the hostname as well.

Often the /etc/hosts entry takes precedence over DNS allowing you to locally do "interesting" things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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