当前位置:   article > 正文

linux内网机器访问外网代理设置_redhat enterprise 设置代理上网

redhat enterprise 设置代理上网

摘要: 公司一般出于安全考虑, 在同一局域网中只有一台机器可以访问外网,运维进行了整体的限制, 但是在后面的工作中,需要在机器上安装一些软件,及命令,所以其他的机器需要访问外网来简化工作, 但又不能打乱原有运维的设置,所以需要在能访问外网的机器上做个代理。

第一步、二步都是在能访问外网的机器上操作, 第三步是在不能访问外网机器上操作。
1、检查机器
     在操作中发现访问外网的机器本身不能使用yum 安装软件,故需要配置yum安装源。如果可以的,这步可忽略。

  1. [root@localhost test]# lsb_release -a
  2. LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
  3. Distributor ID: RedHatEnterpriseServer
  4. Description: Red Hat Enterprise Linux Server release 5.7 (Tikanga)
  5. Release: 5.7
  6. Codename: Tikanga
  7. [root@localhost test]# cd /etc/yum.repos.d/
  8. [root@localhost test]# wget http://mirrors.163.com/.help/CentOS5-Base-163.repo
 中间 wget 所获取的文件,需要将$releasever 修改为 5

  1. # CentOS-Base.repo
  2. #
  3. # The mirror system uses the connecting IP address of the client and the
  4. # update status of each mirror to pick mirrors that are updated to and
  5. # geographically close to the client. You should use this for CentOS updates
  6. # unless you are manually picking other mirrors.
  7. #
  8. # If the mirrorlist= does not work for you, as a fall back you can try the
  9. # remarked out baseurl= line instead.
  10. #
  11. #
  12. [base]
  13. name=CentOS-5 - Base - 163.com
  14. baseurl=http://mirrors.163.com/centos/5/os/$basearch/
  15. #mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=os
  16. gpgcheck=1
  17. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
  18. #released updates
  19. [updates]
  20. name=CentOS-5 - Updates - 163.com
  21. baseurl=http://mirrors.163.com/centos/5/updates/$basearch/
  22. #mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=updates
  23. gpgcheck=1
  24. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
  25. #packages used/produced in the build but not released
  26. [addons]
  27. name=CentOS-5 - Addons - 163.com
  28. baseurl=http://mirrors.163.com/centos/5/addons/$basearch/
  29. #mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=addons
  30. gpgcheck=1
  31. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
  32. #additional packages that may be useful
  33. [extras]
  34. name=CentOS-5 - Extras - 163.com
  35. baseurl=http://mirrors.163.com/centos/5/extras/$basearch/
  36. #mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=extras
  37. gpgcheck=1
  38. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
  39. #additional packages that extend functionality of existing packages
  40. [centosplus]
  41. name=CentOS-5 - Plus - 163.com
  42. baseurl=http://mirrors.163.com/centos/5/centosplus/$basearch/
  43. #mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=centosplus
  44. gpgcheck=1
  45. enabled=0
  46. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
  47. #contrib - packages by Centos Users
  48. [contrib]
  49. name=CentOS-5 - Contrib - 163.com
  50. baseurl=http://mirrors.163.com/centos/5/contrib/$basearch/
  51. #mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=contrib
  52. gpgcheck=1
  53. enabled=0
  54. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
  yum clean all  清除原有缓存
  yum list           获取yum列表
  如果出现列表数据如下这种表示设置成功

  1. sqlite-devel.i386 3.3.6-7 base
  2. sqlite-devel.x86_64 3.3.6-7 base
  3. squashfs-tools.x86_64 3.0-4 base
  4. squirrelmail.noarch 1.4.8-21.el5.centos base
  5. srptools.x86_64 0.0.4-10.el5 base
  6. sssd.x86_64 1.5.1-70.el5 base
  7. sssd-client.i386 1.5.1-70.el5 base
  8. sssd-client.x86_64 1.5.1-70.el5 base
  9. sssd-tools.x86_64 1.5.1-70.el5 base

2、安装squid
    squid介绍及其简单配置
    前面准备好yum命令, 可以直接在线安装

yum install squid
   安装完成后, cd  /etc/squid/ 目下, 修改squid.conf 文件中的内容,修改之前, 可以先备份该文件:
cp squid.conf squid.conf_bak
  然后找到 文件中的 http_access deny all   将其修改为 http_access allow all  表示所有用户都可以访问这个代理,
  还有找到  http_port 3128  修改为   http_port 192.168.3.171:3128  这里的IP及端口是 squid的代理IP及端口,
  该IP是能访问外网机器的IP地址,如果是本机,则可以不用修改该地址, 下面启动squid 代理

  1. [root@localhost squid]# squid -k parse
  2. [root@localhost squid]#
  3. [root@localhost squid]#
  4. [root@localhost squid]# squid -z
  5. 2014/07/22 14:43:01| Creating Swap Directories
  6. [root@localhost squid]#
  7. [root@localhost squid]#
  8. [root@localhost squid]# service squid start
  9. Starting squid: [ OK ]
  10. [root@localhost squid]#
  11. [root@localhost squid]#
  12. [root@localhost squid]#
  13. [root@localhost squid]# netstat -nltp
  14. Active Internet connections (only servers)
  15. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  16. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 4341/portmap
  17. tcp 0 0 0.0.0.0:3128 0.0.0.0:* LISTEN 22862/(squid)
  18. tcp 0 0 0.0.0.0:792 0.0.0.0:* LISTEN 4426/rpc.statd

3、配置不能访问外网的机器代理
   在其他有需要访问外网的内网机器上设置其访问外部网络的代理机器
export http_proxy=http://192.168.3.171:3128

   export的效力仅及于该此登陆操作,非全局,详细内容可参考:linux环境变量 export命令详解

   这样就可以让不能访问外部网络的内网机器通过可以访问外网的机器做为代理访问到外部网络,来方便安装一些软件,命令等操作。


4、测试

     在配置的内网机器上执行:curl www.baidu.com,出现以下内容即访问网络成功:

  1. [cosw@platdevsxyd01 ~]$ curl www.baidu.com
  2. <!DOCTYPE html>
  3. <!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge>
  4. <meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css>
  5. <title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper>
  6. <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>
  7. </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1>
  8. <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1>
  9. <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr">
  10. <input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr">
  11. <input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1>
  12. <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>
  13. <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a>...</html>



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/168761
推荐阅读
相关标签
  

闽ICP备14008679号