创建host-only虚拟网卡
VBox管理器页面-管理-主机网络管理器,如果已经存在默认的虚拟网卡则下一步,如果不存在则创建一个虚拟网卡,不启用DHCP服务器,这里ip地址为192.168.137.1,实际我本地设置为192.168.102.1,掩码设置为255.255.255.0。
设置虚拟机master和slave1, slave2为Host-Only模式
配置各台虚拟机的网络
vi /etc/sysconfig/network-scripts/ifcfg-eth0
master
DEVICE=eth0
HWADDR=08:00:27:5D:52:BC
TYPE=Ethernet
UUID=d2cdd853-f19c-4dd7-bfdf-ea6b8a954b54
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.102.3
NETMASK=255.255.255.0
GATEWAY=192.168.102.1
DNS1=192.168.102.1
slave1
DEVICE=eth0
HWADDR=08:00:27:DC:F2:46
TYPE=Ethernet
UUID=14155cf0-7177-4ed7-94cd-5325f9f94c8a
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.102.4
NETMASK=255.255.255.0
GATEWAY=192.168.102.1
DNS1=192.168.102.1
slave2
DEVICE=eth0
HWADDR=08:00:27:DC:F2:46
TYPE=Ethernet
UUID=14155cf0-7177-4ed7-94cd-5325f9f94c8a
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.102.5
NETMASK=255.255.255.0
GATEWAY=192.168.102.1
DNS1=192.168.102.1
重启各台虚拟机网络服务
service network restart
关闭各台虚拟机的防火墙
1. 永久性生效
开启:chkconfig iptables on
关闭:chkconfig iptables off
2. 即时生效,重启后失效
开启:service iptables start
关闭:service iptables stop
Fedora 18以上用一个名叫firewalld的玩意,所以需要:
systemctl stop firewalld.service有必要的话就
systemctl disable firewalld.service
测试互联
[root@master ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:5D:52:BC
inet addr:192.168.102.3 Bcast:192.168.102.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe5d:52bc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2463 errors:0 dropped:0 overruns:0 frame:0
TX packets:1350 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:208042 (203.1 KiB) TX bytes:143877 (140.5 KiB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [root@master ~]# ping 192.168.102.4
PING 192.168.102.4 (192.168.102.4) 56(84) bytes of data.
64 bytes from 192.168.102.4: icmp_seq=1 ttl=64 time=1.14 ms
64 bytes from 192.168.102.4: icmp_seq=2 ttl=64 time=0.350 ms
64 bytes from 192.168.102.4: icmp_seq=3 ttl=64 time=0.246 ms
64 bytes from 192.168.102.4: icmp_seq=4 ttl=64 time=0.267 ms
64 bytes from 192.168.102.4: icmp_seq=5 ttl=64 time=0.223 ms
64 bytes from 192.168.102.4: icmp_seq=6 ttl=64 time=0.256 ms
更全面的说明参考https://blog.csdn.net/hliq5399/article/details/78193113