#!/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环境变量
开启代理
source setproxy.sh on
关闭代理
source setproxy.sh off
查看代理
env|grep -i proxy
使用curl命令测试代理设置
curl ipinfo.io
参考链接:
https://www.sujx.net/2023/07/31/vm-clash/index.html
https://blog.csdn.net/weixin_44984664/article/details/108028704