diff --git a/plugins/guests/debian/cap/configure_networks.rb b/plugins/guests/debian/cap/configure_networks.rb index 49da980bf..3cb896b15 100644 --- a/plugins/guests/debian/cap/configure_networks.rb +++ b/plugins/guests/debian/cap/configure_networks.rb @@ -13,9 +13,8 @@ module VagrantPlugins machine.communicate.tap do |comm| # First, remove any previous network modifications # from the interface file. - comm.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces") - comm.sudo("su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'") - comm.sudo("rm -f /tmp/vagrant-network-interfaces") + comm.sudo("sed -e '/^#VAGRANT-BEGIN/,$ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces.pre") + comm.sudo("sed -ne '/^#VAGRANT-END/,$ p' /etc/network/interfaces | tail -n +2 > /tmp/vagrant-network-interfaces.post") # Accumulate the configurations to add to the interfaces file as # well as what interfaces we're actually configuring since we use that @@ -47,8 +46,8 @@ module VagrantPlugins comm.sudo("/sbin/ip addr flush dev eth#{interface} 2> /dev/null") end - comm.sudo("cat /tmp/vagrant-network-entry >> /etc/network/interfaces") - comm.sudo("rm -f /tmp/vagrant-network-entry") + comm.sudo('cat /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post > /etc/network/interfaces') + comm.sudo('rm -f /tmp/vagrant-network-interfaces.pre /tmp/vagrant-network-entry /tmp/vagrant-network-interfaces.post') # Bring back up each network interface, reconfigured interfaces.each do |interface|