CentOS报错:Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock32 error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

最小化安装的CentOS 7在运行yum安装命令时报了以下错误:

 1 Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock32 error was
 2 
 3 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
 4  
 5 One of the configured repositories failed (Unknown),
 6 and yum doesn't have enough cached data to continue. At this point the only
 7 safe thing yum can do is fail. There are a few ways to work "fix" this:
 8  
 9  1. Contact the upstream for the repository and get them to fix the problem.
10  
11  2. Reconfigure the baseurl/etc. for the repository, to point to a working
12     upstream. This is most often useful if you are using a newer
13     distribution release than is supported by the repository (and the
14     packages for the previous distribution release still work).
15  
16  3. Disable the repository, so yum won't use it by default. Yum will then
17     just ignore the repository until you permanently enable it again or use
18     --enablerepo for temporary usage:
19  
20         yum-config-manager --disable <repoid>
21  
22  4. Configure the failing repository to be skipped, if it is unavailable.
23     Note that yum will try to contact the repo. when it runs most commands,
24     so will have to try and fail each time (and thus. yum will be be much
25     slower). If it is a very temporary problem though, this is often a nice
26     compromise:
27  
28         yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

 

 
 百度了一下这个错误,发现报错原因是“本机无法连接网络的网络设置”的原因。

于是参照“How to Setup network on centos 7”这篇博文,配置了下DHPC,最终解决了这个error。

配置CentOS 7的网络,步骤如下:

1.在终端中输入以下命令,查看安装在本机的网卡:

1 [root@localhost ~]# nmcli d
2 设备   类型      状态    连接  
3 ens33  ethernet  连接的  ens33 
4 lo     loopback  未托管  --

 

2.切换到/etc/sysconfig/network-scripts/目录下,打开“ifcfg-ens33”文件: 

打开ifcfg-ens33文件,展开如下:

 1 [root@localhost network-scripts]# vi ifcfg-ens33
 2 
 3 TYPE=Ethernet
 4 PROXY_METHOD=none
 5 BROWSER_ONLY=no
 6 BOOTPROTO=dhcp
 7 DEFROUTE=yes
 8 IPV4_FAILURE_FATAL=no
 9 IPV6INIT=yes
10 IPV6_AUTOCONF=yes
11 IPV6_DEFROUTE=yes
12 IPV6_FAILURE_FATAL=no
13 IPV6_ADDR_GEN_MODE=stable-privacy
14 NAME=ens33
15 UUID=c71a84d9-bbd2-445d-bac8-d53d545055e0
16 DEVICE=ens33
17 ONBOOT=yes
18 IPV6_PRIVACY=no

动态配置 或 静态配置

  » 动态配置

  依次将第6行和第17行替换为:

  BOOTPROTO=dhcp
  ONBOOT=yes

  然后,通过键入以下命令重新启动网络服务:

[root@localhost network-scripts]# systemctl restart network

 测试网络是否成功

 

 » 静态配置  

 依次将第2行和第11行替换为:

  BOOTPROTO=static
  ONBOOT=yes

  然后,在文件末尾添加以下4行:

1 IPADDR=172.27.0.32
2 NETMASK=255.255.255.0
3 GATEWAY=172.27.0.1
4 DNS1=172.27.0.5

然后,通过键入以下命令重新启动网络服务:

[root@localhost network-scripts]# systemctl restart network

 centos查询本机的外网IP: curl ifconfig.me 命令即可查看

 

 

 

 

 

 

posted @ 2018-01-12 14:27  LeoLiY  阅读(1287)  评论(0编辑  收藏  举报