- 論壇徽章:
- 0
|
由于項(xiàng)目實(shí)驗(yàn)需求,需要只能針對國內(nèi)主機(jī)提供服務(wù),這就需要有一份國內(nèi)IP地址的列表。
首先需要得到國內(nèi)的IP列表,我們通過apnic查到國內(nèi)的IP列表。
http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst
可以寫一個(gè)簡單的腳本:
# wget -q -O - http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst | grep cn | awk '{print $5}' > cn.txt
這樣cn.txt中就是所有的國內(nèi)網(wǎng)段。
然后寫了一個(gè)fw.sh的腳本,里面INPUT的默認(rèn)處理策略是DROP,然后允許局域網(wǎng)地址和部分公網(wǎng)地址的訪問,允許遠(yuǎn)程管理網(wǎng)段的22端口訪問,然后就是ACCEPT國內(nèi)的IP列表。
#!/bin/sh
IPT=/sbin/iptables
LOCAL_RANGE=192.168.1.0/24
INET_RANGE=1.2.3.0/24
REMOTE_ADMIN_RANGE=4.3.2.0/24
#Clean The Old Tables
for TABLE in filter nat mangle ; do
$IPT -t $TABLE -F
$IPT -t $TABLE -X
done
$IPT -P INPUT DROP
$IPT -P OUTPUT ACCEPT
$IPT -A INPUT -s $LOCAL_RANGE -j ACCEPT
$IPT -A INPUT -s $INET_RANGE -j ACCEPT
$IPT -A INPUT -p tcp -s $REMOTE_ADMIN_RANGE --dport 22 -j ACCEPT
$IPT -A INPUT -p tcp --dport 22 -j DROP
#Enable TCP SYN Cookie Protection
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
########################################################
#Stealth Scans and TCP State Flags
#All of the bits are cleared
$IPT -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
#SYN and FIN are both set
$IPT -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
#SYN and RST are both set
$IPT -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
#FIN and RST are both set
$IPT -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j DROP
#FIN is the only bit set,without the expected accompanying ACK
$IPT -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j DROP
#PSH is the only bit set,without the expected accompanying ACK
$IPT -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j DROP
#URG is the only bit set,without the expected accompanying ACK
$IPT -A INPUT -p tcp --tcp-flags ACK,URG URG -j DROP
#############################################################
# ICMP Control and Status Message
$IPT -A INPUT --fragment -p icmp -j DROP
$IPT -A OUTPUT --fragment -p icmp -j DROP
###########################################################
#Using Connection State to by-pass Rule Checking
$IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPT -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPT -A INPUT -m state --state INVALID -j DROP
$IPT -A OUTPUT -m state --state INVALID -j DROP
###########################################################
#China NetRange
# wget -c http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst
# grep cn country-ipv4.lst | awk '{print $5}' > cn.txt
while read iprange
do
$IPT -A INPUT -s $iprange -j ACCEPT
done
本文來自ChinaUnix博客,如果查看原文請點(diǎn):http://blog.chinaunix.net/u/12592/showart_2077912.html |
|