[vagrant]vagrant centos静态ip设置

vagrant 中使用的是public_network,而工作网络中,由于桥接了很多路由器,导致ip段位和本机的ip段位不在同一个局域网中

ifconfig之后的结果

[root@localhost network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:5A:FB:02
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe5a:fb02/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1269 errors:0 dropped:0 overruns:0 frame:0
TX packets:780 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:113182 (110.5 KiB) TX bytes:90192 (88.0 KiB) eth1 Link encap:Ethernet HWaddr 08:00:27:65:77:09
inet addr:192.168.200.102 Bcast:192.168.200.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe65:7709/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:783 errors:0 dropped:0 overruns:0 frame:0
TX packets:20 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:49649 (48.4 KiB) TX bytes:2040 (1.9 KiB)

主要修改eth1,在本机中是/etc/sysconfig/network-scripts/ifcfg-eth1.

BOOTPROTO=static
ONBOOT=yes
DEVICE=eth1
IPADDR=192.168.1.119
GATEWAY=192.168.1.1
NETMASK=255.255.255.0

重启网络

service network restart

方法二修改Vagrantfile,将public_network固定一个ip地址。如

config.vm.network "public_network", ip: "192.168.1.119"

参考:

  1. Centos 7 学习之静态IP设置
  2. Public Networks
上一篇:c++四舍五入的新方法


下一篇:(转)TCP和UDP之间的区别