Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9268245
  • 博文数量: 1669
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12594
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1669)

文章存档

2023年(4)

2022年(1)

2021年(10)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: 系统运维

2019-06-20 14:38:34

RedHat 5.4 Squid配置透明代理服务器 2013-01-14 11:04:51| 分类: mem_squid_porxy | 标签: |字号大中小 订阅 一、基本配置 Squid代理服务器配置两个网卡 WAN:eth0:10.10.10.200 需要配置网关、DNS,允许上网 LAN:eth1:172.168.1.254 不用配置网关、DNS Clinet:172.16.1.2/24 需要配置网关、DNS squid(代理) 端口:3128 RedHat 5.4 Squid配置透明代理服务器 - zhuzhu - 五事九思 (大连Linux主机维护) 系 统 主机名 服务器IP 客户端IP RedHat 5.4 proxy Eth0:10.10.10.200 172.16.1.0 Eth1:172.16.1.254 需求: 1. 禁止单IP上网 2. 禁止网段10-50上网 3. 禁止所有网段访问IP:172.16.1.200(MySQL) 4. 禁止访问:网站 5. 禁止访问包含关键字163网址 6. 禁止下载*.mp3$ *.exe$ *.zip$ *.rar$ 类型的文件 7. 禁止网段10-50客户端在周一到周五的09:00-18:00上班时间上网 8. 禁止端口号上网 9. 限制用户并发连接数为:由转发功能 [root@proxy ~]# vim /etc/sysctl.conf 7 net.ipv4.ip_forward = 0 #0为关闭 修改为 7 net.ipv4.ip_forward = 1 #1为开启路由 :wq 保存 [root@localhost ~]# sysctl -p #命令查看 net.ipv4.ip_forward = 1 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 4294967295 kernel.shmall = 268435456 4、配置Iptables防火墙 [root@proxy ~]# setup #进入图形界面,打开防火墙为:Enabled [root@proxy ~]# service iptables start #开启 [root@proxy ~]# chkconfig iptables on #开机启动 [root@proxy ~]# iptables -L #列出规则 [root@proxy ~]# iptables -F #清空规则 [root@proxy ~]# iptables -t nat -L #用详细方式列出 nat 表所有链的所有规则 [root@proxy ~]# iptables -t filter -L #用详细方式列出 filter 表所有链的所有规则 编辑iptables配置文件,开启防火墙3128端口(后面配置squid的端口号3128) [root@proxy ~]# vim /etc/sysconfig/iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3128 -j ACCEPT [root@proxy ~]# service iptables restart #重启 开启外网eth0,DNS的NAT网络地址转换功能 [root@proxy ~]# iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -p udp --dport 53 -o eth0 -j MASQUERADE [root@proxy ~]# iptables -t nat –Lvn #用详细方式列出 nat 表所有链的所有规则,只显示IP地址和端口号 设置端口转发功能,把内网eth1的80端口转发到外网eth0的3128端口 [root@proxy ~]# iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-ports 3128 [root@proxy ~]# iptables -t nat -Lvn Chain PREROUTING (policy ACCEPT 104 packets, 12110 bytes) pkts bytes target prot opt in out source destination 2 96 REDIRECT tcp -- eth1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 redir ports 3128 Chain POSTROUTING (policy ACCEPT 10 packets, 752 bytes) pkts bytes target prot opt in out source destination 5 307 MASQUERADE udp -- * eth0 172.16.1.0/24 0.0.0.0/0 udp dpt:53 Chain OUTPUT (policy ACCEPT 1 packets, 284 bytes) pkts bytes target prot opt in out source destination [root@proxy ~]# service iptables save #保存规则 Saving firewall rules to /etc/sysconfig/iptables: [ OK ] 5、客户端IE浏览访问: RedHat 5.4 Squid配置透明代理服务器 - zhuzhu - 五事九思 (大连Linux主机维护) 6、编辑squid配置文件 [root@proxy ~]# vim /etc/squid/squid.conf 924 http_port 3128 修改为 924 http_port 3128 transparent #监听3128端口接收到的http请求 1576 # cache_mem 8 MB 修改为 1576 cache_mem 256 MB #高速缓存 1783 # cache_dir ufs /var/spool/squid 100 16 256 修改为 1783 cache_dir ufs /var/spool/squid 10240 16 256 #设置硬盘缓存大小为10G,目录为/var/spool/squid,一级子目录16个,二级子目录256个 1945 access_log /var/log/squid/access.log squid #设置访问日志 1961 cache_log /var/log/squid/cache.log #设置缓存日志 1971 cache_store_log /var/log/squid/store.log #设置网页缓存日志 2941 # cache_mgr root 修改为 2941 cache_mgr yanghw85@163.com #设置管理员邮箱地址 :wq 保存 [root@proxy ~]# service squid restart Stopping squid: [ OK ] Starting squid: . [ OK ] 7、测试正常上网: RedHat 5.4 Squid配置透明代理服务器 - zhuzhu - 五事九思 (大连Linux主机维护) 8、查看日志: [root@proxy ~]# tail -f /var/log/squid/access.log 9、手动添加访问控制策略(注意:策略要合理的配置应用,避免冲突) [root@proxy ~]# vim /etc/squid/squid.conf 配置策略在590行开始 在下面添加以下策略内容: #####################禁止单IP上网############################### acl badip src 172.16.1.2/32 http_access deny badip #####################禁止网段10-50上网########################## acl badip src 172.16.1.10-172.16.1.50/32 http_access deny badip #####################禁止所有网段访问IP:172.16.1.200(MySQL)####### acl MySQL dst 172.16.2.100 http_access deny MySQL #####################禁止访问:网站################ acl web dstdomain -i http_access deny web #####################禁止访问包含关键字163网址################## acl web163 url_regex -i 163 http_access deny web163 ###########禁止下载*.mp3$ *.exe$ *.zip$ *.rar$ *.doc$类型的文件######## acl webxiazai urlpath_regex -i \.mp3$ \.exe$ \.zip$ \.rar$ \.doc$ http_access deny webxiazai #####禁止网段10-50客户端在周一到周五的09:00-18:00上班时间上网###### acl badip src 172.16.1.10-172.16.1.50/32 acl worktime time MTWHF 09:00-18:00 http_access deny badip worktime ########################限制443端口上网 ############################ acl http port 443 http_access deny http ########################限制用户并发连接数为:5 ###################### acl client15 src 172.16.1.15 acl conn5 maxconn 5 http_access deny client15 conn5 :wq [root@proxy ~]# service squid restart #重启 Stopping squid: [ OK ] Starting squid: . [ OK ] 配置完成!现在内部网段172.16.1.0/24内客户机可以通过代理服务器172.16.1.254访问外网。

阅读(1727) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~