背景
首先有两台服务器10.255.158.235和10.255.159.184,其中184无外网,235有外网。现在184服务器是无法访问外网的,需要使用代理的方法让184通过有外网的235访问外网。
该操作一共可以分为两个部分:一、在服务器235上安装代理程序 二、配置184代理。
在235上安装代理服务器(服务端)
使用squid
#安装squid,这里采用yum的安装方式
[root@cdh01 ~] yum install -y squid
#cd到配置文件目录下
[root@cdh01 ~] cd /etc/squid/
#备份原始配置文件
[root@cdh01 ~] cp squid.conf squid.conf_bak
#修改配置文件
[root@cdh01 squid]# vi squid.conf
squid.conf配置文件修改内容如下:
#将http_access deny all注释修改为http_access allow all
#http_access deny all
http_access allow all
# 修改端口为代理的端口
http_port 3128
启动squid:
#检查语法是否错误
[root@cdh01 squid] squid -k parse
#初始化缓存空间
[root@cdh01 squid] squid -z
2018/12/05 13:58:56 kid1| Set Current Directory to /var/spool/squid
2018/12/05 13:58:56 kid1| Creating missing swap directories
2018/12/13:58:56 kid1| No cache_dir stores are configured.
#启动squid
[root@cdh01 squid] service squid start
Redirecting to /bin/systemctl start squid.service
#检查端口是否开启成功
[root@cdh01 squid]# netstat -an | grep 3128
tcp6 0 0 :::3128 :::* LISTEN
测试,使用wget baidu.com或curl www.baidu.com 测试内网服务器能否访问外网
[root@cdh01 ~] wget baidu.com
--2018-12-05 14:07:48-- http://baidu.com/
Connecting to 172.19.58.201:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 81 [text/html]
Saving to: ‘index.html.1’
100%[=================================================================================================================================>] 81 --.-K/s in 0s
2018-12-05 14:07:48 (20.7 MB/s) - ‘index.html.1’ saved [81/81]
配置184代理(客户端)
1.临时使用,直接运行以下命令
export http_proxy=http://10.255.158.235:3128
export https_proxy=http://10.255.158.235:3128
export no_proxy="127.0.0.1, localhost, 10.255.158.235"
2.永久生效,在/etc/profile中添加以下内容:
export http_proxy=http://10.255.158.235:3128
export https_proxy=http://10.255.158.235:3128
export no_proxy="127.0.0.1, localhost, 10.255.158.235"
no_proxy不支持模糊匹配