最近开始使用Vagrant来快速安装虚拟机。我注意到我的网络配置并不完美,但我无法做到正确。
这是我的 Vagrantfile:
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt'
Vagrant.configure("2") do |config|
config.vm.box = "debian/jessie64"
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
config.vm.provider "libvirt" do |lv|
lv.driver = "kvm"
end #config.vm.provider
#how many hosts to deploy?
n = 1
(10..n+9).each do |i|
config.vm.define "#{i}" do |vs|
vs.vm.hostname = "vs-#{i}"
vs.vm.network "private_network", ip: "10.0.0.#{i}"
end #config.vm.define
end #loop
#copy local ssh key to vm with ansible
config.vm.provision :ansible do |ansible|
ansible.playbook = "vagrant-provision.yml"
## Debugging
#ansible.verbose = true
#ansible.verbose="vvvvv"
end
end #Vagrant.configure
我的盒子启动正确,并且也可以通过定义的 IP 地址 (10.0.0.X) 访问,但该地址位于 eth1 上。 Vagrant 首先创建另一个接口 eth0,该接口接收 192.168.121.XXX 地址。我想摆脱这个,但我不知道如何。
这是的输出流浪者 ssh 配置:
$ vagrant ssh-config
Host 10
HostName 192.168.121.148
User vagrant
Port 22
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/max/vagrant/vs/.vagrant/machines/10/libvirt/private_key
IdentitiesOnly yes
LogLevel FATAL
这是来自虚拟机内部的:
root@vs-10:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:b1:1f:fd brd ff:ff:ff:ff:ff:ff
inet 192.168.121.148/24 brd 192.168.121.255 scope global dynamic eth0
valid_lft 3503sec preferred_lft 3503sec
inet6 fe80::5054:ff:feb1:1ffd/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:c8:05:48 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.10/24 brd 10.0.0.255 scope global eth1
valid_lft forever preferred_lft forever
root@vs-10:~# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth1
iface eth1 inet static
address 10.0.0.10
netmask 255.255.255.0
#VAGRANT-END
如您所见,我的 Vagrantfile 中定义的地址已插入到接口文件中,但对于 eth1。 eth0 没有在那里定义,但当我运行时仍然显示IP地址。我想在接口 eth0 上使用地址 10.0.0.10 并去掉 192.168.121.XXX 地址。