目錄
前言
之前都是使用帶有gui界面的***,但是如果在服務器上面,需要用純命令行來操作的時候,又應該怎麼辦呢?
方法
解決方案就是 shadowsocks+ Privoxy。 使用shadowsock建立一個本地sock5代理, 但因爲在命令行中不能直接使用sock5,所以所以需要使用privoxy把sock5代理轉爲http代理。
Shadowsocks篇
安裝Shadowsocks
pip install shadowsocks # pip安裝ss客戶端
如果提示 -bash: pip: command not found
運行 yum -y install python-pip
編輯 shadowsocks配置文件:
vim /etc/shadowsocks.json
{
"server":"SERVER-IP", # 你的服務器ip
"server_port":PORT, # 服務器端口
"local_address": "127.0.0.1",
"local_port":1080,
"password":"PASSWORD", # 密碼
"timeout":300,
"method":"aes-128-cfb", # 加密方式
"fast_open": false,
"workers": 1
}
運行sslocal。我比較喜歡在screen中運行命令,所以在screen中運行運行sslocal。如果不在screen中運行的話,可以在前面加*nohup*。
sslocal -c /etc/shadowsocks.json &
Privoxy篇
安裝Privoxy
yum -y install privoxy
配置Socks5全局代理
修改privoxy的config文件,打開 /etc/privoxy/config
vim /etc/privoxy/config
找到類似於這樣的,listen-address localhost:8118然後把它註釋掉。前面加#即可註釋 。
然後在最後一行加這些內容,並保存關閉:
forward-socks5 / 127.0.0.1:1080 .
listen-address 127.0.0.1:8118
配置http,https代理:
(1)臨時配置,可以先直接export一下臨時用着,只不過重啓電腦之後,又需要再次export一遍。
export http_proxy=http://127.0.0.1:8118 # privoxy默認監聽端口爲8118
export https_proxy=http://127.0.0.1:8118
(2)也可以有個一勞永逸的方法:
(2.1)設置當前用戶的全局代理
修改bashrc文件
vim ~/.bashrc
添加下面的內容,wq保存
export http_proxy=http://127.0.0.1:8118
export https_proxy=http://127.0.0.1:8118
export ftp_proxy=http://127.0.0.1:8118
立即生效
source ~/.bashrc
(2.2)設置當前用戶的全局代理
# 修改profile文件
vim /etc/profile
# 添加下面的內容,wq保存。
export http_proxy=http://127.0.0.1:8118
export https_proxy=http://127.0.0.1:8118
export ftp_proxy=http://127.0.0.1:8118
# 立即生效
source /etc/profile
至此Privoxy配置完成。
運行Privoxy:
sudo service privoxy start
還有幾個命令:
關閉: sudo service privoxy stop
顯示運行狀態: sudo service privoxy status
測試
執行命令:
http_proxy=http://localhost:8118 curl ip.gs
或者
curl ip.gs
根據地區可以判斷成功與否:
Current IP / 當前 IP: *.*.*.*
ISP / 運營商: *.com
City / 城市: London
Country / 國家: United Kingdom
Please join Telegram group https://t.me/sbfans if you have any issues. / 如有問題,請加入 Telegram 羣 https://t.me/sbfans
/\_/\
=( °w° )=
) ( //
(__ __)//
————————————————
這裏有一個問題是,用ping依然是拼不通Google的,因爲ping不是走http這些通道。
參考:
https://www.cnblogs.com/straycats/p/8452354.html
https://gist.github.com/alexniver/9a4f1791fe4305b0750a
http://404-notfound.cn/CentOS命令行使用SS代理的方法/
https://blog.forecho.com/ubuntu-use-shadowsocks-and-privoxy.html