更改网络后 Vagrant 无法启动

Vagrant can't start after changing network

我使用 vagrant 按照本指南安装 KVM:

https://www.cyberciti.biz/faq/installing-kvm-on-ubuntu-16-04-lts-server/

此处更改了桥接网络:

Step 3: Configure bridged networking

$ sudo cp /etc/network/interfaces /etc/network/interfaces.bakup-1-july-2016
$ sudo vi /etc/network/interfaces

auto br1
iface br0 inet static
     address 10.18.44.26
     netmask 255.255.255.192
     broadcast 10.18.44.63
     dns-nameservers 10.0.80.11 10.0.80.12
     # set static route for LAN
     post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.18.44.1
     post-up route add -net 161.26.0.0 netmask 255.255.0.0 gw 10.18.44.1
     bridge_ports eth0
     bridge_stp off
     bridge_fd 0
     bridge_maxwait 0

# br1 setup with static wan IPv4 with ISP router as a default gateway
auto br1
iface br1 inet static
     address 208.43.222.51
     netmask 255.255.255.248
     broadcast 208.43.222.55
     gateway 208.43.222.49
     bridge_ports eth1
     bridge_stp off
     bridge_fd 0
     bridge_maxwait 0

$ sudo systemctl restart networking

当我重新启动 vagrant 时,它总是停在这里:

$ vagrant up                                                                  
==> default: Attempting graceful shutdown of VM...                                
    default: Guest communication could not be established! This is usually because
    default: SSH is not running, the authentication information was changed,      
    default: or some other networking issue. Vagrant will force halt, if          
    default: capable.                                                             
==> default: Forcing shutdown of VM...                                            
==> default: Clearing any previously set forwarded ports...                       
==> default: Clearing any previously set network interfaces...                    
==> default: Preparing network interfaces based on configuration...               
    default: Adapter 1: nat                                                       
    default: Adapter 2: hostonly                                                  
==> default: Forwarding ports...                                                  
    default: 22 (guest) => 2222 (host) (adapter 1)                                
==> default: Running 'pre-boot' VM customizations...                              
==> default: Booting VM...                                                        
==> default: Waiting for machine to boot. This may take a few minutes...          
    default: SSH address: 127.0.0.1:2222                                          
    default: SSH username: vagrant                                                
    default: SSH auth method: private key                                         
Timed out while waiting for the machine to boot. This means that                  
Vagrant was unable to communicate with the guest machine within                   
the configured ("config.vm.boot_timeout" value) time period.                      

If you look above, you should be able to see the error(s) that                    
Vagrant had when attempting to connect to the machine. These errors               
are usually good hints as to what may be wrong.                                   

If you're using a custom box, make sure that networking is properly               
working and you're able to connect to the machine. It is a common                 
problem that networking isn't setup properly in these boxes.                      
Verify that authentication configurations are also setup properly,                
as well.                                                                          

If the box appears to be booting properly, you may want to increase               
the timeout ("config.vm.boot_timeout") value.

如何解决?

如果您使用的是 vagrant,则不需要进行这些修改,您只需在 Vagrantfile 中更改网络配置(参见 Public Networks)并进行更改

Vagrant.configure("2") do |config|
  ...
  config.vm.network "public_network"
  ...
end

vagrant 会注意更新正确的配置文件