在Vagrant中设置的IP不在默认位置

发布于 2022-09-04 23:27:44 字数 4586 浏览 23 评论 0

在Windows 10 中使用Vagrant 1.9.2

工作环境使用VPN。

想在Vagrant中指定两个自定义的IP:

Vagrant.configure("2") do |config|                                     
  config.vm.box = "bento/centos-7.3"                                   

  config.vm.provider :virtualbox do |v|                                
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]               
  end                                                                  

  config.vm.define "master", primary: true do |master|                 
    master.vm.network :private_network, ip: "192.168.33.200"           
    master.vm.network :forwarded_port, guest: 22, host: 1234, id: 'ssh'
  end                                                                  

  config.vm.define "node1", autostart: true do |node1|                 
    node1.vm.network :private_network, ip: "192.168.33.201"            
    node1.vm.network :forwarded_port, guest: 22, host: 1235, id: 'ssh' 
  end                                                                  
end

但登陆到master虚拟机时得到以下信息:

[root@localhost ~]# ip a                                                                 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1               
    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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:98:15:79 brd ff:ff:ff:ff:ff:ff                                   
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3                         
       valid_lft 86061sec preferred_lft 86061sec                                         
    inet6 fe80::f7f:ed69:e0f3:2e88/64 scope link                                         
       valid_lft forever preferred_lft forever                                           
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:6c:30:78 brd ff:ff:ff:ff:ff:ff                                   
    inet 192.168.33.200/24 brd 192.168.33.255 scope global enp0s8                        
       valid_lft forever preferred_lft forever                                           
    inet6 fe80::a00:27ff:fe6c:3078/64 scope link                                         
       valid_lft forever preferred_lft forever                                           
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN        
    link/ether 02:42:3c:df:fa:b0 brd ff:ff:ff:ff:ff:ff                                   
    inet 172.17.0.1/16 scope global docker0                                              
       valid_lft forever preferred_lft forever            
                                      
[root@localhost ~]# ip route                                                             
default via 10.0.2.2 dev enp0s3  proto static  metric 100                                
10.0.2.0/24 dev enp0s3  proto kernel  scope link  src 10.0.2.15  metric 100              
169.254.0.0/16 dev enp0s8  scope link  metric 1003                                       
172.17.0.0/16 dev docker0  proto kernel  scope link  src 172.17.0.1                      
192.168.33.0/24 dev enp0s8  proto kernel  scope link  src 192.168.33.200  

[root@localhost ~]# ls /etc/sysconfig/network-scripts/ifcfg-
ifcfg-enp0s3  ifcfg-enp0s8    ifcfg-lo

node1可以ssh登陆到master:

[root@localhost ~]# ssh vagrant@192.168.33.200
The authenticity of host '192.168.33.200 (192.168.33.200)' can't be established.
ECDSA key fingerprint is 04:9d:3e:eb:4e:7b:14:17:2d:e8:18:0d:80:ab:71:9c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.33.200' (ECDSA) to the list of known hosts.
vagrant@192.168.33.200's password:
Last login: Wed May 24 01:09:34 2017 from 10.0.2.2
[vagrant@localhost ~]$

这里的带有自定义IP(192.168.33.200)的enp0s8网络为什么没在默认位置?
即使从Vagrantfile中移除这行:

v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]

还是一样的结果。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文