/etc/bashrc
/etc/profile
~/.profile
~/.bashrc
以上任意文件添加以下内容:
# add for proxy
export hostip=$(ip route | grep default | awk '{print $3}')
export hostport=10810
#export HTTPS_PROXY="socks5://${hostip}:${hostport}"
#export HTTP_PROXY="socks5://${hostip}:${hostport}"
#export ALL_PROXY="socks5://${hostip}:${hostport}"
alias proxy='
export HTTPS_PROXY="socks5://${hostip}:${hostport}";
export HTTP_PROXY="socks5://${hostip}:${hostport}";
export ALL_PROXY="socks5://${hostip}:${hostport}";
'
alias unproxy='
unset HTTPS_PROXY;
unset HTTP_PROXY;
unset ALL_PROXY;
'
以上配置的端口
hostport
为socks的局域网端口,这个是v2ray的默认值,如果想走http
协议可以将代理设置为http://${hostip}:10811
。
配置完成后,开启代理直接在终端输入proxy
,取消代理输入unproxy
。
开启代理后,可以使用以下命令验证:
curl www.google.com.hk
curl cip.cc
注意:ping www.google.com是无法连通的,因为ping走的是网络层的IMCP协议,不经过传输层和应用层。
参考:https://zhuanlan.zhihu.com/p/46973701