1、问题的出现
用VirtualBox安装Win10,网络连接选择"桥接网卡",无任何问题;
用VirtualBox安装(第一个CentOS,s1)CentOS-7-x86_64-Minimal-1511.iso,网络连接选择"桥接网卡",无任何问题,能够正常上网,yum,ping都正常;
用VirtualBox安装(第二个CentOS,s2)CentOS-7-x86_64-Minimal-1511.iso,网络连接选择"桥接网卡",问题就来了,运行yum -y install git,一直报错"loaded plugins fastestmirror you need to be root to perform this command",此时还未意识到是网络问题导致的,各种折腾,一开始方向就错了,一直从"yum install"的错误查找解决方法,各种修改、重启都没解决问题。后来实在没法,尝试了一下ping 172.16.70.170(内网ip),居然提示"connect: Network is unreachable" ,果断查看当前网络信息"ip addr",没有获取到网络地址,这才发现居然是网络问题导致"yum install 错误:loaded plugins fastestmirror you need to be root to perform this command"。
2、 解决问题
经过一番折腾,终于找到了问题,接下来就是如何解决,按照一般的思路是去"/etc/sysconfig/network-scripts"查看ifcfg-eth0内容,问题又来了,居然没有这个文件,当时就迷茫了,不知道怎么办了。
$ cd /etc/sysconfig/network-scripts/$ lsifcfg-enp0s3 ifdown-post ifup-eth ifup-routesifcfg-lo ifdown-ppp ifup-ippp ifup-sitifdown ifdown-routes ifup-ipv6 ifup-tunnelifdown-bnep ifdown-sit ifup-isdn ifup-wirelessifdown-eth ifdown-tunnel ifup-plip init.ipv6-globalifdown-ippp ifup ifup-plusb network-functionsifdown-ipv6 ifup-aliases ifup-post network-functions-ipv6ifdown-isdn ifup-bnep ifup-ppp
各种查找"ifcfg-eth0 missing",也没解决问题。突然想起我不是有一个能够上网的s1么,然后登录s1,同样进入"/etc/sysconfig/network-scripts/"目录查看文件列表,居然和s3一摸一样,这就奇怪了,一样的文件,问什么不能一个能上网一个不能上网呢?然后运行"ip addr"查看网络
$ ip addr1: lo:mtu 65536 qdisc noqueue state UNKNOWN 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 forever2: enp0s3: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:8a:4b:83 brd ff:ff:ff:ff:ff:ff inet 172.16.70.173/24 brd 172.16.70.255 scope global dynamic enp0s3 valid_lft 256686sec preferred_lft 256686sec inet6 fe80::a00:27ff:fe8a:4b83/64 scope link valid_lft forever preferred_lft forever
从信息里面可以看出网络指向的配置是enp0s3,而不是eth0,然后对比一下s1与s2的ifcfg-enp0s3文件,只有下面一行不一样
s1
ONBOOT=yes
s2
ONBOOT=no
然后修改s2的/etc/sysconfig/network-scripts/ifcfg-enp0s3文件内容与s1保持一致,然后重启,再次ping 172.16.70.170,通了,问题解决了,运行 yun install 也不提示"loaded plugins fastestmirror you need to be root to perform this command"错误了。
$ vi /etc/sysconfig/network-scripts/ifcfg-enp0s3$ reboot$ ping 172.16.70.170PING 172.16.70.170 (172.16.70.170) 56(84) bytes of data.64 bytes from 172.16.70.170: icmp_seq=1 ttl=64 time=0.554 ms64 bytes from 172.16.70.170: icmp_seq=2 ttl=64 time=0.245 ms64 bytes from 172.16.70.170: icmp_seq=3 ttl=64 time=0.306 ms^C--- 172.16.70.170 ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2001msrtt min/avg/max/mdev = 0.245/0.368/0.554/0.134 ms$ yum -y install git
3、总结
在虚拟机上安装CentOS的默认网络名称不一定都是eth0,有可能网络设置不一样,而默认网络名称也不一样;
在解决问题的时候方向很重要,如果走错了,那就越来越远;
经验很重要,如果之前碰到个类似问题,就不会花这么多时间在解决这种基本配置的小问题上;