Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following setup:

  • Windows 7 computer
  • Installation of Ruby, Vagrant, VirtualBox
  • VBox image Ubuntu 14.x
  • Working in the intranet of my company that needs a proxy to access the internet

I am able to configure the VBox image for the user vagrant to access the internet by setting the environment variable http_proxy to our proxy. However, when I try to set the proxy in a shell provisioner, I have problems. Here are the parts of the script that define the proxy, and the parts that make the first access to the internet:

# Base setup proxy and DISPLAY
set HTTP_PROXY=http://proxy.name.com:8080
echo "Add proxy to necessary parts"
echo 'export http_proxy=http://proxy.name.com:8080' >> ~vagrant/.bash_profile
echo 'export DISPLAY=192.168.137.1:0.0' >> ~vagrant/.bash_profile
echo 'export http_proxy=http://proxy.name.com:8080' >> /root/.bash_profile
export http_proxy=$HTTP_PROXY

# Install Git
echo "Install Git"
apt-get update
apt-get install -y git
...

However, I get the following output:

Add proxy to necessary parts
Install Git
Err http://security.ubuntu.com trusty-security InRelease

Err http://archive.ubuntu.com trusty InRelease

Err http://archive.ubuntu.com trusty-updates InRelease

Err http://security.ubuntu.com trusty-security Release.gpg
  Could not resolve 'security.ubuntu.com'
Err http://archive.ubuntu.com trusty Release.gpg
  Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-updates Release.gpg
  Could not resolve 'archive.ubuntu.com'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease
...

How can I set inside a Unix script the proxy and use it immediately, so that apt-get, git clone, ... could be used?

share|improve this question

migrated from serverfault.com Nov 9 '14 at 17:59

This question came from our site for system and network administrators.

3 Answers 3

up vote 4 down vote accepted

There's a plugin for it!

Install vagrant-proxyconf:

vagrant plugin install vagrant-proxyconf

Configure it (in $HOME/.vagrant.d/Vagrantfile for all Vagrant VMs):

Vagrant.configure("2") do |config|
  if Vagrant.has_plugin?("vagrant-proxyconf")
    config.proxy.http     = "http://10.206.246.20:8080"
    config.proxy.https    = "http://10.206.246.20:8080"
    config.proxy.no_proxy = "localhost,127.0.0.1"
  end
end
share|improve this answer
    
Will give it a try when I am in my company network again. Thank's for the idea! –  mliebelt Nov 9 '14 at 9:59
    
Worked like a charm. That is the more canonical solution, so I have taken this one instead of the one by f01 –  mliebelt Nov 10 '14 at 15:48

I tried this and it works, removed set.

HTTP_PROXY=http://10.206.246.20:8080 export http_proxy=$HTTP_PROXY

share|improve this answer
1  
I will check this, and will come back in a minute. But looks promising (don't remember where SET is necessary, Windows?). –  mliebelt Nov 7 '14 at 10:37
1  
In BASH, set is for setting shell options stuff. :) –  f01 Nov 7 '14 at 10:39
1  
Worked, found the next syntax error, but now I am able to get things from the internet. Great! –  mliebelt Nov 7 '14 at 10:45
    
I have marked the solution by tmatilai as the right one, because it is the solution that fits much better. –  mliebelt Nov 10 '14 at 15:49
    
In Bash we use "export", in Fish we use "set". Windows, what is that? –  Achmed Durangi Jul 3 at 9:13

There is no point install plugins when you can't even access to internet.

On Windows, you can set as below:

set HTTP_PROXY=http://192.168.0.1:8080

set HTTPS_PROXY=https://192.168.0.1:8080"

This should work.

share|improve this answer
    
Sorry, wrong answer. I want to set the proxy automatically in the linux environment provisioned by Vagrant. I have access to the internet, and want a solution that does the provisioning for me. The installation of the plugin is done in the host environment (which is Windows) ... –  mliebelt Jan 1 at 16:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.