Ubuntu proxies – Grant your server access through the firewall

Once again I bumped into a proxy issue, but now I’m inside a *nix environment.

I recently installed an Ubuntu 12.04.3 LTS server inside a virtual box, primarily to be used as a web server for my GitLab repo management. I was following this installation guide when suddenly in step 2, I encountered an error, something like this:

curl: (7) couldn't connect to host

Curl couldn’t seem to connect and download the ruby-2.0.0-p247.tar.gz file. Well since I thought this is just an isolated case, I opted to manually download the file and untar it. This is all fine with me until I encountered the next error:

ERROR:  Could not find a valid gem 'bundler' (>=0), here is why:
          Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT::
 Connect timed out - connect(2) (https://rubygems.org/latest_specs.4.8.gz)

This is just annoying because I know very much that this is a proxy issue. I’ve encountered this in the windows environment and I managed to fix it, as elaborated in this post. But inside ubuntu, much more a server, without any GUI (definitely not my cup of tea), I braced myself for a daunting task. Good thing, through hours of research, these valuable info popped out and saved me from spending precious time troubleshooting stuff.

Below is the gist of the links above (credits to Baltusaj, geirha, Julian Knight, izx and the others involved in the discussion).

 

WAYS TO IMPLEMENT THE PROXY

 

>> ONE-AND-DONE USAGE

If you need to access the internet but you don’t want your proxy getting saved on a configuration file, you can do this:

sudo env http_proxy=http://<user>:<password>@<server>:<port> apt-get update

The magic command is the env http_proxy because this will carry your credentials to be able to pass through the wall.

 

>> THROUGH CONFIGURATION FILES

If you think you’d need to go back and forth through the firewall, typing the commands mentioned in the previous point would be a hassle. Below are the options:

:: Through the environment configuration file

This is the setup that worked for me.

  1. Open /etc/environment file
  2. Add the ff. variable-value pairs (enter both upper and lower case variables since applications only look for one or the other:
    1. http_proxy="http://<server>:<port>"
    2. HTTP_PROXY="http://<server>:<port>"
    3. https_proxy="http://<server>:<port>"
    4. HTTPS_PROXY="http://<server>:<port>"
    5. ftp_proxy="http://<server>:<port>"
    6. FTP_PROXY="http://<server>:<port>"
    7. no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
    8. NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"
  3. Save it and you’re done

 

:: Through the 95proxies configuration file

According to izx of askubuntu.com, In some cases, apt-get, aptitude, etc. will not obey the environment variables when used normally with sudo. Configure them separately inside this file.

  1. Open /etc/apt/apt.conf.d/ directory
  2. If the 95proxies file does not exist, make one
  3. Add the ff. variable-value pairs:
    1. Acquire::http::proxy "http://<server>:<port>";
    2. Acquire::https::proxy "https://<server>:<port>";
    3. Acquire::ftp::proxy "ftp://<server>:<port>";
  4. Save it and you’re done

 

DON’T FORGET TO RESTART YOUR SERVER.

 

Enjoy!