linux虚拟机如何配置网卡信息(确保两台服务器通信)
1、分别使用vmware将两台linux虚拟机还原至安装的初始状态(前提是已经创建快照,实验目的是配置网卡信息,确保两台主机可以通信,因此需要两台虚拟机)
2、为了更加清晰的分辨两台主机,先分别配置主机名称,并查看系统版本
[root@linuxprobe Desktop]# vim /etc/hostname ## 修改虚拟机1主机名称
host1
[root@linuxprobe Desktop]# hostname ## 查看
host1
[root@linuxprobe Desktop]# hostnamectl ## 查看系统信息
Static hostname: host1
Icon name: computer
Chassis: n/a
Machine ID: 3475295383774df4b83491fd573fbbc2
Boot ID: 71ab80ee01054f5b84d6cd935259a977
Virtualization: vmware
Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server
Kernel: Linux 3.10.0-123.el7.x86_64
Architecture: x86_64
[root@linuxprobe Desktop]# reboot ## 重启,是主机名称生效
[root@linuxprobe Desktop]# vim /etc/hostname ## 修改虚拟机2主机名称
host2
[root@linuxprobe Desktop]# hostname ## 查看
host2
[root@linuxprobe Desktop]# hostnamectl ## 查看系统版本信息,也是RHEL7
Static hostname: linuxprobe.com
Icon name: computer
Chassis: n/a
Machine ID: 94333412b1ab4fb8b024d9b7038e4caa
Boot ID: 3998b9eeab3f45ffa78549f214f057ae
Virtualization: vmware
Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server
Kernel: Linux 3.10.0-123.el7.x86_64
Architecture: x86_64
[root@linuxprobe Desktop]# reboot ## 重启使主机名称生效
2、分别查看两台虚拟机的网卡信息
[root@host1 Desktop]# ifconfig ## 查看虚拟机1网卡信息,有网卡名称,MAC地址,但是没有IP信息
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:e4:f7:b9 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 658 bytes 51740 (50.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 658 bytes 51740 (50.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@host2 Desktop]# ifconfig ## 查看虚拟机2的网卡信息,有网卡名称,MAC地址,但是没有IP
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:aa:2b:29 txqueuelen 1000 (Ethernet)
RX packets 1 bytes 243 (243.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 530 bytes 41628 (40.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 530 bytes 41628 (40.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
3、分别修改两台虚拟机的网卡配置文件
[root@host1 Desktop]# cd /etc/sysconfig/network-scripts/ ## 进入虚拟机1网卡配置文件目录
[root@host1 network-scripts]# ls
ifcfg-eno16777728 ifdown-ippp ifdown-routes ifup ifup-ipv6 ifup-ppp ifup-tunnel
ifcfg-lo ifdown-ipv6 ifdown-sit ifup-aliases ifup-isdn ifup-routes ifup-wireless
ifdown ifdown-isdn ifdown-Team ifup-bnep ifup-plip ifup-sit init.ipv6-global
ifdown-bnep ifdown-post ifdown-TeamPort ifup-eth ifup-plusb ifup-Team network-functions
ifdown-eth ifdown-ppp ifdown-tunnel ifup-ippp ifup-post ifup-TeamPort network-functions-ipv6
[root@host1 network-scripts]# vim ifcfg-eno16777728 ## 编辑配置文件
TYPE=Ethernet
BOOTPROTO=static
NAME=eno16777728
ONBOOT=yes
IPADDR=192.168.10.10
NETMASK=255.255.255.0
GATEWAY=192.168.10.1
DNS1=192.168.10.1
## 参数解释
##TYPE:网络类型
##BOOTPROTO:地址分配模式
##NAME:网卡名臣
##ONBOOT:是否开机自动重启网卡
##IPADDR:IP地州
##NETMADK:子网掩码
##GATEWAY:网关地址
##DNS1:DNS地址
[root@host1 network-scripts]# ifconfig ## 查看网卡重启前网卡信息
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:e4:f7:b9 txqueuelen 1000 (Ethernet)
RX packets 5 bytes 762 (762.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 786 bytes 61852 (60.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 786 bytes 61852 (60.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@host1 network-scripts]# systemctl restart network ## 重启网卡
[root@host1 network-scripts]# ifconfig ## 查看网卡重启后网卡信息,多出了IP信息
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fee4:f7b9 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:e4:f7:b9 txqueuelen 1000 (Ethernet)
RX packets 5 bytes 762 (762.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 26 bytes 3600 (3.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 793 bytes 62618 (61.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 793 bytes 62618 (61.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@host1 network-scripts]# ping -c 3 192.168.10.10 ## 本地主机测试网络联通性,联通
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.056 ms
64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.040 ms
64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.042 ms
--- 192.168.10.10 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.040/0.046/0.056/0.007 ms
[root@host2 Desktop]# cd /etc/sysconfig/network-scripts/ ## 进入虚拟机2网卡配置文件所在目录
[root@host2 network-scripts]# ls
ifcfg-eno16777728 ifdown-bnep ifdown-ipv6 ifdown-ppp ifdown-Team ifup ifup-eth ifup-isdn ifup-post ifup-sit ifup-tunnel network-functions
ifcfg-lo ifdown-eth ifdown-isdn ifdown-routes ifdown-TeamPort ifup-aliases ifup-ippp ifup-plip ifup-ppp ifup-Team ifup-wireless network-functions-ipv6
ifdown ifdown-ippp ifdown-post ifdown-sit ifdown-tunnel ifup-bnep ifup-ipv6 ifup-plusb ifup-routes ifup-TeamPort init.ipv6-global
[root@host2 network-scripts]# vim ifcfg-eno16777728 ## 编辑配置文件
TYPE=Ethernet
BOOTPROTO=static
NAME=eno16777728
ONBOOT=yes
IPADDR=192.168.10.20
NETMASK=255.255.255.0
GATEWAY=192.168.10.1
DNS1=192.168.10.1
[root@host2 network-scripts]# ifconfig ## 查看重启网卡前网卡信息
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:aa:2b:29 txqueuelen 1000 (Ethernet)
RX packets 104 bytes 6885 (6.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 914 bytes 71964 (70.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 914 bytes 71964 (70.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@host2 network-scripts]# systemctl restart network ## 重启网卡
[root@host2 network-scripts]# ifconfig ## 查看网卡重启后网卡信息,多出了IP信息
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.20 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:feaa:2b29 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:aa:2b:29 txqueuelen 1000 (Ethernet)
RX packets 104 bytes 6885 (6.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 26 bytes 3736 (3.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 921 bytes 72730 (71.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 921 bytes 72730 (71.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@host2 network-scripts]# ping 192.168.10.20 ## 本地主机测试联通性,联通
PING 192.168.10.20 (192.168.10.20) 56(84) bytes of data.
64 bytes from 192.168.10.20: icmp_seq=1 ttl=64 time=0.031 ms
64 bytes from 192.168.10.20: icmp_seq=2 ttl=64 time=0.056 ms
64 bytes from 192.168.10.20: icmp_seq=3 ttl=64 time=0.041 ms
64 bytes from 192.168.10.20: icmp_seq=4 ttl=64 time=0.042 ms
^C
--- 192.168.10.20 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.031/0.042/0.056/0.011 ms
4、测试虚拟机1和虚拟机2是否联通
[root@host1 network-scripts]# ifconfig | head -n 3 ## 查看虚拟机1 IP
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fee4:f7b9 prefixlen 64 scopeid 0x20<link>
[root@host1 network-scripts]# ping -c 5 192.168.10.20 ## 测试虚拟机1和虚拟机2的联通性,联通
PING 192.168.10.20 (192.168.10.20) 56(84) bytes of data.
64 bytes from 192.168.10.20: icmp_seq=1 ttl=64 time=0.423 ms
64 bytes from 192.168.10.20: icmp_seq=2 ttl=64 time=0.187 ms
64 bytes from 192.168.10.20: icmp_seq=3 ttl=64 time=0.209 ms
64 bytes from 192.168.10.20: icmp_seq=4 ttl=64 time=0.220 ms
64 bytes from 192.168.10.20: icmp_seq=5 ttl=64 time=0.199 ms
--- 192.168.10.20 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4001ms
rtt min/avg/max/mdev = 0.187/0.247/0.423/0.090 ms
[root@host2 network-scripts]# ifconfig | head -n 3 ## 查看虚拟机2IP
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.20 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:feaa:2b29 prefixlen 64 scopeid 0x20<link>
[root@host2 network-scripts]# ping -c 5 192.168.10.10 ## 测试联通性,联通
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.272 ms
64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.246 ms
64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.219 ms
64 bytes from 192.168.10.10: icmp_seq=4 ttl=64 time=0.230 ms
64 bytes from 192.168.10.10: icmp_seq=5 ttl=64 time=0.255 ms
--- 192.168.10.10 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4002ms
rtt min/avg/max/mdev = 0.219/0.244/0.272/0.023 ms
5、修改虚拟机1网卡IP,测试和虚拟机2的联通性
[root@host1 network-scripts]# ls
ifcfg-eno16777728 ifdown-ippp ifdown-routes ifup ifup-ipv6 ifup-ppp ifup-tunnel
ifcfg-lo ifdown-ipv6 ifdown-sit ifup-aliases ifup-isdn ifup-routes ifup-wireless
ifdown ifdown-isdn ifdown-Team ifup-bnep ifup-plip ifup-sit init.ipv6-global
ifdown-bnep ifdown-post ifdown-TeamPort ifup-eth ifup-plusb ifup-Team network-functions
ifdown-eth ifdown-ppp ifdown-tunnel ifup-ippp ifup-post ifup-TeamPort network-functions-ipv6
[root@host1 network-scripts]# vim ifcfg-eno16777728 ## 修改配置文件
TYPE=Ethernet
BOOTPROTO=static
NAME=eno16777728
ONBOOT=yes
IPADDR=192.168.3.10
NETMASK=255.255.255.0
GATEWAY=192.168.3.1
DNS1=192.168.3.1
[root@host1 network-scripts]# ifconfig ## 查看重启网卡前网卡信息
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fee4:f7b9 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:e4:f7:b9 txqueuelen 1000 (Ethernet)
RX packets 140 bytes 12075 (11.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 231 bytes 16610 (16.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 931 bytes 75480 (73.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 931 bytes 75480 (73.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@host1 network-scripts]# systemctl restart network ## 重启网卡
[root@host1 network-scripts]# ifconfig ## 查看重启网卡后网卡信息,IP信息发生变化
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.10 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::20c:29ff:fee4:f7b9 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:e4:f7:b9 txqueuelen 1000 (Ethernet)
RX packets 140 bytes 12075 (11.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 257 bytes 20056 (19.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 942 bytes 76666 (74.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 942 bytes 76666 (74.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@host1 network-scripts]# ping -c 3 192.168.3.10 ## 测试本地联通性,联通
PING 192.168.3.10 (192.168.3.10) 56(84) bytes of data.
64 bytes from 192.168.3.10: icmp_seq=1 ttl=64 time=0.031 ms
64 bytes from 192.168.3.10: icmp_seq=2 ttl=64 time=0.041 ms
64 bytes from 192.168.3.10: icmp_seq=3 ttl=64 time=0.043 ms
--- 192.168.3.10 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.031/0.038/0.043/0.007 ms
[root@host1 network-scripts]# ping -c 3 192.168.10.20 ## 测试和虚拟机2的连通性,不联通
PING 192.168.10.20 (192.168.10.20) 56(84) bytes of data.
From 192.168.3.10 icmp_seq=1 Destination Host Unreachable
From 192.168.3.10 icmp_seq=2 Destination Host Unreachable
From 192.168.3.10 icmp_seq=3 Destination Host Unreachable
--- 192.168.10.20 ping statistics ---
3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 1999ms
pipe 3
6、修改虚拟机2网卡IP,测试和虚拟机1的连通性
[root@host2 network-scripts]# ls
ifcfg-eno16777728 ifdown-bnep ifdown-ipv6 ifdown-ppp ifdown-Team ifup ifup-eth ifup-isdn ifup-post ifup-sit ifup-tunnel network-functions
ifcfg-lo ifdown-eth ifdown-isdn ifdown-routes ifdown-TeamPort ifup-aliases ifup-ippp ifup-plip ifup-ppp ifup-Team ifup-wireless network-functions-ipv6
ifdown ifdown-ippp ifdown-post ifdown-sit ifdown-tunnel ifup-bnep ifup-ipv6 ifup-plusb ifup-routes ifup-TeamPort init.ipv6-global
[root@host2 network-scripts]# vim ifcfg-eno16777728 ## 编辑虚拟机2的网卡配置文件
TYPE=Ethernet
BOOTPROTO=static
NAME=eno16777728
ONBOOT=yes
IPADDR=192.168.3.20
NETMASK=255.255.255.0
GATEWAY=192.168.3.1
DNS1=192.168.3.1
[root@host2 network-scripts]# ifconfig ## 查看重启网卡前网卡信息
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.20 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:feaa:2b29 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:aa:2b:29 txqueuelen 1000 (Ethernet)
RX packets 331 bytes 23607 (23.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 135 bytes 10795 (10.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 997 bytes 79808 (77.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 997 bytes 79808 (77.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@host2 network-scripts]# systemctl restart network ## 重启网卡
[root@host2 network-scripts]# ifconfig ## 查看重启网卡后网卡信息,IP信息发生变化
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.20 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::20c:29ff:feaa:2b29 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:aa:2b:29 txqueuelen 1000 (Ethernet)
RX packets 331 bytes 23607 (23.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 159 bytes 13947 (13.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 1005 bytes 80680 (78.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1005 bytes 80680 (78.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@host2 network-scripts]# ping -c 3 192.168.3.20 ## 测试本地主机联通性,联通
PING 192.168.3.20 (192.168.3.20) 56(84) bytes of data.
64 bytes from 192.168.3.20: icmp_seq=1 ttl=64 time=0.032 ms
64 bytes from 192.168.3.20: icmp_seq=2 ttl=64 time=0.041 ms
64 bytes from 192.168.3.20: icmp_seq=3 ttl=64 time=0.045 ms
--- 192.168.3.20 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.032/0.039/0.045/0.007 ms
[root@host2 network-scripts]# ping -c 3 192.168.3.10 ## 此时,测试和虚拟机1的联通性,联通
PING 192.168.3.10 (192.168.3.10) 56(84) bytes of data.
64 bytes from 192.168.3.10: icmp_seq=1 ttl=64 time=0.385 ms
64 bytes from 192.168.3.10: icmp_seq=2 ttl=64 time=0.247 ms
64 bytes from 192.168.3.10: icmp_seq=3 ttl=64 time=0.188 ms
--- 192.168.3.10 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.188/0.273/0.385/0.083 ms
此时,再用虚拟机1测试和虚拟机2的联通性:
[root@host1 network-scripts]# ifconfig | head -n 3 ## 查看虚拟机1的IP
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.10 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::20c:29ff:fee4:f7b9 prefixlen 64 scopeid 0x20<link>
[root@host1 network-scripts]# ping -c 3 192.168.3.20 ## 测试和虚拟机2的联通性,联通
PING 192.168.3.20 (192.168.3.20) 56(84) bytes of data.
64 bytes from 192.168.3.20: icmp_seq=1 ttl=64 time=0.230 ms
64 bytes from 192.168.3.20: icmp_seq=2 ttl=64 time=0.244 ms
64 bytes from 192.168.3.20: icmp_seq=3 ttl=64 time=0.214 ms
--- 192.168.3.20 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.214/0.229/0.244/0.017 ms
说明:192.169.10.10和192.168.10.20可以联通;192.168.3.10和192.168.3.20可以联通;交叉时不连通。
7、测试和外网的联通性
以上的测试中两台虚拟机均为仅主机模式:
[root@host1 network-scripts]# ping -c 3 www.baidu.com ## 测试虚拟机1和外网的联通性,不联通
ping: unknown host www.baidu.com
[root@host2 network-scripts]# ping -c 3 www.baidu.com ## 测试虚拟机2和外网的联通性,不联通
ping: unknown host www.baidu.com