Problems with YUM through a proxy in CentOS 5.2

I found a problem trying to use yum through a proxy in CentOS 5.2, alias CentOS 5(final), maybe a bug. I found some workarounds searching in Google, but they were dirty workarounds...

The problem:
When you try your first connection with yum, even if you have added the proxy in '/etc/yum.conf', you got this error:

[root@box ~]# yum update kernel*

[...]

=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Installing:
 kernel                  x86_64     2.6.18-92.1.10.el5  updates            16 M
 kernel-devel            x86_64     2.6.18-92.1.10.el5  updates           5.0 M
Updating:
 kernel-headers          x86_64     2.6.18-92.1.10.el5  updates           883 k

Transaction Summary
=============================================================================
Install      2 Package(s)         
Update       1 Package(s)         
Remove       0 Package(s)         

Total download size: 22 M
Is this ok [y/N]: y

Downloading Packages:
(1/3): kernel-2.6.18-92.1 100% |=========================|  16 MB    00:39     
(2/3): kernel-headers-2.6 100% |=========================| 883 kB    00:02     
(3/3): kernel-devel-2.6.1 100% |=========================| 5.0 MB    00:12     

warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897


GPG key retrieval failed: [Errno 4] IOError: <urlopen error (113, 'No route to host')>

After some testing I found that yum was not contacting the proxy to retrieve that GPG key, so somewhere in yum there is a routine that it is not reading '/etc/yum.conf'
Fortunately it can read environment variables...

The workaround:
First of all be sure you have properly added your proxy in '/etc/yum.conf'

echo 'proxy=http://myproxy.domain.com:3128/' >> /etc/yum.conf

Use always append ( >> ) to avoid overwriting your 'yum.conf' file.
Then, just for the first time, run yum with this command to update the kernel or whatever you wish to update or install:

[root@box ~]# http_proxy="http://myproxy.domain.com:3128/" yum update kernel*  

You only need to run yum in this way the first time you use it, after it downloads the 'GPG key' everything should work properly.
That's all.


Back
Salvatore Toribio

20080909