2

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

2

The proposed solution can't work in the general case - it assumes that everything will acknowledge and use the Environment variable.

In order to make this work for HTTP, you need to set u a "Transparent Proxy", which generally requires IPTABLES nat rules to capture and redirect the traffic. Have a look here for how to do this.

Doing the same thing for HTTPS is practical but you will need to additionally install a CA in SQUID and accept it in the Ubuntu box so it can intercept the traffic.

This might not be practical with FTP (I've not tried it)

| improve this answer | |
1

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.

| 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
  • do we still need to configure url in the browser to access internet through proxy ?? ( eq. inside firefox settings > Configure proxies to access internet ) – pkm Aug 5 '17 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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