Linux proxy_switch function

Submitted by ccztux on Fri, 03/31/2017 - 18:53

Append the following function to: /etc/profile and modify the variable: proxy to fit your requirements:


proxy_switch()
{
	local proxy=

	case "$1" in
			on)
				proxy="http://10.0.0.10:3128"
				;;
			off)
				proxy=
				;;
			*)
				printf "Usage: %s on|off\n" "${FUNCNAME[0]}"
				;;
	esac

	export http_proxy="$proxy"
	export https_proxy="$proxy"
	export ftp_proxy="$proxy"
	export socks_proxy="$proxy"
	export HTTP_PROXY="$proxy"
	export HTTPS_PROXY="$proxy"
	export FTP_PROXY="$proxy"
	export SOCKS_PROXY="$proxy"
}

Relogin or source /etc/profile and the new function is available in the CLI:


18:55:52 [user@localhost]:~$ proxy_switch 
Usage: proxy_switch on|off