使用squid限制elinks中对yahoo.com的访问

使用squid限制elinks中对yahoo.com的访问

我需要限制对 yahoo.com 及其所有子域的访问elinks。我必须用鱿鱼。

答案1

您可以使用

acl my_network src 192.168.0.0/16       # RFC1918 possible internal network
acl block_yahoo dstdomain .yahoo.com
http_access deny my_network block_yahoo
http_access allow my_network
http_access deny all

在“/etc/squid/squid.conf”中添加以上行后,只需运行以下命令即可重新加载鱿鱼配置

squid -k reconfigure

参考这个链接了解更多信息

答案2

使用 2 个以太网卡的 Squid 互联网过滤

这里我使用 Centos 6.5 作为我的 Squid 服务器

有2个以太网卡

  1. eth0 与 192.168.1.0/24 连接到 ISP 路由器 @ 192.168.1.1,分配 IP 192.168.1.15

  2. eth1,网络为 198.168.0.0/24 本地网络的 DHCP 服务器,或使用静态 IP,192.168.0.15

  3. iptable 具有基本规则,包括用于重定向的squid3 重定向规则。

  4. 两个以太网卡都需要在不同的网络中分配静态IP 地址。

在下创建阻止的文件列表

vim /etc/squid/blockedsites.squid

输入需要屏蔽的网站

.facebook.com
.skypeassets.com
.yahoo.com
.ui.skype.com
.twitter.com
.ndtv.com

创建阻止关键字列表

`vim /etc/squid/blockkeywords.squid`

porn
xxx

创建被阻止的 IP 列表

vim /etc/squid/blockip.squid

192.168.0.125

创建允许的 IP 列表

vim /etc/squid/allowip.squid

192.168.0.10

编辑配置文件并输入以下规则

 vim /etc/squid/squid.conf

更改各自所需的规则

#########################################################################
##### Restricting Web Access By Time #####
acl home_network src 192.168.0.0/24
acl business_hours time M T W H F A 08:45-22:00
acl RestrictedHost src 192.168.0.221
# Restricting Web Access By Time
http_access deny RestrictedHost 
http_access allow home_network business_hours
#########################################################################
acl blockregexurl url_regex -i .facebook.com gtalk.google.com talkx.l.google.com .facebook.com .mail.gmail.com .skype.com
http_access deny blockregexurl
#########################################################################
##### Block Using Mac Address #####
#acl badmac arp E3:40:G8:07:B7:54
#http_access deny badmac
#########################################################################
#### Block Using Port of Specific IP ####
#acl block_port port 1234
#acl no_block_port_ip src 192.168.1.36
#http_access deny block_port !no_block_port_ip
#http_access allow all
#########################################################################
#####Restricting Access to specific web sites#####
# ACL blocksites 
acl blocksites dstdomain "/etc/squid/blockedsites.squid"
# Deny access to blocksites ACL
http_access deny blocksites 
#########################################################################
# ACL blockkeywords
acl blockkeywords url_regex -i "/etc/squid/blockkeywords.squid"
# Deny access to blockkeywords ACL
http_access deny blockkeywords 
#########################################################################
##### Restricting Access to specific Ipaddress #####
# ACL blockip
acl blockip src "/etc/squid/blockip.squid"
# Deny access to blockip ACL
http_access deny blockip
#########################################################################
# ACL allowip
acl allowip src "/etc/squid/allowip.squid"
http_access allow allowip
#########################################################################
##### Restricting Download size #####
#Restrict download size
#reply_body_max_size 100 MB all
#########################################################################
##### facebook Rule ######
acl fb dstdomain .facebook.com
acl officetime time M T W H F A 9:30-18:00
# Facebook Restriction
http_reply_access deny fb officetime
http_access deny CONNECT fb officetime
#########################################################################
###### Hotmail MSN Block######
acl msn url_regex messenger.hotmail.com
# Yahoo! Messenger
acl ym dstdomain .messenger.yahoo.com .psq.yahoo.com
acl ym dstdomain .us.il.yimg.com .msg.yahoo.com .pager.yahoo.com
acl ym dstdomain .rareedge.com .ytunnelpro.com .chat.yahoo.com
acl ym dstdomain .voice.yahoo.com
acl ymregex url_regex yupdater.yim ymsgr myspaceim
acl ym dstdomain .skype.com .imvu.com
# Yahoo Messenger
http_access deny ym
http_access deny ymregex
#########################################################################
##### MSN Imagine messenger Restriction#####
acl messenger_site dstdomain .imagine-msn.com/messenger
##### Google Talk Restriction #####
acl messenger_site dstdomain .talk.google.com
##### Google talk ssl Restriction #####
acl messenger_site dstdomain talkx.l.google.com:443
acl gtalk dstdomain gtalk.google.com talkx.l.google.com
##### Ebuddy Messenger Restrcition #####
acl messenger_site dstdomain .ebuddy.com
http_access deny messenger_site
#########################################################################
#### Skype Messenger Block #####
# Skype
acl numeric_IPs dstdom_regex ^(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|(\[([0-9af]+)?:([0-9af:]+)?:([0-9af]+)?\])):443
acl Skype_UA browser ^skype
acl validUserAgent browser \S+
# Skype Restriction
http_access deny numeric_IPS
http_access deny Skype_UA
http_access deny !validUserAgent
###########################################################################
# Hostname
visible_hostname squidserver
###########################################################################
# Squid normally listens to port 3128
http_port 3128 intercept
###########################################################################

根据您的需要更改 ACL

然后将 iptables 添加到代理服务器创建一个 .sh 文件并保存并使用 sh 执行

vim iptables.sh

在创建的sh文件中输入脚本

#! /bin/sh
#just for the sake of turning the networks off and on... not sure if it would work turning them back on only at the end of script ?
ifconfig eth0 down;
ifconfig eth1 down;
ifconfig lo down;
ifconfig lo up;
ifconfig eth0 up;
ifconfig eth1 up;
ifup eth0;
ifup eth1;
#I seemed to have some issues with the routing table so i thought I throw in a check up :
route add 127.0.0.1 dev lo;
route add -net 127.0.0.0/8 dev lo;
route add -net 192.168.0.0/24 dev eth1;
route add 192.168.1.0 dev eth0;
route add default gw 192.168.1.1;
# turn fowarding off while configuring iptables :
sysctl net/ipv4/ip_forward=0
iptables -F
iptables -X
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD ACCEPT
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
#And on again once the policies are set
sysctl net/ipv4/ip_forward=1
#redirect port 80 on lan card and masquerade on wan card :
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
#accept all packets in lo and protect against spoofing :
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -i !lo -s 127.0.0.0/8 -j DROP
iptables -A FORWARD -i !lo -s 127.0.0.0/8 -j DROP
#accept only established input but all output on WAN card
iptables -A OUTPUT -o eth0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
#just forget the invalid packets :
iptables -A OUTPUT -o eth0 -m state --state INVALID -j DROP
iptables -A INPUT -i eth0 -m state --state INVALID -j DROP
#not sure whether to put this before or after spoofing protection ?
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A OUTPUT -o eth1 -j ACCEPT
#against spoofing on LAN card input :
iptables -A INPUT -i !eth1 -s 192.168.0.0/24 -j DROP
iptables -A FORWARD -i !eth1 -s 192.168.0.0/24 -j DROP

然后使用执行脚本

sh iptables.sh

查看 iptables 使用命令

iptables -L

使用保存 iptables

iptables-save > /root/iptables_save.ip

如果没有,请将 iptables 脚本添加到 rc 文件中,使其在每次重新启动后执行

vim /etc/rc.local

将其添加到 rc.local 文件中

sh /root/iptables.sh

然后将客户端计算机的 IP 更改为 192.168.0.1,将网关更改为代理 IP 地址

例如:

address 192.168.0.99
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.15

就是这样..

这不会阻止 https,用户仍然可以浏览 https 站点,如果您需要阻止 https,我们需要在每个浏览器中添加鱿鱼服务器代理设置

如果我们需要阻止 https 这个透明设置,我们需要设置一个 SSL Bump,它肯定会阻止每个 https 站点的

请查看我的网站帖子中有关上述内容的内容。使用 2 个以太网卡的 Squid 互联网过滤

相关内容