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

setting the hostname on CentOS 7 #4352

Closed
pazooki opened this issue Aug 15, 2014 · 10 comments
Closed

setting the hostname on CentOS 7 #4352

pazooki opened this issue Aug 15, 2014 · 10 comments

Comments

@pazooki
Copy link

pazooki commented Aug 15, 2014

Apparently the right way to set the hostname in el7 is by using hostnamectl.
hostnamectl set-hostname {{ your_hostname }}

right now vagrant can't set hostname for Centos 7 ...

@spkane
Copy link

spkane commented Aug 16, 2014

I can second this problem.

A line like

config.vm.host_name = 'test-target-1.example.com'

causes something like this:

==> default: Setting hostname...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

service network restart

Stdout from the command:

Restarting network (via systemctl):  [FAILED]


Stderr from the command:

Job for network.service failed. See 'systemctl status network.service' and 'journalctl -xn' for details.

@jayjanssen
Copy link

+1

@mitchellh
Copy link
Contributor

So right now, its a complicated process to change the hostname:

  1. Update sysconfig
  2. Update hostname via sudo hostname
  3. Update /etc/hosts
  4. Update DHCP_HOSTNAME in /etc/sysconfig
  5. Restart networking.

Does the hostnamectl command replace a single step above, or all of them?

@pazooki
Copy link
Author

pazooki commented Aug 31, 2014

@mitchellh I think that's the case. I just did "homenamectl set-hostname <my_host_name>" and that was it. systemd takes care of the rest..

Here is the man page:

HOSTNAMECTL(1) hostnamectl HOSTNAMECTL(1)

NAME
hostnamectl - Control the system hostname

SYNOPSIS
hostnamectl [OPTIONS...] {COMMAND}

DESCRIPTION
hostnamectl may be used to query and change the system hostname and related settings.

  This tool distinguishes three different hostnames: the high-level "pretty" hostname which might include all kinds of special characters (e.g.
  "Lennart's Laptop"), the static hostname which is used to initialize the kernel hostname at boot (e.g. "lennarts-laptop"), and the transient
  hostname which might be assigned temporarily due to network configuration and might revert back to the static hostname if network connectivity is
  lost and is only temporarily written to the kernel hostname (e.g. "dhcp-47-11").

  Note that the pretty hostname has little restrictions on the characters used, while the static and transient hostnames are limited to the usually
  accepted characters of Internet domain names.

  The static hostname is stored in /etc/hostname, see hostname(5) for more information. The pretty hostname, chassis type, and icon name are stored
  in /etc/machine-info, see machine-id(5).

UPDATE:
There is also an issue with network card names on CentOS 7. in order to get it to work you need to use the old style naming (eth0, eth1, ...). That was probably a VirtualBox issue.
http://wiki.centos.org/FAQ/CentOS7#head-31ebc6642958a0df12304d6aab9a49034a3b7802

@mitchellh
Copy link
Contributor

Fixed. Thanks @pazooki

@biemond
Copy link

biemond commented Sep 4, 2014

I get this error with the latest vagrant.

 The following SSH command responded with a non-zero exit status.
 Vagrant assumes that this means the command failed!

 homenamectl set-hostname admin.example.com
 bash: line 2: homenamectl: command not found

it should be hostnamectl set-hostname xxx.example.com
and not homenamectl

Thanks

@pazooki
Copy link
Author

pazooki commented Sep 4, 2014

Oh my bad!! apparently someone else mentioned that:
41f4ec1

@biemond
Copy link

biemond commented Sep 4, 2014

Also another problem with centos 7.0 by setting the hostname in vagrant like this
admin.vm.hostname = "admin.example.com"

This should also updates the /etc/hosts file, this does not happen in centos 7.0 ( with centos 6.5 it works)

uname -a is ok but when using puppet it fails because facter fqdn says admin.lan instead of admin.example.com

uname -a
Linux admin.example.com 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

[vagrant@admin ~]$ sudo facter fqdn
admin.lan

@dmacvicar
Copy link
Contributor

So this has to be fixed duplicating the hostnamectl call in all every distro that uses systemd?. I noticed arch also has this code and SLES-12 still fails.

Is copy-paste the call to a guest plugin the right approach?

Or said differently, is there a way we could detect systemd and have a set of capabilities in common for all systemd based distros?

@jdiez17
Copy link

jdiez17 commented Mar 23, 2016

+1, all distros that use systemd set the hostname via hostnamectl. I just ran into this issue on a Fedora 23 Server box, where Vagrant sets the hostname by writing to /etc/hostname (see here). This is interpreted as a "transient hostname" and does not persist across reboots.

@hashicorp hashicorp locked and limited conversation to collaborators Mar 23, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants