备注

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 7搭建正向代理服务器,代理内网PC上网_squid



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

centos 7搭建正向代理服务器,代理内网PC上网_防火墙关闭_02


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

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


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

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

centos 7搭建正向代理服务器,代理内网PC上网_防火墙关闭_05

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


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

centos 7搭建正向代理服务器,代理内网PC上网_代理拒绝连接_07

安装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 7搭建正向代理服务器,代理内网PC上网_centos7_08

注意有两个http_access allow localnet,

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

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

centos 7搭建正向代理服务器,代理内网PC上网_防火墙关闭_10

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

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



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

centos 7搭建正向代理服务器,代理内网PC上网_代理拒绝连接_12

systemctl stop firewall
systemctl disable firewall

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

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


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

kubunt 客户端设置:

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


输入百度测试:

centos 7搭建正向代理服务器,代理内网PC上网_代理拒绝连接_14


查看squid 日志

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