Linux开启网络代理

/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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值