linux內網機器訪問外網代理設置

第一步、二步都是在能訪問外網的機器上操做, 第三步是在不能訪問外網機器上操做。sql

一、檢查機器

     在操做中發現訪問外網的機器自己不能使用yum 安裝軟件,故須要配置yum安裝源。若是能夠的,這步可忽略。shell

[root@localhost test]# lsb_release -a
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
Distributor ID: RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 5.7 (Tikanga)
Release:        5.7
Codename:       Tikanga
[root@localhost test]# cd /etc/yum.repos.d/
[root@localhost test]# wget http://mirrors.163.com/.help/CentOS5-Base-163.repo

    中間 wget 所獲取的文件,須要將$releasever 修改成 5centos

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-5 - Base - 163.com
baseurl=http://mirrors.163.com/centos/5/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#released updates 
[updates]
name=CentOS-5 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/5/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-5 - Addons - 163.com
baseurl=http://mirrors.163.com/centos/5/addons/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=addons
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-5 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/5/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-5 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/5/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-5 - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/5/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

  yum clean all  清除原有緩存緩存

  yum list           獲取yum列表網絡

  若是出現列表數據以下這種表示設置成功less

sqlite-devel.i386                                                                            3.3.6-7                                                                   base     
sqlite-devel.x86_64                                                                          3.3.6-7                                                                   base     
squashfs-tools.x86_64                                                                        3.0-4                                                                     base     
squirrelmail.noarch                                                                          1.4.8-21.el5.centos                                                       base     
srptools.x86_64                                                                              0.0.4-10.el5                                                              base     
sssd.x86_64                                                                                  1.5.1-70.el5                                                              base     
sssd-client.i386                                                                             1.5.1-70.el5                                                              base     
sssd-client.x86_64                                                                           1.5.1-70.el5                                                              base     
sssd-tools.x86_64                                                                            1.5.1-70.el5                                                              base


二、安裝squid

    前面準備好yum命令, 能夠直接在線安裝tcp

yum install squid

   安裝完成後, cd  /etc/squid/ 目下, 修改squid.conf 文件中的內容,修改以前, 能夠先備份該文件:ui

cp squid.conf squid.conf_bak

  而後找到 文件中的 http_access deny all   將其修改成 http_access allow all  表示全部用戶均可以訪問這個代理,this

  還有找到  http_port 3128  修改成  http_port 192.168.3.171:3128  這裏的IP及端口是 squid的代理IP及端口,url

  該IP是能訪問外網機器的IP地址,若是是本機,則能夠不用修改該地址, 下面啓動squid 代理

[root@localhost squid]# squid -k parse
[root@localhost squid]# 
[root@localhost squid]# 
[root@localhost squid]# squid -z
2014/07/22 14:43:01| Creating Swap Directories
[root@localhost squid]# 
[root@localhost squid]# 
[root@localhost squid]# service squid start
Starting squid:                                            [  OK  ]
[root@localhost squid]# 
[root@localhost squid]# 
[root@localhost squid]# 
[root@localhost squid]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      4341/portmap        
tcp        0      0 0.0.0.0:3128                0.0.0.0:*                   LISTEN      22862/(squid)       
tcp        0      0 0.0.0.0:792                 0.0.0.0:*                   LISTEN      4426/rpc.statd


三、配置不能訪問外網的機器代理

   在其餘有須要訪問外網機器上設置其訪問外部網絡的代理機器

export http_proxy=http://192.168.3.171:3128

  這樣就可讓不能訪問外部網絡的機器經過能夠訪問外網的機器作爲代理訪問到外部網絡,來方便安裝一些軟件,

  命令等操做。

相關文章
相關標籤/搜索