山间明月文化传媒作品集 既然选择了远方,便只顾风雨兼程

mac系统如何设置socks代理

If you're somewhere that has a network that is partly blocked, but allows SSH, or if you are in a coffee shop or something similar and are worried about security, you can setup a SOCKS proxy to route all your traffic via a remote server that you control, and then out onto the Internet.


Setup SOCKS proxy

First, you need to SSH to the remote machine with some special parameters:

ssh -vND 8888 user@host.com

Some detail on those options:

-v verbose mode; useful for debugging
-N don't start an interactive shell on the remote server
-D setup the SOCKS proxy on port 8888 on localhost


直接上我自己用的脚本:

#!/bin/bash

while [ '' == '' ]
do
    ping -q -c5 baidu.com > /dev/null

    if [ $? -eq 0 ]
    then
        ssh_d_process_num=`ps aux|grep -E 'ssh \-' |grep -v grep |wc -l`
        if [ $ssh_d_process_num == 0 ]; then
            /usr/local/bin/sshpass -p "654321" ssh -ND 8080 sshuser@server &
        fi
    fi

    sleep 60
done


实现每分钟检测一次,如果中断,自动重连。


关于如何安装 sshpass 命令,点击传送门:https://gist.github.com/arunoda/7790979

标签: mac代理

作者:松鼠先生 分类:技术分享 浏览:1467 评论:0
留言列表
发表评论
来宾的头像