[linux] CentOS 7 error: yum command reports “Cannot find a valid baseurl for repo: base/7/x86_6” or cannot access the Internet

1. Error reporting

 fe1a9a38c11834585d147b18d6e2b6b.png

2. Reason for error

The system cannot parse the yum source for the following reasons

  1. The virtual machine cannot access the Internet! You need to check the network configuration to confirm that you can access the Internet and then look at the second situation
  • Check if you can access the Internet: ping a public network pi
ping 114.114.114.114

 image.png
 image.png

  1. DNS configuration problem! Check if there is a problem with the DNS configuration. You can do this nslookup www.baidu.com

& height=47 & amp;id=u28e350f7 & amp;name=image.png & amp;originHeight=47 & amp;originWidth=423 & amp;originalType=binary & amp;ratio=1 & amp;rotation=0 & amp; showTitle=true & amp;size=1379 & amp;status=done & amp;style=none & amp;taskId=u044e3be9-9662-4af3-8171-0bfbaa1d449 &title=parsing failed&width=423″ alt =”image.png” title=”parsing failed”>

  1. If the above two situations are normal, but the yum source still cannot be parsed, you can try another yum source

3. Solutions

  1. The network adapter of VMware can be set to NAT or bridge mode

 image.png

  1. Create network card file
    1. Directory: cd /etc/sysconfg/network-scripts/
    2. Check if there is: ifcfg-ens33 or ifcfg-ens32, if there is no change file created (no suffix)
  2. Modify the content of the ifcfg-ens33/ifcfg-ens33 file, and open it for editing through the vim command
vim/vi ifcfg-ens33

 image.png
bridge mode

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp" #If it is bridge mode dhcp is automatically obtained, if it is NAT: static
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="ens33"
UUID="784d0f02-9840-411b-afc1-9d65850bd9dd"
DEVICE="ens33"
ONBOOT="yes"
  • BOOTPROTO="dhcp" #If it is a bridge mode dhcp is automatically obtained, if it is NAT: static
  • ONBOOT="yes" ON

If it is NAT mode, you need to add these

DNS1=8.8.8.8
DNS2=223.5.5.5
GATEWAY=192.168.1.2 # View your own parameters and finally configure 2 for forwarding
NETMASK=255.255.255.0
IPADDR=192.168.1.180# View your own parameters
  • IPADDR: The last three digits of IP + are randomly selected from 0 to 155
  • GATEWAY: gateway
  • DNS: DNS configuration (used to solve problem 2)

View parameters:
Input: ip a
 1679449292114.png

  1. restart network service
systemctl restart network.service
  1. Enter the command to view the IP address: ip a

This is my network card configuration (NTA mode)
 image.png
Reference article: 1. https://blog.csdn.net/weixin_43232955/article/details/108290006
2. https://blog.csdn.net/qq_39720249/article/details/84065760