squid代理配置

背景

首先有两台服务器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不支持模糊匹配

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值