elementary / initial-setup

New user setup app designed for elementary OS
https://elementary.io
GNU General Public License v3.0
36 stars 12 forks source link

/etc/hosts not updated to reflect hostname set on initial setup #135

Open o-alquimista opened 2 years ago

o-alquimista commented 2 years ago

What Happened?

/etc/hosts

Steps to Reproduce

  1. Install elementary, get to the initial setup
  2. In the last step, where you create a new user, define a custom hostname, such as my-hostname. The hostname field will be pre-filled with something like Inspiron-3583-abcdefgh; delete that and set a custom name instead.
  3. Login as that user and run cat /etc/hosts

Expected Behavior

Expected contents of /etc/hosts:

127.0.0.1 my-hostname.localdomain my-hostname localhost.localdomain localhost
::1 my-hostname.localdomain my-hostname localhost.localdomain localhost

Actual contents of /etc/hosts:

127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
127.0.0.1 Inspiron-3583-abcdefgh.localdomain Inspiron-3583-abcdefgh

It's a bit messy too, right? But the relevant problem here is the absence of my-hostname.

OS Version

6.1 (Jólnir)

Software Version

Latest release (I have run all updates)

Log Output

No response

Hardware Info

joeljosedev commented 2 years ago

I believe this method is responsible for setting the hostname when the uesr clicks on the Finish Setup button.

cassidyjames commented 2 years ago

The utility method is here:

https://github.com/elementary/initial-setup/blob/e34c159d4e5d46b6d74a560ed59c47861c610c5a/src/Utils.vala#L186-L226

If I'm reading this correctly, we just use org.freedesktop.hostname1.set-static-hostname and don't manually do anything else to set the hostname; I'd imagine the FreeDesktop DBus interface should handle that?

pridumkuvatyj commented 2 years ago

Also this proposed device name Inspiron-3583-abcdefgh is used in syslog and maybe other logs.

I have a bit more strange behavior. During installation I changed proposed Lenovo-IdeaPad-Y580-d4dce24c to prid-PC. Later during Dropbox authentication it showed me a pridPC name without a dash. And the /etc/hostname, /etc/hosts files contained only the initially proposed Lenovo-IdeaPad-Y580-d4dce24c name. After changing manually the name in these 2 files and rebooting several times, I've noticed the Lenovo-IdeaPad-Y580-d4dce24c name in syslog: Jan 25 02:29:42 Lenovo-IdeaPad-Y580-d4dce24c kernel: [26215.856346] [UFW BLOCK] ...

Something strange is going on with the device name.

davidmhewitt commented 2 years ago

This causes a secondary problem where sudo commands are really slow if you choose anything other than the default hostname. See the following for reference: https://stackoverflow.com/questions/22249688/linux-sudo-is-working-slow-after-changing-the-hostname