17

I tried sudo apt-get update in the new Windows Subsystem for Linux, but I get the following error:

Error

The most relevant parts seem to be the "could not resolve" lines about Ubuntu servers, like:

Could not resolve 'archive.ubuntu.com'
1
  • 1
    Did you check basics like ip DNS etc
    – SeanClt
    Apr 16 '16 at 18:26
23

There is an open GitHub issue about this error.

It appears that the most likely problem is that /etc/resolv.conf didn't get generated correctly. Make sure it contains a nameserver line for a valid DNS server, preferably one on your local network. Many routers provide DNS services to their networks; on my network, I would add this line:

nameserver 192.168.1.1

If there are entries that don't correspond to valid DNS servers, remove them.

If you use a third-party antivirus product, try disabling its firewall - there are reports that some such programs interfere with Bash's connectivity.

3
  • 4
    nameserver 8.8.8.8 worked for me as well. Jan 21 '17 at 23:54
  • 1
    it actually depends on the internal address of your host. I agree more to add internet ip like 1.1.1.1 or 8.8.8.8 Apr 17 '20 at 13:50
  • So, thank you, this solves my Debian question about apt update/upgrade Jun 23 '20 at 16:33
6

Create /etc/apt/apt.conf to add proxy configuration.

sudo nano /etc/apt/apt.conf

Add this line to your /etc/apt/apt.conf file

Acquire::http::Proxy "http://proxyaddress:port";

Save it with Ctrl+X, Y and retry:

Now run the below command

sudo apt-get update

I tried and verified.

1
  • I believe, this is the correct answer in case of an HTTP Proxy in place.
    – Hans
    Jul 7 '19 at 12:47
2

It looks like your DNS settings are incorrect or you could have a gateway/netmask incompatibility.

use ip link to verify that an interface is listed as 'up' and then ifconfig to for the settings of that interface. you may also need to cat /etc/sysconfig/network-scripts/ifcfg-eth? to look at the settings of the interfaces.

try traceroute -d 8.8.8.4 to see if you can reach google's public DNS server. That will verify you are getting out to the outside network. If it works with -d but fails to resolve the IP's to names when run without the -d then a quick fix would be to add 8.8.8.8 & 8.8.8.4 to your DNS Settings for the interface that is up, and then issue a service network restart to restart the network services and make the DNS changes active.

I forgot if you don't have a gui interface configured yet, you can easily edit the interface configs with system-config-network. Navigate with arrow keys,tab, esc, and enter

2
  • 4
    I can't install traceroute in the first place because of the network problems. Jun 26 '17 at 22:17
  • 2
    It looks like tracepath is an option you can try. You can also sneaker-net the RPM onto the system from another on a USB drive since it all of its dependencies are common things....libc.so, rpmlib and rtld Jul 10 '17 at 21:06
1

In my case it was the ZoneAlarm firewall. I snoozed it for 5 minutes and internet access was established immediately from Ubuntu. So I added Ubuntu as "trusted" application in Zone Alarm.

1
  • Where exactly in ZA? And Which executable did you add or mark as trusted? In Application control I dont see "ubuntu" but some seemingly temporary file ubuntu1804.exe which even if I change to trusted can't access the internet
    – Recct
    May 19 '20 at 9:23
0

In my case this was actually caused by Norton "Smart" Firewall (ironic name). Disabling firewall brought the internet to life without editing any system files (WSL 2, Ubuntu 18.04). However setting nameserver to 8.8.8.8 fixed other issues

0

Works for CentOS/RHEL/Fedora:

Please set the proxy using the following command:

Command to set the proxy:

export http_proxy=http://SERVER:PORT/

Command to verify whether proxy is set or not:

echo $http_proxy
0

In my case it was Kaspersky. I have given a detailed explanation here: https://github.com/microsoft/WSL/issues/4275#issuecomment-674480761

[EDIT]

Contents of the above link:

Apart from adding routes and nameservers, Kapersky was causing the issue for me. Stoping it was not working either probably it was making changes to some system files to prevent access to WSL application. I found this to be helpful:

Go to: More Tools -> Manage Application -> Application Control -> Manage Application -> 'your WSL app name' -> click on network(green arrow) -> Change value to allow.

Attaching screen shot of same: enter image description here

2
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Dave M
    Aug 18 '20 at 14:17
  • Agreed @FromReview, will add it here. Aug 18 '20 at 17:30
0

Try downgrading from WSL2 to WSL1.

For example: wsl --set-version Ubuntu 1

This fixed all of my connectivity issues.

-2

Before trying the above (which are all very valid and possible solutions for your root cause), try to disable your antivirus/firewall first. Worked for me.

1
  • It is not clear which answer you are referring to exactly. However, the accepted answer, already made the suggestion to disable your firewall.
    – Ramhound
    Jun 22 '20 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.