Created
April 26, 2024 05:01
-
-
Save hrchu/105f01dbe44bb4f36a8250ffe89d2369 to your computer and use it in GitHub Desktop.
ubuntu HTTP proxy switch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Remove proxy settings for various protocols | |
unset http_proxy | |
unset https_proxy | |
unset ftp_proxy | |
unset rsync_proxy | |
# Remove proxy for apt (if exists) | |
sudo rm -f /etc/apt/apt.conf.d/99proxy | |
# Remove proxy for curl | |
rm -f ~/.curlrc | |
# Remove proxy for wget | |
rm -f ~/.wgetrc | |
# Remove Docker proxy configuration | |
sudo rm -f /etc/docker/daemon.json | |
# Restart Docker service for the changes to take effect | |
sudo service docker restart | |
# Display confirmation | |
echo "Proxy settings disabled." | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set the proxy address and port | |
proxy_address="10.160.3.88" | |
proxy_port="8080" | |
# Set proxy settings for various protocols | |
export http_proxy="http://${proxy_address}:${proxy_port}" | |
export https_proxy="http://${proxy_address}:${proxy_port}" | |
# Set proxy for apt (if using apt package manager) | |
echo "Acquire::http::Proxy \"http://${proxy_address}:${proxy_port}\";" | sudo tee /etc/apt/apt.conf.d/99proxy > /dev/null | |
# Set proxy for curl | |
echo -e "proxy = \"http://${proxy_address}:${proxy_port}\"" >> ~/.curlrc | |
# Set proxy for wget | |
echo -e "use_proxy = on\nhttp_proxy = http://${proxy_address}:${proxy_port}\nhttps_proxy = http://${proxy_address}:${proxy_port}" >> ~/.wgetrc | |
# Configure Docker to use the proxy | |
sudo mkdir -p /etc/docker | |
cat <<EOF | sudo tee /etc/docker/daemon.json > /dev/null | |
{ | |
"proxies": { | |
"http-proxy": "http://${proxy_address}:${proxy_port}", | |
"https-proxy": "http://${proxy_address}:${proxy_port}", | |
"no-proxy": "*.test.example.com,.example.org,127.0.0.0/8" | |
} | |
} | |
EOF | |
# Restart Docker service for the changes to take effect | |
sudo service docker restart | |
# Display confirmation | |
echo "Proxy set to ${proxy_address}:${proxy_port} for WSL, Docker, curl, and wget." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment