版本比较

标识

  • 该行被添加。
  • 该行被删除。
  • 格式已经改变。

1.创建脚本 setproxy.sh

代码块
#!/bin/bash
# encoding: utf-8

Proxy_IP=192.168.5.222
Proxy_Port=7890

# Set System Proxy
function xyon(){
    export https_proxy=http://$Proxy_IP:$Proxy_Port
    export http_proxy=http://$Proxy_IP:$Proxy_Port
    export all_proxy=socks5://$Proxy_IP:$Proxy_Port
    echo -e "System Proxy is $Proxy_IP:$Proxy_Port"
}

# unSet System Proxy
function xyoff(){
    unset all_proxy
    unset https_proxy
    unset http_proxy
    echo -e "System Proxy is Disabled"
}

# Default Function is Set Proxy
if [ $# != 0 ]
then
	if [ $1 == 'off' ]
	then
		xyoff
	elif [ $1 == 'on' ]
	then
		xyon
	else
		echo "Please Input on or off!"
	fi
else
	echo "Please input command."
fi

需要注意192.168.5.222,是台式机局域网IP,非VMware网卡IP。

代码块
chmod +x setproxy.sh

...

因为父子shell的问题,使用source来使得脚本设置来修改当前父Shell环境变量

...


2.开启代理

代码块
source setproxy.sh on

...


3.关闭代理

代码块
languagebash
source setproxy.sh off


4.查看代理

代码块
languagebash
env|grep -i proxy

使用curl命令测试代理设置

代码块
languagebash
curl ipinfo.io


参考链接:

https://www.sujx.net/2023/07/31/vm-clash/index.html

...