分享

squid代理局域网服务器访问公网【转】

 印度阿三17 2021-02-20

首先有两台服务器A、B,其中A为局域网,B有公网。A配置(内网IP172.19.58.202\系统CentOS7.4),B配置(内网IP172.19.58.201\系统CentOS7.4)。现在A服务器是无法访问公网的,需要使用代理的方法让A通过有公网的B访问公网。

该操作一共可以分为两个部分:一、配置A代理 二、在服务器B上安装代理程序。

一、配置A代理 

#cd到/etc/profile.d/目录下
#新建proxy.sh,命名无所谓
[root@ali2 /] cd /etc/profile.d/
[root@ali2 profile.d] vi proxy.sh

proxy.sh里面内容:

#IP为要连接的代理服务器B,端口是要代理的端口,如下的意思该服务器要通过172.19.58.201服务器的端口10991的代理来访问公网
export http_proxy=http://172.19.58.201:10991
#如果要设置https代理,应该添加如下配置,暂未尝试过
#export https_proxy=http://172.19.58.201:10991
#设置不代理的IP或者网址,如下配置,这些请求不会被代理,不支持模糊匹配
export no_proxy="127.0.0.1, localhost, 172.19.58.202,172.19.58.201"

 

然后source /etc/profile,再使用指令echo $http_proxy,如果能打印出相关代理信息说明操作成功。

[root@ali2 profile.d] echo $http_proxy 
http://172.19.58.201:10991

 

二、在服务器B上安装代理程序

#安装squid,这里采用yum的安装方式 
[root@ali1 ~] yum install -y squid 
#cd到配置文件目录下 
[root@ali1 ~] cd /etc/squid/ 
#备份原始配置文件
[root@ali1 ~] cp squid.conf squid.conf_bak 
#修改配置文件 
[root@ali1 squid]# vi squid.conf

 

squid.conf配置文件修改内容如下

 

#将http_access deny all注释修改为http_access allow all
#http_access deny all
http_access allow all 
# 修改端口为代理的端口 
http_port 10991

启动

#检查语法是否错误
[root@ali1 squid] squid -k parse
 
#初始化缓存空间
[root@ali1 squid] squid -z
[root@ali1 squid] 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@ali1 squid] service squid start
Redirecting to /bin/systemctl start squid.service
 
#检查端口是否开启成功
[root@ali1 squid]# netstat -an | grep 10991 
tcp6 0 0 :::10991 :::* LISTEN

 

测试,使用wget baidu.com或curl www.baidu.com 测试内网服务器能否访问外网

[root@ali2 ~] wget baidu.com
--2018-12-05 14:07:48-- http://baidu.com/ 
Connecting to 172.19.58.201:10991... 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]

 

问题2:无法进行域名解析

此时发现无法使用域名只能使用ip来访问

原因:dns未配置,在squid的配置文件中添加8.8.8.8和8.8.4.4

[root@liumiaocn ~]# grep nameserver /etc/squid/squid.conf
dns_nameservers 8.8.8.8 8.8.4.4
[root@liumiaocn ~]# 
[root@liumiaocn ~]# systemctl restart squid
[root@liumiaocn ~]#

 

转自

(3条消息) 局域网服务器如何设置代理访问公网_y1006597541的博客-CSDN博客
https://blog.csdn.net/y1006597541/article/details/100152435 

(3条消息) squid:http和https的代理服务器设置指南_知行合一 止于至善-CSDN博客_squid
https://blog.csdn.net/liumiaocn/article/details/80586879

用squid做http/https正向代理 - 又是火星人 - 博客园
https://www.cnblogs.com/echo1937/p/6728461.html

 

来源:https://www./content-4-864051.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多