sudo add-apt-repository hangs

Solution 1:

I have followed this instructions, and it worked great for me (Ubuntu 20.04).

In command line, type this

sudo gedit /etc/gai.conf

Then, edit this line by removing the #

precedence ::ffff:0:0/96  100

Solution 2:

In my case I was having problems handling ipv6 from the responses. I was getting a blinking cursor and had to wait, sometimes, for one minute so it would work, although the requests which were handled from the beginning only with ipv4 were working fast and fine.

I discovered this when checked the behavoiur of the terminal command wget. Google which defaults requests on ipv6 at port 80 (http) was taking more than a minute to timeout and use ipv4 [and finally work]; then github.com that only uses ipv4, also on port 80 (http), was working ok.

Not all requests go through ipv6, many still use ipv4 as default and sometimes is the only valid answer. It doesn't matter if we are using wget, curl or add-apt-repository (which i think uses python 3.6.9 socket and all of its network libraries) those all try to resolve the ipv6 at first.

In my case, i had to have a valid ipv6 address to make a request (from my computer) and although the IPS modem and my router were configured to handle ipv6, this computer which originally had Windows 10 (removed from ssd) then had Ubuntu 18.04 (full installation) installed was not completely configured. I had to go to wifi settings and select to get an automatic ipv6 address and settings (DHCP), that was it for me. Make sure you select for ipv6 "Automatic, DHCP only" and not only "Automatic" as there are both available choices.

Apparently when we are working from the terminal in Ubuntu, it tries to resolve the first available address that in this cases was ipv6. So now i can get everything fast, since my pc can resolve the requests through ipv6 very fast and translates them to the ipv4 address.