centos 7搭建正向代理服务器,代理内网PC上网

Posted 小叶子i

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos 7搭建正向代理服务器,代理内网PC上网相关的知识,希望对你有一定的参考价值。

备注

ip地址


正向代理服务器---centos 7

网卡1:192.168.3.21

网卡2:192.168.145.129

普通PC             ---kubuntu

192.168.145.128


1.centos服务器虚拟机的配置

服务器有两张网卡,一张网卡桥接到我的傻瓜家用路由器上网的,dhcp分配地址为192.168.3.21

另一张网卡设置成桥接到vmnet7 ,这是个私网,默认是无法上网的


centos



2.PC 客户端的虚拟机设置

centos


3.vmnet 7 这个网段的地址是192.168.145.0:

centos


目前这个kubuntu客户端是无法上网的:

centos

centos

centos


4.配置centos 7为squid正向代理服务器,centos7有两张网卡,其中一张网卡是可以上网的,如图ping baidu是通的

centos

安装squid:

yum install -y squid

编辑squid配置文件

[root@localhost ~]# cp  /etc/squid/squid.conf  /etc/squid/squid.conf.bak   备份配置文件
[root@localhost ~]# vi /etc/squid/squid.conf 这是默认配置文件
#
# Recommended minimum configuration:
#

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT

#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128

# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256

# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid

#
# Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\\?) 0 0% 0
refresh_pattern . 0 20% 4320



这几处修改如下:

centos

注意有两个http_access allow localnet,

centos

默认端口修改成你想要的端口,我这里保持默认:

centos

重启一下进程,查看一下端口号是tcp 3128,已在监听

centos



接下来最重要的一步,关闭centos squid 服务器的防火墙:

centos

systemctl stop firewall
systemctl disable firewall

重启服务器。重启好后,运行squid

systemctl start squid
设置squid为自启动
systemctl enable squid


=================================

kubunt 客户端设置:

centos


输入百度测试:

centos


查看squid 日志

centos





以上是关于centos 7搭建正向代理服务器,代理内网PC上网的主要内容,如果未能解决你的问题,请参考以下文章

Nginx搭建HTTP正向代理服务器

CentOS 7 配置 Nginx 正向代理 httphttps 最详解

CentOS搭建squid正向代理

正向代理配置网关服务器

Squid(代理服务)

通过 Nginx 的正向代理审计监控内网用户的外网访问记录