Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
o-alquimista opened this issue Jan 16, 2022 · 4 comments
Open
Labels
Priority: High To be addressed after any critical issues

Comments

@o-alquimista
Copy link

o-alquimista commented Jan 16, 2022

What Happened?

/etc/hosts

  • has no entry for the hostname you set in the initial setup (e.g. my-hostname).
  • will contain references to the suggested hostname (e.g. Inspiron-3583-abcdefgh) even if you decide to use a different name.

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

  • Dell Inspiron 15 3583
@joeljosedev
Copy link
Contributor

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

@cassidyjames
Copy link
Contributor

The utility method is here:

public static bool set_hostname (string hostname) {
string? primary_text = null;
string secondary_text = _("Initial Setup could not set your hostname.");
string? error_message = null;
try {
var permission = new Polkit.Permission.sync ("org.freedesktop.hostname1.set-static-hostname", new Polkit.UnixProcess (Posix.getpid ()));
if (permission != null && permission.allowed) {
get_hostname_interface_instance ();
hostname_interface_instance.set_pretty_hostname (hostname, false);
hostname_interface_instance.set_static_hostname (gen_hostname (hostname), false);
} else {
primary_text = _("No Permission to set hostname '%s'").printf (hostname);
}
} catch (GLib.Error e) {
primary_text = _("Unable to set Hostname '%s'").printf (hostname);
error_message = e.message;
}
if (primary_text != null) {
var error_dialog = new Granite.MessageDialog.with_image_from_icon_name (
primary_text,
secondary_text,
"dialog-error",
Gtk.ButtonsType.CLOSE
);
if (error_message != null) {
error_dialog.show_error_details (error_message);
}
error_dialog.run ();
error_dialog.destroy ();
return false;
}
return true;
}

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
Copy link

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
Copy link
Member

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

@davidmhewitt davidmhewitt added this to OS 7 Apr 1, 2022
@davidmhewitt davidmhewitt moved this to Needs Discussion in OS 7 Apr 1, 2022
@danirabbit danirabbit removed this from OS 7 Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High To be addressed after any critical issues
Projects
None yet
Development

No branches or pull requests

5 participants