1. 程式人生 > >squid 代理上網

squid 代理上網

客戶端 .com export mini 客戶端使用 style pro ash nal

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 生效

squid 代理上網