From 3082ea502e2d7ad314d78cb0af5d71cc36bc42bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Fri, 26 Jan 2018 12:02:17 +0100 Subject: [PATCH] Debian: Point hostname to 127.0.1.1 in /etc/hosts Closes #9403 --- plugins/guests/debian/cap/change_host_name.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/guests/debian/cap/change_host_name.rb b/plugins/guests/debian/cap/change_host_name.rb index 8f31341b7..6cba5f34c 100644 --- a/plugins/guests/debian/cap/change_host_name.rb +++ b/plugins/guests/debian/cap/change_host_name.rb @@ -18,7 +18,11 @@ module VagrantPlugins # Prepend ourselves to /etc/hosts grep -w '#{name}' /etc/hosts || { - sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts + if grep -w '^127\\.0\\.1\\.1' /etc/hosts ; then + sed -i'' 's/^127\\.0\\.1\\.1\\s.*$/127.0.1.1\\t#{name}\\t#{basename}/' /etc/hosts + else + sed -i'' '1i 127.0.1.1\\t#{name}\\t#{basename}' /etc/hosts + fi } # Update mailname