背景

首先有两台服务器AB,其中A(192.168.1.100)有外网,B(192.168.1.101)没有外网,使用A开启代理服务器,让B连接A使得B能访问外网

配置 A(有外网)服务器

1.安装squid代理server

yum install -y squid

2.备份配置文件,以防万一

#进入配置文件目录
cd  /etc/squid/
#备份原始配置文件
cp squid.conf squid.conf_bak

3.编辑配文件

#打开配置文件
vi squid.conf

定位到http_access deny all(输入/http_access deny all)然后将

http_access deny all

修改为(deny改allow)

http_access allow all

然后定位到http_port(输入/http_port)
修改端口,这个端口是代理端口 (我这边设置为8888)

http_port 8888

4.检查并启动代理服务器

检查语法是否正确(一般没问题 可跳过)

squid -k parse

初始化缓存空间

squid -z

启动代理服务器

service squid start

检查端口是否启动(8888是上面设置的端口)

netstat -an | grep 8888

配置 B(没有外网)服务器

1.配置代理地址

编辑profile

vi /etc/profile

在里面加入需要连接的代理配置
设置代理地址为服务器地址(http://A服务器地址:上面设的端口8888)

export http_proxy=http://192.168.1.100:8888

在里面加入不代理的地址
一般都为本机地址

export no_proxy="127.0.0.1, localhost, 192.168.1.101"

保存退出

重新载入配置

source /etc/profile

测试配置是否生效

echo $http_proxy

#显示以下说明OK
http://192.168.1.100:8888

2.测试外网

是否能连上百度


curl www.baidu.com