23

If I want to have GNOME applications (as well as Firefox and Chrome) access the network through a proxy, I need only use gnome-network-properties (a nice and simple GUI I must say). For other apps (e.g. APT, Transmission, XChat), I have to use their specific ways of doing it.

Is there a way to avoid this, something I can turn on and off when in a network that requires a proxy (hostname:port)?

tshepang
  • 64,472
  • 86
  • 223
  • 290
  • 1
    I think that the `http_proxy` variable is what you're looking for. Take a look in the [Proxy Support](http://ubuntuforums.org/showthread.php?t=1575) howto. – sakisk Mar 18 '11 at 08:28
  • I do believe a VPN is the best solution. It is straight forward and realistic. A VPN acts as a relay which is what the network will want. – nicholas macnutt Aug 05 '20 at 10:57

8 Answers8

12

I think pretty much all linux/unix software that uses networking will honor the http_proxy and ftp_proxy environment variables. Depending on how your distribution is set up, /etc/environment will exist and be read by default by login shells.

You can add a line saying

http_proxy=123.45.67.89:1011

in /etc/environment easily enough, but changes in that file will only take hold the next time you start a shell process -- and only in that shell process. I don't think you can modify global variables in a shell other than your current one.

Shadur
  • 30,641
  • 11
  • 58
  • 69
7

I agree that the best way to use the proxy server is with the environment variable http_proxy, as other answers have pointed out. Unfortunately, not all applications honour the http_proxy environment variable, which is why I still use tsocks for some programs to use LD_PRELOAD to force network connections to go through a SOCKS proxy.

jsbillings
  • 24,006
  • 6
  • 56
  • 58
4

Besides tsocks — which still AFAICT requires you to launch programs with the correct environment to work — you should check out tun2socks. With it you set up a TUN interface (i.e. a new network interface, just like a VPN would create) and any packets sent there get proxied to your SOCKS5 server. You then set up your system routes to actually send the traffic to this. Seems like a nice approach.

(I also found redsocks via this post. This doesn't seem as elegant as using a TUN interface to me — e.g. it doesn't really handle UDP at all, for starters.)

Brad Parks
  • 1,619
  • 3
  • 22
  • 38
natevw
  • 174
  • 8
4

I use this tool, which is basically a couple of scripts to configure settings for different applications from single point.

PS: I wrote and maintain that tool.

3

There's no one-for-all solution. Each program uses its own way to connect to a proxy server.

I have a similar problem at my office. I found that best way to do this is to use a VPN connection. When you connect, the whole system network traffic will go through the VPN. If you don't have access to a VPN server, you can run a new one manually, and connect it to the proxy server you've got.

If you have an application that doesn't support proxy, you can use something like socksify, to wrap its network connection.

Aidin
  • 384
  • 2
  • 4
  • So you've tried [this](http://unix.stackexchange.com/questions/9517/is-there-a-way-to-set-network-proxy-system-wide/9519#9519) and failed? – tshepang Mar 18 '11 at 11:02
2

This worked for me
vi /etc/environment:

http_proxy="http://username:password@proxysrv:8080/"
https_proxy="https://username:password@proxysrv:8080/"
ftp_proxy="ftp://username:password@proxysrv:8080/"
no_proxy=".mylan.local,.domain1.com,host1,host2"

also
vi /etc/yum.conf:

proxy=http://proxysrv:8080
danilopopeye
  • 105
  • 3
0

I have a similar issue, but for me to accomplish a system wide proxy will be addressing Linux's kernel iptables. Adding and removing forwarding rules in the iptables (specific addresses,ports & protocols), acting on the network layer is the only way to ensure a system wide proxy, that can't be overridden by any app-specific settings in the application layer.

tshepang
  • 64,472
  • 86
  • 223
  • 290
0

In addtion to Shawn Jones resolution,

theres also a CHEATY lazy solution

http_proxy="http://username:password@proxysrv:8080/"
https_proxy=$http_proxy

if you need to setup also for the other it will only be required to write once.

djdomi
  • 121
  • 8