How to configure http proxy exceptions on Linux

When you are behind HTTP proxy, you need to configure proxy settings for your applications in one way or another. Typically you define http_proxy environment variable pointing to your proxy, so that all HTTP requests go through the proxy. But what if you want to bypass HTTP proxy for specific destination web servers? That's when you need to configure HTTP proxy exceptions.

On Linux, you can define HTTP proxy exceptions via "no_proxy" environment variable. In "no_proxy" variable, you specify a list of domain names or IP addresses for which HTTP proxy should not be used. Along with domain names or IP addresses, you can also specify port number if necessary.

If you would like to define HTTP proxy exceptions system wide, do the following.

On Ubuntu, Debian or Mint:

$ sudo vi /etc/environment
http_proxy="http://proxy.com:8000"
no_proxy="127.0.0.1, localhost, *.cnn.com, 192.168.1.10, domain.com:8080"

On CentOS, Fedora or RHEL:

$ sudo vi /etc/profile.d/proxy.sh
export http_proxy="http://proxy.com:8000"
export no_proxy="127.0.0.1, localhost, *.cnn.com, 192.168.1.10, domain.com:8080"

The above example means that if you are reaching local host (e.g., 127.0.0.1, localhost), *.cnn.com, domain.com:8080, or a host with IP address 192.168.1.10, you will not use HTTP proxy. For all other destinations, you will use the designated HTTP proxy (proxy.com:8000).

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

One thought on “How to configure http proxy exceptions on Linux

  1. Hi Dan,

    Thank you for the information. Just a quick question: when a Linux box is behind a proxy which requires Windows domain credentials, say Forefront TMG, proxy configuration becomes a mess.

    You can go edit /etc/profile.d/proxy.sh to include
    export proxy_username=tolga@domain.com
    export proxy_password=12345678
    export http_proxy="http://$proxy_username:$proxy_password@10.0.0.10:1325"
    export https_proxy="https://$proxy_username:$proxy_password@10.0.0.10:1325"

    However when you echo $proxy_username, you receive tolgadomain.com. Even if you

    export proxy_username=domain.com\tolga
    or
    export proxy_username=domain.com\\tolga

    echo $proxy_username returns tolgadomain.com and thus does not authenticate with the proxy server.

    Any ideas?

    Thank you,
    Tolga

Leave a comment

Your email address will not be published. Required fields are marked *