案例一(标准代理)
拓扑图:
squid服务器配置步骤:
1.[root@localhost Server]# rpm -ivh squid-2.6.STABLE21-3.el5.i386.rpm
2.vim /etc/resolv.conf //设置dns 文件内容增加:- nameserver 222.88.88.88
- nameserver 222.85.85.85
3.vim /etc/squid/squid.conf //编辑配置文件
文件内容修改:
- visible_hostname 192.168.2.100 //访问不通时,地址反馈给客户端
- http_port 192.168.2.10:3128
- http_access allow all //允许所有地址访问
4.vim /etc/squid/squid.conf //控制部分修改
文件内容修改:
acl badip src 192.168.2.10/32 http_access deny badip //拒绝来源地址访问acl webip dst 192.168.101.254/32
http_access deny webip //拒绝访问目的地址acl webip dst 192.168.101.254/32
acl mangerip src 192.168.145.10/32 http_access deny !mangerip webip //只允许145.10访问101.100acl badweb dstdomain .sina.com.cn
http_access deny badweb //拒绝访问域名为sina.com.cn网址acl worktime time MTWHF 08:00-18:00
http_access deny worktime(data 082918002012月日小时分年) //拒绝工作时间访问acl worktime time MTWHF 08:00-18:00
acl badcontent urlpath_regex -i \.jpg$ http_access deny worktime badcontent //拒绝工作时间访问不好的内容acl badurl url_regex -i sina
http-access deny badurl //拒绝访问网址内容带有sina的网站5.重新启动squid服务
service squid restart
客户端配置:
内网地址不需要设置网关和dns,只需要打开代理服务器
如图:
客户端测试:
客户端能够访问到internet.
案例二(透明代理)
拓扑图:
squid服务器配置步骤:
1.设置关于dns的nat转换
[root@localhost ~]# iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -p udp --dport 53 -o eth1 -j MASQUERADE
命令说明:
-A :追加规则-s :来源
--dport 53 :目标端口,DNS解析的协议端口是udp53 ,主服务器和备份服务器区域文件传输的协议端口是tcp53
-o :出口
-j :动作
MASQUERADE :地址伪装
2.设置端口重定向
[root@localhost ~]# iptables -t nat -A PREROUTING -p tcp --dport 80 -i eth0 -j REDIRECT --to-ports 3128 3.vim /etc/squid/squid.conf //设置透明代理文件内容修改:
http_port 192.168.2.10:3128 transparent 4.vim /etc/sysctl.conf //打开数据包转发能力文件内容修改:
net.ipv4.ip_forward = 1 启动转发功能: [root@localhost ~]#sysctl -p客户端配置:
dns指向和网关参数:
客户端测试:
C:\Documents and Settings\yang>pingPinging [119.75.217.56] with 32 bytes of
案例三(反向代理)
拓扑图:
squid服务器配置步骤:
1.vim /etc/squid/squid.conf
文件内容修改:
- http_access allow all
- http_port 192.168.101.11:80 vhost
- cache_peer 192.168.2.100 parent 80 0 originserver
linux的web服务器配置步骤:
1.[root@localhost Server]# rpm -ivh httpd-2.2.3-22.el5.i386.rpm 2.[root@localhost ~]# echo "hello" >/etc/www/html/index.html 3.[root@localhost Server]# rpm -ivh lynx-2.8.5-28.1.el5_2.1.i386.rpm 4.[root@localhost Server]# lynx 如图:网络中客户端配置:
外网客户端测试:
外网访问squid服务器的外端口地址见图: