創建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