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!

Could not fetch specs from https://rubygems.org/: Ruby Gems behind the corporate firewall

Image

This error might be a case of running bundle, or gem install behind a (corporate) firewall. To be able to get through, you have to specify the HTTP_PROXY environment for your session.

Image

Type the following on your current session:

set HTTP_PROXY=http://your_username:your_passoword@server:port

Also, I haven’t checked if the character case of the HTTP_PROXY matters. So to be sure, type the variable name using UPPERCASES.

To check if the variable was set, just type:

set HTTP_PROXY

If it was properly set in the previous step, then the variable-value pair will show up.

For more info, you may visit the ff. sites:

  • The source of the solution above:

http://stackoverflow.com/questions/4418/how-do-i-update-ruby-gems-from-behind-a-proxy-isa-ntlm

  • Parameter –http-proxy from inside the gem.bat (an alternative so you won’t need to set environment variable HTTP_PROXY over and over again, but I haven’t tested it):

http://stackoverflow.com/questions/1903005/installing-gems-from-behind-a-corporate-firewall

  • If you feel like giving up and chose to do a manual work-around (this works, and this is the long-cut):

http://help.rubygems.org/kb/rubygems/installing-gems-with-no-network