diff --git a/lib/vagrant/systems/redhat.rb b/lib/vagrant/systems/redhat.rb index a86908561..8a854fc00 100644 --- a/lib/vagrant/systems/redhat.rb +++ b/lib/vagrant/systems/redhat.rb @@ -26,15 +26,14 @@ module Vagrant def change_host_name(name) vm.ssh.execute do |ssh| - host_name_already_set = ssh.test?("sudo hostname | grep '#{name}'") - ssh.exec!("sudo sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network") unless host_name_already_set - ssh.exec!("sudo hostname #{name}") unless host_name_already_set + # Only do this if the hostname is not already set + if !ssh.test?("sudo hostname | grep '#{name}'") + ssh.exec!("sudo sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/sysconfig/network") + ssh.exec!("sudo hostname #{name}") + ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts") + end end end - end end end - - -