[root@linux-virsh-106 network-scripts]# cd /etc/squid/
[root@linux-virsh-106 squid]# ls
cachemgr.conf errors icons mib.txt mime.conf mime.conf.default msntauth.conf msntauth.conf.default squid.conf squid.conf.bak20140120 squid.conf.bak2014012002 squid.conf.default
提取出配置文件中有用的信息
[root@linux-virsh-106 squid]# grep -v "^#" squid.conf.bak20140120 |grep -v "^$" >> squid.conf
启动squid
[root@linux-virsh-106 squid]# service squid start
启动 squid:. [确定]
[root@linux-virsh-106 squid]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:1004 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3128 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN
tcp 0 0 :::22 :::* LISTEN
基本工作已经完成,现在根据自己的需求配置squid
[root@linux-virsh-106 squid]# cat squid.conf
acl lan src 192.168.10.0/24 #这个是内网ip要连接的地址
acl all src 0.0.0.0/0.0.0.0
#自己添加的可以允许访问的url
acl url1 url_regex -i qq.com
acl url2 url_regex -i pengyou.com
acl url3 url_regex -i baidu.com
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
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
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access allow url1
http_access allow url2
http_access allow url3
http_access deny all
icp_access allow all
#在端口的后面要加上transparent,否则无法转发
http_port 3128 transparent
#visible_hostname 也是要自己添加上去
visible_hostname 192.168.10.26
hierarchy_stoplist cgi-bin ?
access_log /var/log/squid/access.log squid
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
coredump_dir /var/spool/squid
根据自己需求在iptables添加端口信息
[root@linux-virsh-106 squid]# iptables -t nat -A PREROUTING -p tcp --dport 8003 -j REDIRECT --to-port 3128