Centos7 ping: www.baidu.com: Name or service not known的问题

春节复工之后,再次登录服务器。服务器的ip被改动了。
不知道是何原因,conda update --all指令和git clone 指令都用不了了。

[xl@GPU1 ~]$ conda update --all
Collecting package metadata (current_repodata.json): failed

#>>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 1078, in __call__
        return func(*args, **kwargs)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 84, in _main
        exit_code = do_call(args, p)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/cli/conda_argparse.py", line 82, in do_call
        exit_code = getattr(module, func_name)(args, parser)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/cli/main_update.py", line 20, in execute
        install(args, parser, 'update')
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/cli/install.py", line 265, in install
        should_retry_solve=(_should_retry_unfrozen or repodata_fn != repodata_fns[-1]),
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/solve.py", line 117, in solve_for_transaction
        should_retry_solve)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/solve.py", line 158, in solve_for_diff
        force_remove, should_retry_solve)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/solve.py", line 262, in solve_final_state
        ssc = self._collect_all_metadata(ssc)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/common/io.py", line 88, in decorated
        return f(*args, **kwds)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/solve.py", line 415, in _collect_all_metadata
        index, r = self._prepare(prepared_specs)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/solve.py", line 1004, in _prepare
        self.subdirs, prepared_specs, self._repodata_fn)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/index.py", line 229, in get_reduced_index
        repodata_fn=repodata_fn)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/subdir_data.py", line 105, in query_all
        result = tuple(concat(executor.map(subdir_query, channel_urls)))
      File "/home/xl/anaconda2/lib/python2.7/site-packages/concurrent/futures/_base.py", line 641, in result_iterator
        yield fs.pop().result()
      File "/home/xl/anaconda2/lib/python2.7/site-packages/concurrent/futures/_base.py", line 462, in result
        return self.__get_result()
      File "/home/xl/anaconda2/lib/python2.7/site-packages/concurrent/futures/thread.py", line 63, in run
        result = self.fn(*self.args, **self.kwargs)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/subdir_data.py", line 98, in <lambda>
        package_ref_or_match_spec))
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/subdir_data.py", line 110, in query
        self.load()
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/subdir_data.py", line 174, in load
        _internal_state = self._load()
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/subdir_data.py", line 248, in _load
        repodata_fn=self.repodata_fn)
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/core/subdir_data.py", line 587, in fetch_repodata_remote_request
        """) % maybe_unquote(repr(e))
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/common/url.py", line 368, in maybe_unquote
        return unquote_plus(remove_auth(url)) if url else url
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/common/url.py", line 372, in remove_auth
        url_parts = parse_url(url)._asdict()
      File "/home/xl/anaconda2/lib/python2.7/site-packages/conda/_vendor/urllib3/util/url.py", line 196, in parse_url
        raise LocationParseError(url)
    LocationParseError: Failed to parse: ConnectionError(MaxRetryError("HTTPSConnectionPool(host='mirrors.tuna.tsinghua.edu.cn', port=443): Max retries exceeded with url: 

`$ /home/xl/anaconda2/bin/conda update --all`

  environment variables:
                 CIO_TEST=<not set>
                CLASSPATH=.:/usr/java/jdk1.8.0_151/lib/dt.jar:/usr/java/jdk1.8.0_151/lib/tools.j
                          ar:/usr/java/jdk1.8.0_151/jre/lib
                CONDA_EXE=/home/xl/anaconda2/bin/conda
         CONDA_PYTHON_EXE=/home/xl/anaconda2/bin/python
               CONDA_ROOT=/home/xl/anaconda2
              CONDA_SHLVL=0
          LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:/usr/local/cuda-9.0/extras/CUPTI/lib64:/usr/
                          local/lib/openmpi:/usr/local/cuda-9.0/lib64:/home/xl/anaconda2/lib
               MODULEPATH=/usr/share/Modules/modulefiles:/etc/modulefiles
                     PATH=/home/xl/anaconda2/bin:/home/xl/anaconda2/condabin:/usr/local/cuda-9.0
                          /bin:/root/anaconda3/bin:/usr/java/jdk1.8.0_151/bin:/usr/java/jdk1.8.0
                          _151/jre/bin:/home/softwarePlatform/Dev_Platform/hadoop3/bin:/usr/loca
                          l/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/xl/.local/bin:/home/xl/
                          bin
               PYTHONPATH=/home/xl/usr/bin/python3:/home/xl/ssd_caffe/python:/home/xl/caffe/pyth
                          on:/home/xl/ssd-caffe/python::/usr/local/lib/python2.7/dist-
                          packages/models:/usr/local/lib/python2.7/dist-packages/models
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>

     active environment : None
            shell level : 0
       user config file : /home/xl/.condarc
 populated config files : /home/xl/.condarc
          conda version : 4.8.0
    conda-build version : 3.18.9
         python version : 2.7.16.final.0
       virtual packages : __glibc=2.17
                          __cuda=9.0
       base environment : /home/xl/anaconda2  (writable)
           channel URLs : https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64
                          https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
                          https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64
                          https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/xl/anaconda2/pkgs
                          /home/xl/.conda/pkgs
       envs directories : /home/xl/anaconda2/envs
                          /home/xl/.conda/envs
               platform : linux-64
             user-agent : conda/4.8.0 requests/2.22.0 CPython/2.7.16 Linux/3.10.0-1062.1.2.el7.x86_64 centos/7.7.1908 glibc/2.17
                UID:GID : 1004:1004
             netrc file : None
           offline mode : False


An unexpected error has occurred. Conda has prepared the above report.

If submitted, this report will be used by core maintainers to improve
future releases of conda.
Would you like conda to send this report to the core maintainers?

[y/N]: 

No report sent. To permanently opt-out, use

    $ conda config --set report_errors false
    

在这里插入图片描述
推测网络连接出现问题。
于是,通过ping指令进行验证:
在这里插入图片描述果然是网络不通。上网查了一下,最终得到解决:

1.查看网络配置

按照centos7 ping: www.baidu.com: Name or service not known这篇博客中的提供方案,首先需要查看下系统的ip、子网掩码和网关等信息。

查到ip为:
在这里插入图片描述
子网掩码和网关为:
在这里插入图片描述

2.编辑Linux中的网络配置文件

配置文件在/etc/sysconfig/network-scripts/目录下,网络配置文件名可能会有不同。我的网络配置文件ifcfg-em3,有人的是ifcfg-ens33
其原来的内容如下:

TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=em3
UUID=2ac0a65c-1e6d-401c-8691-9342907d49a2
DEVICE=em3
ONBOOT=yes #网络设备开机启动
IPADDR=192.168.1.181
PREFIX=24
GATEWAY=192.168.10.1 #网关IP
DNS1=114.114.114.114
DNS2=8.8.8.8
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

发现
ONBOOT=yes #网络设备开机启动是对的
IPADDR=192.168.1.181与我的主机ip也是相符的
默认网关GATEWAY=192.168.10.1不对,我的实际的默认网关是192.168.1.1

修改GATEWAY=192.168.1.1

3.重启网络服务

service network restart

4.测试一下

Centos7 ping: www.baidu.com: Name or service not known的问题_第1张图片
可以了!
OK 搞定!

5.DNS文件配置

上面我的网络配置文件ifcfg-em3
DNS1=114.114.114.114
DNS2=8.8.8.8
与我的/etc/resolv.conf文件中的
nameserver 114.114.114.114
nameserver 8.8.8.8
一致且可行,没有修改为
在这里插入图片描述

在这里插入图片描述
这里做一下说明。

参考网址

【1】centos7 ping: www.baidu.com: Name or service not known
【2】centos7 ping: www.baidu.com: Name or service not known

你可能感兴趣的:(操作技能)