有两台计算机A、B,其中B调好了外网,A只有内网。为了让A也能够更新软件,需要在B上配置HTTP代理。

计算机A:只能访问内网,无法下载软件;ip:192.168.9.26
计算机B:可以访问内网和外网 ip:192.168.55.250

计算机B做代理,让计算机A通过B 访问外网。

计算机B安装squid 做代理上网

sudo apt-get install squid
cd /etc/squid3
cp squid.conf  squid.conf_bak
vi squid.conf 

http_access deny all 改为 http_access allow all

添加ip限制(第一次没有添加地址限制,无法代理成功;也可以做地址段限制
acl localnet src 192.168.9/24)

acl localnet src 192.168.9.26
http_access allow localnet

Default:
Deny, unless rules exist in squid.conf.
#
#
Recommended minimum Access Permission configuration:
#
Deny requests to certain unsafe ports
http_access deny !Safe_ports
Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports
Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager
We strongly recommend the following be uncommented to protect innocent
web applications running on the proxy server who think the only
one who can access services on "localhost" is a local user
http_access deny to_localhost
#
INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
Example rule allowing access from your local networks.
Adapt localnet in the ACL section to list your (internal) IP networks
from where browsing should be allowed
acl localnet src 192.168.9.26
http_access allow localnet

http_access allow localhost
And finally deny all other access to this proxy
http_access allow all

保存

wq!

验证语法配置

sudo squid3 -k parse 

上一步做完会提示已经运行了squid,查看是否运行

sudo netstat -nltp | grep squid

tcp6 0 0 :::3128 :::* LISTEN 22379/squid3

如果squid运行后改配置,需要重启:

sudo service squid3 restart 

计算机A 测试代理功能:

vi ~/.bashrc

输入:
export http_proxy=http://192.168.55.250:3128

source ~/.bashrc

查看是否成功代理:

curl baidu.com

<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&amp;")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a>  <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号  <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

现在HTTP访问网页代理成功,但是apt-get 无法使用。

按照网上设置代理的方式
1、sudo vi /etc/apt/apt.conf
2、添加Acquire::http::proxy=”http://192.168.55.250:3128″ ;

sudo apt-get update
失败

或者
1、 sudo vi /etc/apt/apt.conf.d/05proxy
2、添加 Acquire::http::proxy=”http://192.168.55.250:3128″ ;

sudo apt-get update
失败

sudo apt-get -c /etc/apt/apt.conf update
还是失败

但是添加参数可以更新:

sudo apt-get update -o Acquire::http::proxy="http://192.168.55.250:3128" 

还没想到怎么解决这个问题。(语法错误问题)

==============

删掉第2步中proxy后面的“=”, 不需要添加参数 ,就可以直接apt-get update了:

  1. sudo vi /etc/apt/apt.conf
  2. 添加 Acquire::http::proxy “http://192.168.55.250:3128”;

参考:

https://help.ubuntu.com/community/AptGet/Howto#Setting_up_apt-get_to_use_a_http-proxy




发表评论

电子邮件地址不会被公开。 必填项已用*标注