When working with the $http_proxy
environment variable in Linux, many developers encounter situations where certain internal network resources shouldn't go through the proxy. Unlike GUI browsers that provide proxy exception settings, command-line tools and some applications rely solely on environment variables.
Here are several methods to handle proxy exceptions when using $http_proxy
:
1. Using no_proxy Environment Variable
The most straightforward solution is to set the no_proxy
environment variable alongside $http_proxy
:
export http_proxy="http://proxy.example.com:8080"
export no_proxy="localhost,127.0.0.1,192.168.1.0/24,.internal.example.com"
2. Application-Specific Configuration
Some applications have their own proxy exception settings. For Chromium specifically:
chromium --proxy-server="http://proxy.example.com:8080" \
--proxy-bypass-list="*.internal.example.com,192.168.*.*"
For more complex scenarios, consider these approaches:
PAC File Solution
Create a Proxy Auto-Config (PAC) file:
function FindProxyForURL(url, host) {
// Bypass proxy for internal domains
if (shExpMatch(host, "*.internal.example.com") ||
isInNet(host, "192.168.1.0", "255.255.255.0")) {
return "DIRECT";
}
// Use proxy for all other requests
return "PROXY proxy.example.com:8080";
}
Then configure Chromium to use it:
chromium --proxy-pac-url="file:///path/to/proxy.pac"
Shell Script Wrapper
Create a wrapper script that dynamically adjusts proxy settings:
#!/bin/bash
# Check if target is in exception list
if [[ "$1" =~ ^192\.168\. ]] || [[ "$1" == "internal.example.com" ]]; then
unset http_proxy https_proxy
else
export http_proxy="http://proxy.example.com:8080"
export https_proxy="$http_proxy"
fi
# Execute the original command
shift
exec "$@"
When proxy exceptions don't work as expected:
- Verify the
no_proxy
format - domains should be comma-separated without spaces - Check for CIDR notation support in your application
- Test with
curl -v
to see if the proxy is being bypassed - Remember that some applications may cache proxy settings
For persistent settings across all users, add these to /etc/environment
:
http_proxy="http://proxy.example.com:8080"
no_proxy="localhost,127.0.0.1,.internal.example.com"
When working behind corporate proxies in Linux environments, we often set the $http_proxy
environment variable to route traffic through intermediary servers. However, many applications (like Chromium, wget, curl) that respect this variable don't natively support proxy exceptions - a critical requirement when accessing internal resources.
The most effective way to handle proxy exceptions is through the $NO_PROXY
environment variable (sometimes called $no_proxy
). This works alongside $http_proxy
to define bypass rules:
export http_proxy="http://proxy.example.com:8080"
export HTTPS_PROXY="http://proxy.example.com:8080"
export no_proxy="localhost,127.0.0.1,192.168.1.0/24,.internal.example.com"
The variable accepts multiple formats for different matching scenarios:
- IP Addresses:
192.168.1.100
- IP Ranges:
192.168.1.0/24
- Domain Names:
.example.com
(matches all subdomains) - Hostnames:
internal-server
While many tools respect NO_PROXY
, some require special handling:
For Chromium/Chrome
Create a wrapper script or modify your .bashrc
:
#!/bin/bash
export no_proxy="localhost,127.0.0.1,192.168.*,.corp"
/usr/bin/chromium-browser --proxy-server="$http_proxy" --no-proxy-server="$no_proxy" "$@"
For cURL
cURL has excellent proxy exception support:
curl --noproxy "*.internal,192.168.*,localhost" https://internal-site
For System-wide Configuration
Add to /etc/environment
for all users:
http_proxy="http://proxy.example.com:3128"
no_proxy="localhost,127.0.0.1,.localdomain,.example.com,192.168.1.0/24"
If exceptions aren't working:
- Verify variable names (some tools expect lowercase
no_proxy
) - Check for IP range syntax support (CIDR notation may not work everywhere)
- Test with basic patterns first (
localhost
) - Use
env
command to confirm environment variables are set