/etc/hosts
is for defining your own domain names for certain IP addresses. It commonly has this entry:
127.0.0.1 localhost
That means that localhost
, when used in a browser or other program that accesses the internet, should be directed to 127.0.0.1
. It's like having your own local DNS server (that nobody else can use). You can also add more than one name:
127.0.0.1 local localhost
And it doesn't need to be just 127.0.0.1. You can put any number of names to whatever IP addresses you want.
/etc/hostname
is how you specify your computer’s hostname. That is used for many things such as in Bluetooth-enabled computers, that’s the name other devices see. There are a lot of other uses; I recommend you take a look at that Server Fault post I linked. As mentioned by ivanivan, your hostname should be resolvable, so that should be in /etc/hosts
next to localhost
.
The /etc/sysconfig/network
file is used to specify information about the desired network configuration.
(https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-sysconfig-network.html)
I’ve actually never seen this file before (I run Debian, not CentOS), but it appears to be basically a broader form of /etc/hostname
that lets you set more options. It appears that it is also newer than /etc/hostname
, but /etc/hostname
is still there to support older software.
man 5 hosts
,man 5 hostname
andman 5 networks