2

My /etc/apt/sources.list contains:

deb http://ubuntu.mirror.garr.it/ubuntu/ focal main
deb-src http://ubuntu.mirror.garr.it/ubuntu/ focal main

deb-src http://ubuntu.mirror.garr.it/ubuntu/ focal restricted universe multiverse

deb http://ubuntu.mirror.garr.it/ubuntu/ focal-updates main restricted universe multiverse deb-src http://ubuntu.mirror.garr.it/ubuntu/ focal-updates main restricted universe multiverse

deb http://ubuntu.mirror.garr.it/ubuntu/ focal-security main restricted universe multiverse deb-src http://ubuntu.mirror.garr.it/ubuntu/ focal-security main restricted universe multiverse

deb http://ubuntu.mirror.garr.it/ubuntu/ focal-backports main restricted universe multiverse deb-src http://ubuntu.mirror.garr.it/ubuntu/ focal-backports main restricted universe multiverse

deb http://archive.canonical.com/ubuntu focal partner deb-src http://archive.canonical.com/ubuntu focal partner

But when I try anything related to the software updates, e.g., sudo apt update --fix-missing && sudo apt upgrade, I get the following output on terminal:

    sudo apt update --fix-missing && sudo apt upgrade
Err:1 http://archive.canonical.com/ubuntu focal InRelease
  Temporary failure resolving 'proxy_server'
Err:2 http://ubuntu.mirror.garr.it/ubuntu focal InRelease
  Temporary failure resolving 'proxy_server'
Err:3 http://ubuntu.mirror.garr.it/ubuntu focal-updates InRelease
  Temporary failure resolving 'proxy_server'
Err:4 http://ubuntu.mirror.garr.it/ubuntu focal-security InRelease
  Temporary failure resolving 'proxy_server'
Err:5 http://ubuntu.mirror.garr.it/ubuntu focal-backports InRelease
  Temporary failure resolving 'proxy_server'
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.
W: Failed to fetch http://ubuntu.mirror.garr.it/ubuntu/dists/focal/InRelease  Temporary failure resolving 'proxy_server'
W: Failed to fetch http://ubuntu.mirror.garr.it/ubuntu/dists/focal-updates/InRelease  Temporary failure resolving 'proxy_server'
W: Failed to fetch http://ubuntu.mirror.garr.it/ubuntu/dists/focal-security/InRelease  Temporary failure resolving 'proxy_server'
W: Failed to fetch http://ubuntu.mirror.garr.it/ubuntu/dists/focal-backports/InRelease  Temporary failure resolving 'proxy_server'
W: Failed to fetch http://archive.canonical.com/ubuntu/dists/focal/InRelease  Temporary failure resolving 'proxy_server'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

And anything I try to install gives similar problems:

$ sudo apt-get install indicator-cpufreq
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package indicator-cpufreq

Trying to change the server from the Software update app gets stuck in the cache refreshment, or eventually returns an error similar to the Failed to fetch one (the window doesn't allow me to copy&paste the output error).

More info about my system:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal

What should go into the services.list and proxy, and what could the problem be?

EDIT #1: I think my /etc/apt/apt.conf is wrong and I'd appreciate some help in what it could go in that file. echo "$http_proxy" does not return anything, neither does env | grep -i proxy. Settings --> Proxy Network is set on Disabled, but if I check Manual I get proxy-server-ip in the "Proxy HTTP" field and 8080 is the port.

EDIT #2: My /etc/apt/apt.conf.d/proxy.conf contains two lines:

Acquire::http::Proxy "http://proxy_server:port/";
Acquire::https::Proxy "http://proxy_server:port/";
Py-ser
  • 359

2 Answers2

4

It looks like your machine is trying to resolve a host literally named proxy_server. Try ping -c 5 proxy_server to see if it has an IP listed and if you can hit it over ICMP. If you are indeed wanting to use a proxy, then check for that IP in /etc/hosts, or just grep 'proxy_server' /etc/hosts, and make sure you can connect to the IP listed for proxy_server via TCP using telnet proxy_server [port] or nc proxy_server:[port]. The port will usually be 8080 for HTTP or 1080 for SOCKS, but can really be set to anything. You would get the port information from your apt config files, in steps detailed below.

If you can ping proxy_server, then make sure that proxy is working correctly and listening on the correct ports that you have listed in any files under /etc/apt. To list these files, run grep -rl 'proxy_server' /etc/apt.

If you aren't intending to use a proxy to connect, then grep -rl 'proxy_server' /etc/apt to see which files list that string. To remove all lines containing that string, run the following as root grep -rl 'proxy_server' /etc/apt | xargs -I file sed -i '/proxy_server/d' file, and try again.

If there are no files listed in the grep output, then run sudo http_proxy= https_proxy= apt update --fix-missing && sudo http_proxy= https_proxy= apt upgrade, and try again.

If that works, then you are setting the http_proxy and/or https_proxy variables somewhere in your environment, most likely in /root/.bashrc, but in reality, those variables could be set in a variety of files that get sourced). For more information about those files, check this answer. To find out if these variables are set in /root/.bashrc, you can run the commands below to get rid of them, or the script that follows, which would be somewhat safer.

Commands to immediately remove http_proxy and https_proxy from .bashrc:

sudo sed -i '/http_proxy/d;/https_proxy/d' /root/.bashrc
sed -i '/http_proxy/d;/https_proxy/d' ~/.bashrc

Note: the reason I am listing your own ~/.bashrc is because sometimes and in some cases, root is set to inherit the user's profile.

Script that checks if the lines actually exist before attempting to remove them (note that the previous commands won't fail if the lines don't exist, but this will actually return the lines in the output so you knew where they existed:

#!/bin/sh

if grep -E '(http_proxy)|(https_proxy)' /root/.bashrc; then sudo sed -i '/http_proxy/d;/https_proxy/d' /root/.bashrc fi if grep -E '(http_proxy)|(https_proxy)' ~/.bashrc; then sed -i '/http_proxy/d;/https_proxy/d' ~/.bashrc fi

Or if you prefer a one-liner that you can copy/paste:

if grep -E '(http_proxy)|(https_proxy)' /root/.bashrc; then sudo sed -i '/http_proxy/d;/https_proxy/d' /root/.bashrc; fi; if grep -E '(http_proxy)|(https_proxy)' ~/.bashrc; then sed -i '/http_proxy/d;/https_proxy/d' ~/.bashrc; fi

Important: If you have any functions or aliases directly in these .bashrc files that are meant to toggle proxies, it will remove any lines containing http_proxy or https_proxy. In your case, it may be safer to replace http_proxy and https_proxy in the above commands/script with proxy_server.

Your particular one-liner would be as follows:

if grep 'proxy_server' /root/.bashrc; then sudo sed -i '/proxy_server/d' /root/.bashrc; fi; if grep 'proxy_server' ~/.bashrc; then sed -i '/proxy_server/d' ~/.bashrc; fi

Edit: I corrected the grep command based on your comment, and after re-reading your question, if you are not wanting to connect to a proxy at all, simply mv /etc/apt/apt.conf.d/proxy.conf /tmp/ and re-run the command, and it should work just fine. If that's the only place that proxy_server turned up, then I'm not sure why removing the lines didn't work, but it's possible that proxy.conf is getting cached somewhere. By removing the file altogether, your proxy settings will probably get re-initialized.

The actual root of the problem is that you have dummy/example settings in /etc/apt/apt.conf.d/proxy.conf, which is literally trying to resolve the host proxy_server on port port. As you can tell, proxy_server doesn't actually exist, and port would have to be an actual port number in order for apt to connect successfully.

By removing the proxy.conf file (which is not required at all for apt to work, and doesn't ordinarily exist by default), you should be able to resolve this issue.

Edit #2: If you do indeed need to connect to a proxy, then just keep /etc/apt/apt.conf.d/proxy.conf in place and replace proxy_server with the actual IP or hostname of the proxy server and port with the actual port number. Alternately, you can just replace port with the actual port number and create an entry in /etc/hosts for proxy_server pointing to the correct IP address of the actual proxy server.

Final Edit: After chatting with the user, they removed /etc/apt/apt.conf.d/proxy.conf but were still getting the same issue, except instead of not resolving proxy_server, it was not resolving proxy.server, which led me to believe the proxy settings were getting set in another location.

I had them run grep -rlE 'Acquire::.*::Proxy' /etc/apt/, which returned /etc/apt/apt.conf.

I then instructed them to run grep -nE 'Acquire::.*::Proxy' /etc/apt/apt.conf, which returned the following:

...
5:Acquire::http::Proxy "http://user:password@proxy.server:port/";
6:Acquire::https::Proxy "http://user:password@proxy.server:port/";
...

This was essentially doing the same as /etc/apt/apt.conf.d/proxy.conf, only the hostname was proxy.server instead of proxy_server. Still dummy/example settings. After instructing them to comment out lines 5 and 6 and re-run the initial command of sudo apt update --fix-missing && sudo apt upgrade, they confirmed it was working correctly and fetching updates.

rubynorails
  • 2,293
  • $ grep -rl 'proxy_server' /etc/apt returns /etc/apt/apt.conf.d/proxy.conf. This is reported in my original question. Removing those lines from proxy.conf does not solve the errors and warnings reported in my question. If you prefer, we can continue in chat. – Py-ser Apr 20 '22 at 15:33
  • Also, $ ping -c 5 proxy_server returns ping: proxy_server: Temporary failure in name resolution – Py-ser Apr 20 '22 at 15:47
  • sudo http_proxy= https_proxy= apt update --fix-missing && http_proxy= https_proxy= apt upgrade returns the same output of my original question, but also the errors 'E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?. This last errors are gone if I usesudoafter&&` – Py-ser Apr 20 '22 at 15:50
  • Sorry I have updated the command to include sudo after &&. If the grep command returned /etc/apt/apt.conf.d/proxy.conf and you are not wanting to use a proxy, then just mv /etc/apt/apt.conf.d/proxy.conf /tmp/ and re-run sudo apt update --fix-missing && sudo apt upgrade. We can continue in chat if you like. – rubynorails Apr 20 '22 at 16:04
0

Partial answer:

The terminal output indicates you have a proxy server configured somewhere. As you didn't give your full apt configuration, please have a look at how to configure a proxy server apt (e.g. here, first Google result), and then go through your complete apt configuration in /etc/apt and see if you have some proxy settings somewhere.

If there are none, the next step is to do something like sudo env to look at the environment after sudo to verify no proxy is set.

There is not enough information in the current question to determine the actual reason, this needs debugging.


If there is nothing proxy related in sudo env, and no proxy settings anywhere in the apt configuration, next step is to have a look at man apt.conf and enable debugging output. Start with Debug::Acquire::http and Debug::Acquire::https.


If you literally have

Acquire::http::Proxy "http://user:password@proxy.server:port/";

in your apt configuration file, then this makes no sense at all: What is inside the quotation marks is just a placeholder for your actual username, your actual password, the actual hostname of the server, and the actual port.

So if you don't have a concrete proxy server you need to use, and you know your username, your password, and the address of the server, then just delete this file.

As it currently is, apt tries to make a request to proxy.server (literally proxy.server), and of course this hostname does not exist, so it cannot connect, so it cannot download anything.

dirkt
  • 32,309
  • What should I look for in sudo env? There doesn't seem to be anything proxy related. What kind of information you need? If you can guide I'll add it to the original question. – Py-ser Apr 20 '22 at 10:27
  • Besides, the /etc/apt/apt.conf.d/proxy.conf is exactly as suggested in the guide you linked, cause I had followed it before writing this thread. – Py-ser Apr 20 '22 at 10:33
  • 1
    You need to look at all configuration files - proxy.conf isn't the only file that can make those settings. – dirkt Apr 20 '22 at 10:58
  • And please clarify "exactly as suggested". What proxy address did you put in there? Edit your question and include the complete file. – dirkt Apr 20 '22 at 11:02
  • I have edited the question with the /etc/apt/apt.conf.d/proxy.conf. I don't know what all proxy.conf files are or where to look for them, and when I say "there doesn't seem to be anything proxy related" doesn't mean I am exactly sure of what I need to keep an eye on. Also I am not sure about the debugging option. If sudo apt update --fix-missing && sudo apt upgrade -o Debug::Acquire::http=true, then there is no difference between this output and the one in the original question – Py-ser Apr 20 '22 at 13:41
  • Let's continue this discussion in chat – Py-ser Apr 20 '22 at 13:54