diff --git a/plugins/guests/gentoo/cap/change_host_name.rb b/plugins/guests/gentoo/cap/change_host_name.rb index 36377e077..bf79d02a3 100644 --- a/plugins/guests/gentoo/cap/change_host_name.rb +++ b/plugins/guests/gentoo/cap/change_host_name.rb @@ -9,8 +9,14 @@ module VagrantPlugins basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, "") # Set the hostname - hostname '#{basename}' - echo "hostname=#{basename}" > /etc/conf.d/hostname + + # Use hostnamectl on systemd + if [[ `systemctl` =~ -\.mount ]]; then + systemctl set-hostname '#{name}' + else + hostname '#{basename}' + echo "hostname=#{basename}" > /etc/conf.d/hostname + fi # Remove comments and blank lines from /etc/hosts sed -i'' -e 's/#.*$//' /etc/hosts