背景
筆者租賃了華為雲服務器,其中兩台沒有彈性IP,不能連接互聯網,限制需要在能上網的開一個http代理,
以供其他不能上網的使用(apt /apt-get需要http代理,否則無法更新)。
在代理服務器(192.168.0.83)執行以下命令
安裝tinyproxy包 sudo apt-get update sudo apt-get install tinyproxy
編輯配置文件
vim /etc/tinyproxy/tinyproxy.conf
#修改端口為10838Port 10838
#只允許指定網段登錄
Allow 192.168.0.0/24
設置默認啟動
sudo service tinyproxy start
運行及重啟
#重啟 sudo service tinyproxy restart #啟動 sudo service tinyproxy start
測試是否啟動成功(以下說啟動成功)
lsof -i:10838
登錄需要上網代理的服務器
vim ~/.bashrc #shift+G到尾部,添加以下代碼 export HTTPS_PROXY="http://192.168.0.83:10838" export HTTP_PROXY="http://192.168.0.83:10838" export https_proxy="http://192.168.0.83:10838" export http_proxy="http://192.168.0.83:10838"
使配置生效
source ~/.bashrc
測試是否有效
apt update成功
參考:
https://blog.csdn.net/qq_27047075/article/details/104164043
https://www.cnblogs.com/andrewwang/p/9293031.html