setting_network_proxy - dwilson2547/wiki_demo GitHub Wiki
To configure a system-wide proxy for command-line tools (e.g., curl
, wget
, apt
, git
), you can add proxy settings to your .bashrc
file. This ensures that all terminal sessions inherit the proxy configuration.
- 1. Open
.bashrc
- 2. Add Proxy Settings
- 3. Example Configuration
- 4. Save and Apply Changes
- 5. Verify Proxy Settings
- 6. Test the Proxy
- 7. Configure Proxy for Specific Tools
- 8. Authentication (If Required)
- 9. Disable Proxy Temporarily
- 10. Permanent Proxy for All Users
- 11. Troubleshooting
- 12. Example: Full
.bashrc
Proxy Configuration - 13. Notes
Edit your .bashrc
file in your home directory:
nano ~/.bashrc
Add the following lines to the end of the file, replacing proxy-server-ip
and port
with your proxy server’s address and port (e.g., 192.168.1.100:8080
):
export http_proxy="http://proxy-server-ip:port"
export HTTP_PROXY="$http_proxy"
export https_proxy="http://proxy-server-ip:port"
export HTTPS_PROXY="$https_proxy"
export ftp_proxy="http://proxy-server-ip:port"
export FTP_PROXY="$ftp_proxy"
export no_proxy="localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8"
export NO_PROXY="$no_proxy"
# Proxy settings
export http_proxy="http://192.168.1.100:8080"
export HTTP_PROXY="$http_proxy"
export https_proxy="http://192.168.1.100:8080"
export HTTPS_PROXY="$https_proxy"
export ftp_proxy="http://192.168.1.100:8080"
export FTP_PROXY="$ftp_proxy"
export no_proxy="localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8"
export NO_PROXY="$no_proxy"
- Save the file (
Ctrl+O
, thenEnter
innano
). - Exit the editor (
Ctrl+X
innano
). - Reload
.bashrc
to apply the changes:source ~/.bashrc
Check if the environment variables are set:
env | grep -i proxy
Output should look like:
http_proxy=http://192.168.1.100:8080
HTTPS_PROXY=http://192.168.1.100:8080
no_proxy=localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8
Test the proxy with curl
or wget
:
curl -I https://google.com
or
wget -qO- https://google.com
Create or edit /etc/apt/apt.conf.d/proxy.conf
:
sudo nano /etc/apt/apt.conf.d/proxy.conf
Add:
Acquire::http::Proxy "http://proxy-server-ip:port";
Acquire::https::Proxy "http://proxy-server-ip:port";
Configure Git to use the proxy:
git config --global http.proxy http://proxy-server-ip:port
git config --global https.proxy http://proxy-server-ip:port
Configure npm to use the proxy:
npm config set proxy http://proxy-server-ip:port
npm config set https-proxy http://proxy-server-ip:port
Edit /etc/yum.conf
:
sudo nano /etc/yum.conf
Add:
proxy=http://proxy-server-ip:port
If your proxy requires authentication, include the username and password in the proxy URL:
export http_proxy="http://username:password@proxy-server-ip:port"
export https_proxy="http://username:password@proxy-server-ip:port"
To temporarily disable the proxy, unset the environment variables:
unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY ftp_proxy FTP_PROXY no_proxy NO_PROXY
To set the proxy system-wide (for all users), add the proxy settings to /etc/environment
:
sudo nano /etc/environment
Add:
http_proxy="http://proxy-server-ip:port"
HTTP_PROXY="http://proxy-server-ip:port"
https_proxy="http://proxy-server-ip:port"
HTTPS_PROXY="http://proxy-server-ip:port"
ftp_proxy="http://proxy-server-ip:port"
FTP_PROXY="http://proxy-server-ip:port"
no_proxy="localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8"
NO_PROXY="localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8"
- Connection Refused: Verify the proxy server is running and the port is open.
- Authentication Failed: Ensure the username and password are correct.
-
DNS Issues: Add
use_proxy_dns=true
to the proxy URL if DNS resolution fails. -
SSL/TLS Errors: Use
https_proxy
for HTTPS traffic and ensure certificates are trusted.
# Proxy settings
export http_proxy="http://192.168.1.100:8080"
export HTTP_PROXY="$http_proxy"
export https_proxy="http://192.168.1.100:8080"
export HTTPS_PROXY="$https_proxy"
export ftp_proxy="http://192.168.1.100:8080"
export FTP_PROXY="$ftp_proxy"
export no_proxy="localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8"
export NO_PROXY="$no_proxy"
# Alias to toggle proxy
alias proxy-on='source ~/.bashrc'
alias proxy-off='unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY ftp_proxy FTP_PROXY no_proxy NO_PROXY'
- Proxy settings in
.bashrc
only affect command-line tools and terminal sessions. GUI applications may require separate proxy configurations. - For systemd services, configure proxies in the service’s environment file (e.g.,
/etc/systemd/system/service-name.service.d/override.conf
). - Use
export -p
to list all exported environment variables.