Skip to content

Instantly share code, notes, and snippets.

@darkato42
Last active August 5, 2023 13:43
Show Gist options
  • Save darkato42/317c0e1a03c3cf8ee644a211be926549 to your computer and use it in GitHub Desktop.
Save darkato42/317c0e1a03c3cf8ee644a211be926549 to your computer and use it in GitHub Desktop.
Change proxy settings in Ubuntu
#!/bin/bash
# Check if the proxy URL is passed as an argument
if [ -z "$1" ]; then
echo "Please provide the full proxy URL as an argument. E.g., ./update_proxy.sh http://192.168.1.3:3333"
exit 1
fi
PROXY_URL="$1"
# Function to update /etc/profile.d/proxy.sh
update_profile_proxy() {
echo "# set proxy config via profie.d - should apply for all users" > /etc/profile.d/proxy.sh
echo "# http/https/ftp/no_proxy" >> /etc/profile.d/proxy.sh
echo "export http_proxy=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh
echo "export https_proxy=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh
echo "export ftp_proxy=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh
echo "export no_proxy=\"127.0.0.1,localhost\"" >> /etc/profile.d/proxy.sh
echo "" >> /etc/profile.d/proxy.sh
echo "# For curl" >> /etc/profile.d/proxy.sh
echo "export HTTP_PROXY=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh
echo "export HTTPS_PROXY=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh
echo "export FTP_PROXY=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh
echo "export NO_PROXY=\"127.0.0.1,localhost\"" >> /etc/profile.d/proxy.sh
}
# Function to update ~/.wgetrc
update_wgetrc() {
echo "use_proxy = on" > ~/.wgetrc
echo "http_proxy = $PROXY_URL/" >> ~/.wgetrc
echo "https_proxy = $PROXY_URL/" >> ~/.wgetrc
echo "ftp_proxy = $PROXY_URL/" >> ~/.wgetrc
}
# Main function to update the proxy settings
update_proxy_settings() {
echo "Updating proxy settings..."
# Call the function to update profile proxy
update_profile_proxy
# Call the function to update wgetrc
update_wgetrc
echo "Proxy settings updated successfully!"
}
# Run the main function
update_proxy_settings
@darkato42
Copy link
Author

# Download the script
wget https://gist.github.com/darkato42/317c0e1a03c3cf8ee644a211be926549/raw/update_proxy.sh

# Make the script executable
chmod +x update_proxy.sh

# Run the script with the proxy URL
sudo ./update_proxy.sh http://192.168.1.100:7890

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment