合 Centos7内网服务器配置squid上外网
引言
有A和B 2台linux机器,A和B可以互通,但是A可以上百度,B不能上百度,那么如何才能让B也上百度呢???
环境介绍
环境:
服务器A可以上外网:内网192.168.6.22;外网172.17.254.100
服务器B只能上内网:内网192.168.6.23
需求:
如何配置,才可以让服务器B也可以上外网???
配置
服务器A
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | yum install -y squid sudo apt-get install squid cp /etc/squid/squid.conf /etc/squid/squid.conf_bak vi /etc/squid/squid.conf http_port 3128 acl localnet src all http_access allow localnet http_access allow all -- 或直接加入如下内容 cat >> /etc/squid/squid.conf <<"EOF" http_port 3128 acl lhrnet src all http_access allow lhrnet http_access allow all EOF # 检查语法是否错误 squid -k parse # 初始化缓存空间 squid -z # 启动 squid systemctl restart squid systemctl status squid netstat -an | grep 3128 |
服务器B
如下的意思该服务器要通过192.168.6.22服务器的端口3128的代理来访问外网
1 2 3 4 5 6 7 8 | alias proxy='export http_proxy=http://192.168.6.22:3128;export https_proxy=http://192.168.6.22:3128' alias unproxy='unset http_proxy https_proxy' proxy -- 或者 alias proxy='export all_proxy=http://192.168.6.22:3128' alias unproxy='unset all_proxy' proxy |
测试
使用wget baidu.com
或curl www.baidu.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | [root@sdw2 ~]# curl -i www.baidu.com HTTP/1.1 200 OK Accept-Ranges: bytes Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform Content-Length: 2381 Content-Type: text/html Date: Fri, 10 Mar 2023 01:38:14 GMT ETag: "588604c8-94d" Last-Modified: Mon, 23 Jan 2017 13:27:36 GMT Pragma: no-cache Server: bfe/1.0.8.18 Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/ X-Cache: MISS from mdw X-Cache-Lookup: MISS from mdw:3128 Via: 1.1 mdw (squid/3.5.20) Connection: keep-alive <!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&tpl=mn&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&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "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> [root@sdw2 ~]# -- 其它测试 wget http://www.slac.stanford.edu/~abh/bbcp/bin/amd64_rhel60/bbcp -O /usr/local/bin/bbcp && chmod +x /usr/local/bin/bbcp curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo curl -x 192.168.129.221:8888 www.baidu.com yum reinstall -y openssh |