PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Categories:
Resolving PycURL Error 6: 'Couldn't resolve host' on CentOS/Hyper-V

This article provides a comprehensive guide to troubleshoot and resolve the 'Couldn't resolve host' error (PycURL Error 6) commonly encountered on CentOS virtual machines, especially when hosted on Hyper-V. Learn how to diagnose DNS issues, configure network settings, and ensure proper connectivity.
The 'Couldn't resolve host' error, specifically PycURL Error 6, is a common networking problem that indicates your system is unable to translate a hostname (like mirrorlist.centos.org
) into an IP address. This is fundamentally a DNS (Domain Name System) resolution failure. While it can occur in various environments, it's frequently observed in virtualized settings such as CentOS running on Hyper-V, where network configurations might not be immediately obvious or correctly set up.
Understanding the Root Cause: DNS Resolution Failure
When you encounter 'Couldn't resolve host', it means your operating system's network stack cannot find the IP address associated with the requested hostname. This process typically involves querying DNS servers. Several factors can lead to this failure:
- Incorrect DNS Server Configuration: The VM might not be configured to use valid and reachable DNS servers.
- Network Connectivity Issues: The VM might not have a proper network connection to reach any DNS server or the internet.
- Firewall Restrictions: A firewall (either on the VM, Hyper-V host, or external network) might be blocking DNS queries (port 53 UDP/TCP).
- Hostname Typos: Although less common for well-known hosts like
mirrorlist.centos.org
, a typo in the hostname would also result in this error. - Hyper-V Virtual Switch Configuration: The virtual switch used by the VM might not be correctly configured to provide internet access or DNS forwarding.
flowchart TD A[Application Request 'mirrorlist.centos.org'] --> B{OS DNS Resolver} B --> C{Query Configured DNS Servers} C -- DNS Server Unreachable --> D[PycURL Error 6: 'Couldn't resolve host'] C -- DNS Server Reachable but No Response --> D C -- DNS Server Responds with 'Host Not Found' --> D C -- DNS Server Responds with IP --> E[Connect to IP Address] E --> F[Success]
Flowchart illustrating the DNS resolution process and potential failure points leading to 'Couldn't resolve host'.
Diagnosing Network and DNS Issues on CentOS
Before attempting fixes, it's crucial to diagnose where the problem lies. Start by checking basic network connectivity and then move to DNS-specific tests.
ping -c 4 8.8.8.8
Test basic internet connectivity to Google's public DNS server.
If the ping
command fails, your VM likely has no internet access. If it succeeds, the issue is more specific to DNS resolution.
cat /etc/resolv.conf
Check the configured DNS servers on your CentOS system.
This file lists the DNS servers your system uses. Ensure the IP addresses listed are correct and reachable. Common public DNS servers include 8.8.8.8
(Google) or 1.1.1.1
(Cloudflare).
dig mirrorlist.centos.org
nslookup mirrorlist.centos.org
Use dig
or nslookup
to explicitly test DNS resolution for the problematic hostname.
If these commands fail to resolve the hostname, it confirms a DNS resolution problem.
Resolving the 'Couldn't resolve host' Error
Based on your diagnosis, apply the following solutions.
1. Step 1: Configure DNS Servers Manually
If /etc/resolv.conf
is empty or contains incorrect DNS servers, you can manually edit it. However, on modern CentOS systems using NetworkManager, it's better to configure DNS via NetworkManager or the network interface configuration files to ensure persistence across reboots.
For temporary testing, you can edit /etc/resolv.conf
directly:
sudo vi /etc/resolv.conf
Add or modify the nameserver
lines:
nameserver 8.8.8.8
nameserver 8.8.4.4
For a persistent change, edit the network interface configuration file (e.g., /etc/sysconfig/network-scripts/ifcfg-eth0
or ifcfg-ens192
):
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
Add or modify the DNS1
and DNS2
lines:
DNS1=8.8.8.8
DNS2=8.8.4.4
PEERDNS=no
After modifying, restart the network service:
sudo systemctl restart network
2. Step 2: Verify Hyper-V Virtual Switch Configuration
On the Hyper-V host, ensure the virtual machine is connected to a virtual switch that provides internet access. This typically means an 'External' virtual switch bound to a physical network adapter with internet connectivity. If using an 'Internal' or 'Private' switch, you'll need to configure NAT or routing on the host to provide internet access to the VM.
- Open Hyper-V Manager.
- Go to 'Virtual Switch Manager'.
- Ensure the virtual switch connected to your CentOS VM is of type 'External' and is bound to the correct physical network adapter that has internet access.
3. Step 3: Check Firewall Settings
Both the CentOS VM's firewall (firewalld
or iptables
) and any external firewalls (e.g., on the Hyper-V host or network router) can block DNS traffic. Temporarily disable the firewall on the CentOS VM to rule it out:
sudo systemctl stop firewalld
sudo systemctl disable firewalld
If this resolves the issue, re-enable the firewall and configure it to allow outgoing DNS traffic (UDP port 53).
4. Step 4: Review Network Adapter Settings in Hyper-V
Sometimes, the virtual network adapter settings within Hyper-V for the specific VM can cause issues. Ensure the network adapter is enabled and configured correctly.
- In Hyper-V Manager, right-click your CentOS VM and select 'Settings'.
- Navigate to 'Network Adapter'.
- Ensure it's connected to the correct virtual switch.
- Consider removing and re-adding the network adapter if other steps fail, or try using a 'Legacy Network Adapter' for older CentOS versions if you suspect driver issues.
ping 8.8.8.8
to check basic internet reachability and dig mirrorlist.centos.org
to confirm DNS resolution.Advanced Troubleshooting: DHCP and NetworkManager
If your CentOS VM is configured to use DHCP, ensure the DHCP server is correctly providing DNS server addresses. If NetworkManager is managing your network, you can use nmcli
to inspect and modify settings.
nmcli device show eth0 | grep DNS
nmcli connection show 'System eth0' | grep dns
Check DNS settings via NetworkManager for the 'eth0' interface (replace 'eth0' with your actual interface name).
To set DNS servers using nmcli
for a specific connection (e.g., 'System eth0'):
sudo nmcli connection modify 'System eth0' ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli connection modify 'System eth0' ipv4.dns-search "example.com"
sudo nmcli connection up 'System eth0'
Configure static DNS servers using nmcli
and bring the connection up.