小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

iptables NAT squid實現(xiàn)透明代理

 CedarRapids 2013-06-11

iptables 設(shè)置(NAT和ip限制,80轉(zhuǎn)發(fā),需要有ip文件ip2.txt):

intra="192.168.0.0/24"
myip
="219.217.235.73"
myDNS
="202.118.224.101:53"

echo 
1 > /proc/sys/net/ipv4/ip_forward

#清空規(guī)則
/sbin/iptables -
/sbin/iptables -t nat -F

/sbin/iptables -P FORWARD DROP
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT DROP

/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT

#允許DNS
iptables -A INPUT -i eth0 -p udp --sport 53 -j ACCEPT    #允許外面53端口的UDP數(shù)據(jù)進來
iptables -A PREROUTING -t nat -p udp -s $intra -192.168.0.1 --dport 53 -j DNAT --to-destination $myDNS    #允許局域網(wǎng)設(shè)置DNS為192.168.0.1
iptables -A PREROUTING -t nat -p udp -s $intra -d $myip --dport 53 -j DNAT --to-destination $myDNS    #允許局域網(wǎng)設(shè)置DNS為$myip
#
iptables -A FORWARD -p udp -d 202.118.224.101 --dport ! 53 -j DROP

#iptables -A OUTPUT  -d $intra -j ACCEPT    
#
允許局域網(wǎng)發(fā)出的所有消息,如果使用地址過濾,就要修改這里,或者修改squid的規(guī)則。。
#
以下為過濾收費ip
fip=$(awk 'NF>2 {print $1 "/" $3}' ip2.txt)
for x in $fip
    do
        
#允許連接免費IP段
    /sbin/iptables -A FORWARD -d $x -j ACCEPT        #允許內(nèi)網(wǎng)訪問外面
    /sbin/iptables -A OUTPUT -d $x  -j ACCEPT    #允許本機訪問外面
    #iptables -A OUTPUT  -d $x -j ACCEPT        #不知道為什么這么也不行,局域網(wǎng)還是無法訪問外網(wǎng)
    echo $x
    done

#允許外網(wǎng)訪問里面
/sbin/iptables -A FORWARD -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
#允許外網(wǎng)訪問本機
/sbin/iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

#允許內(nèi)網(wǎng)訪問本機
#
/sbin/iptables -A INPUT -i eth1 -s $intra -m state --state ESTABLISHED,RELATED -j ACCEPT
#
/sbin/iptables -A INPUT -i eth1 -s $intra -p tcp --dport 80 -j ACCEPT
/sbin/iptables -A INPUT -i eth1 -s $intra -j ACCEPT
#允許本機訪問內(nèi)網(wǎng)
/sbin/iptables -A OUTPUT -o eth1 -d  $intra -j ACCEPT


#iptables -A INPUT -i eth0 -p udp  -j ACCEPT    #允許外面的UDP數(shù)據(jù)進來

#允許本機上網(wǎng)。。。如果專作服務(wù)器就可以不要
#
/sbin/iptables -A INPUT -d $myip  -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT #允許外面訪問
#
/sbin/iptables -A INPUT -d $myip  -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT #允許里面訪問
#
/sbin/iptables -A OUTPUT -d $intra  -i eth0  -j ACCEPT #允許訪問內(nèi)網(wǎng)

#實現(xiàn)NAT多電腦上網(wǎng)
/sbin/iptables -t nat -A POSTROUTING -o eth0 -192.168.0.0/24 -j SNAT --to 219.217.235.73

# 將 對于 80、443 端口的訪問 重定向到 3128 端口 </P><P>
iptables -t nat -A PREROUTING -i eth1 -p tcp -192.168.0.0/24 --dport 80 -j DNAT --to  192.168.0.1:3128 
iptables 
-t nat -A PREROUTING -i eth1 -p tcp -192.168.0.0/24 --dport 443 -j DNAT --to 192.168.0.1:3128 




squid設(shè)置:
/etc/squid/squid.conf文件:(需要有ip列表文件/etc/squid/freeip_for_squid.txt,一行一個ip/mask

httpd_accel_host virtual
httpd_accel_port 
80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
cache_effective_user squid
cache_effective_group squid
visible_hostname hit405

acl all src 
0.0.0.0/0.0.0.0
#acl auth proxy_auth REQUIRED
#
acl our src 192.168.0.0/255.255.255.0
#
http_access allow our
#
http_access allow  auth !our #這句話那里不對??

#第一種配置,訪問國外時顯示錯誤
#
#################################################################
acl freeip1 dst "/etc/squid/freeip_for_squid.txt"
http_access allow freeip1
http_access deny all
####################################################################################################################################

#第二種配置,訪問國外時使用二級代理(有些問題!!)
#
###################################################################################################################################
#
acl freeip1 dst "/etc/squid/freeip_for_squid.txt"
#
cache_peer 219.232.9.181 parent 80 0 no-query no-digest no-netdb-exchange
#
cache_peer_access  219.232.9.181 allow !freeip1
#
cache_peer_access  219.232.9.181 deny freeip1
#
#
always_direct deny !freeip1
#
always_direct allow freeip1
#
#
never_direct allow !freeip1
#
never_direct deny  freeip1
#
http_access allow all
#
###################################################################################################################################

cache_dir ufs 
/var/spool/squid 100 16 256

執(zhí)行以下命令啟動squid

mkdir  /var/spool/squid 

useradd squid
chown squid 
/var/spool/squid 
chown squid 
/var/log/squid/access.log

#cp ERR_ACCESS_DENIED /usr/share/squid/errors/English
#
rm -f ./access.log
#
ln /var/log/squid/access.log ./
echo "..restart 
squid -k reconfigure
squid 
-z
squid

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多