/etc/hostname vs /etc/hosts vs /etc/sysconfig/network in centos7
I find that I can put different hostnames in following three files. Can anyone help explain when and how to use each of them? It is a CentOS7 box.
/etc/hostname # run command hostname - I suspect this is the actual hostname
/etc/hosts #for 127.0.0.1 only?
/etc/sysconfig/network 3 1 Answer
/etc/hosts is for defining your own domain names for certain IP addresses. It commonly has this entry:
127.0.0.1 localhostThat 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 localhostAnd 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/networkfile is used to specify information about the desired network configuration.
()
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.