squid 代理上网

A服务器可以上网,B服务器不行,想让B服务器借助A上网。

一、A服务器配置

1.安装squid
# yum install squid.x86_64

2.配置squid

#
# 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         #定义 来源 10.0.0.0/8 这个网段的名称为  loaclnet
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                                   # 定义 443 端口的名称为 SSL_ports 
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         不是Safe_ports组中的端口 全部禁止访问
   http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports   不是SSL_ports 组中端口的 禁止连接
   http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost     允许这两个组 localhost manager 访问
   http_access allow localhost manager
   http_access deny manager                     不允许 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
#

在这里添加你的规则,允许哪些客户端使用代理 如下

acl localhost src 10.11.0.31

# 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条目
#
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

二、B服务器设置 

临时修改环境变量,重启失效

#export PROXY=http://A服务器ip:80/
export http_proxy="http://210.45.72.XX:808"

永久生效

#vi /etc/profile   增加以下内容

ftp_proxy=A的ip:3128
http_proxy=A的ip:3128
https_proxy=A的ip:3128
no_proxy=www.baidu.com   #百度不走代理
export ftp_proxy
export http_proxy
export https_proxy
export no_proxy

#source /etc/profile 生效

猜你喜欢

转载自www.cnblogs.com/centos2017/p/8969024.html