BashでのProxy設定

投稿者: | 6月 6, 2020

とにかくネットが速くない。実家はすごく速いのに。Wireguardで繋げてあってSynologyでProxyを立ててあるので、そちらからアクセスしたほうが速い。しかし、Linuxでのシェル設定が面倒。作ってみたので晒しておく。

PROXY_HOST=<Proxy Host>
PROXY_PORT=<Proxy Port>
PROXY=”$PROXY_HOST:$PROXY_PORT”
NO_PROXY_HOST=”localhost, 127.0.*, 10.*, 172.16.*, 172.17.*, 172.18.*, 172.19.*, 172.20.*, 172.21.*, 172.22.*, 172.23.*, 172.24.*,172.25.*, 172.26.*, 172.27.*, 172. 28.*, 172.29.*, 172.30.*, 172.31.*, 192.168.*, ifconfig.me”
nc -v -z -w 1 $PROXY_HOST $PROXY_PORT
ret=$?
if [ $ret = 0 ]; then
export http_proxy=”http://$PROXY”
export https_proxy=”http://$PROXY”
export ftp_proxy=”http://$PROXY”
echo “Proxy $PROXY_HOST $PROXY_PORT enabled”
REMOTE_ADDR=`curl -s ifconfig.me`
export no_proxy=”$NO_PROXY_HOST”
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$https_proxy
export FTP_PROXY=$ftp_proxy
export NO_PROXY=”$no_proxy”
echo “Remote address is $REMOTE_ADDR”
else
unset http_proxy
unset https_proxy
unset ftp_proxy
unset no_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset FTP_PROXY
unset NO_PROXY
echi “Proxy_is not set…”
fi

これを/etc/profile.d配下に置いておけばいい。たかがProxyとのことなのだが、たまにSynologyを撤去しちゃうからSynologyのProxyが開いていれば設定するし、開いてなかったらProxyの設定を無効にするという設定をいれておいた。ちなみにifconfig.meをプロキシ経由しないようにしておいた。

コメントを残す