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've set up a squid forward proxy to cache all internet requests. I have a public ip and opened port 3128. Now I just need to set my ubuntu server to force all internet connections to pass through this proxy, using the ip address and port number.

I know this command which will make ubuntu access the internet via a proxy, but I was told it wasn't permanent.

export http_proxy="http://proxy.example.com:8080"

Which command do I need to use to force ubuntu to go through this proxy regardless of reboots or sessions?

Thanks

share|improve this question
    
Put that line into your ~/.bash_profile –  hvtuananh Jul 19 '13 at 19:40
add comment

1 Answer

You have to set some settings in /etc/environment to make it permanent:

  • Open the /etc/environment file with vi (or your favorite editor). This file stores the system-wide variables initialized upon boot.
  • Add the following lines, modifying appropriately. You must duplicate in both upper-case and lower-case because (unfortunately) some programs only look for one or the other:

     http_proxy=http://myproxy.server.com:8080/
    https_proxy=http://myproxy.server.com:8080/
    ftp_proxy=http://myproxy.server.com:8080/
    no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
    HTTP_PROXY=http://myproxy.server.com:8080/
    HTTPS_PROXY=http://myproxy.server.com:8080/
    FTP_PROXY=http://myproxy.server.com:8080/
    NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com" 
  • apt-get, aptitude, etc. will not obey the environment variables when used normally with sudo. So separately configure them; create a file called 95proxies in /etc/apt/apt.conf.d/, and include the following:

     Acquire::http::proxy "http://myproxy.server.com:8080/";
    Acquire::ftp::proxy "ftp://myproxy.server.com:8080/";
    Acquire::https::proxy "https://myproxy.server.com:8080/";   

Finally, logout and reboot to make sure the changes take effect.

share|improve this answer
    
Right, I've performed all of the steps and added the settings. However CGI scripts seem to ignore the rules. What do I need to do to have CGI scripts also obey them? –  jc.yin Jul 19 '13 at 19:53
    
Do you have logged out and in after you changed it? –  donothingloop Jul 19 '13 at 19:57
    
Well I've rebooted the server.. so shouldn't that mean I've logged in and out? But still CGI scripts that make internet connections outside seem to ignore the environment wide rules –  jc.yin Jul 19 '13 at 22:17
add comment

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.