Ask Your Question
1

hostname is different from /etc/hostname and /etc/hosts

asked 2015-07-19 08:46:13 -0600

updated 2015-07-19 08:47:34 -0600

On a new system install of Fedora 22 KDE my hostname was initially localhost but it changed on its own. It is now dhcpp5. There is no mention of it in /etc/hostname or /etc/hosts. Is that some new naming scheme or a bug?

[sudhir@dhcppc5 ~]$ hostname
dhcppc5
[sudhir@dhcppc5 ~]$ cat /etc/hostname
localhost.localdomain
[sudhir@dhcppc5 ~]$ cat /etc/hosts
127.0.0.1               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
edit retag flag offensive close merge delete

Comments

1

Just for your information, /etc/hosts has nothing to do with your computer's hostname. It's there to provide static resolution of host names to IP addresses without needing DNS. As an example, if a domain's records aren't properly updated you can add the correct info to the file so that you can reach the site. And, of course, if you want to make a site permanently unreachable, you can add an entry giving it an IP of 127.0.0.1 so that you'll never get there again, even by accident or an auto-redirect.

sideburns gravatar imagesideburns ( 2015-07-19 11:21:39 -0600 )edit

Is it advisable to add hostname to /etc/hosts as it happens with a new system install?

sudhirkhanger gravatar imagesudhirkhanger ( 2015-07-19 12:00:33 -0600 )edit

Not unless you expect to need to connect to your own machine by name instead of just using localhost.

sideburns gravatar imagesideburns ( 2015-07-19 12:44:53 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-07-19 08:55:38 -0600

NickTux gravatar image

The hostname of the machine is being managed from systemd and hostnamectl command. There is no need to use any other tool or edit manually any file (basically it's not recommended).

If you want to set the hostname for your system you can do it like this (as root):

# hostnamectl set-hostname --static "YOUR-HOSTNAME-HERE"

reboot the system and see

$ hostnamectl

command output.

Sometimes SELinux playing its own game, you can use

# restorecon -v /etc/hostname

if you have any problems related to hostname changing.

edit flag offensive delete link more

Comments

I had already done that but I wasn't sure why system assigned a different hostname then one in /etc/hostname. Thanks.

sudhirkhanger gravatar imagesudhirkhanger ( 2015-07-19 11:56:18 -0600 )edit

Sometimes your dhcp server will provide a hostname when provisioning an IP, known as a transient hostname in hostnamectl parlance. It's a valuable feature for environments where these things can be centrally configured.

randomuser gravatar imagerandomuser ( 2015-07-19 15:46:13 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-07-19 08:46:13 -0600

Seen: 4,313 times

Last updated: Jul 19 '15