<Location />
Order allow,deny
Allow Form 127.0.0.0/8
Allow From 192.168.0.0/24
</Location>
<Location /admin>
Encryption Required ;這項若開則會變為 https 連線
Order allow,deny
Allow Form 127.0.0.0/8
Allow From 192.168.0.0/24
</Location>
# 請先輸入您的相關參數,不要輸入錯誤了!
# English: Please input your networks parameters ( including your LAN NIC )
EXTIF="eth0" # 這個是可以連上 Public IP 的網路介面,也可能是 ppp0
# This is your NIC, connect to internet. Such as ppp0...
INIF="" # 內部 LAN 的連接介面;若無 LAN ,填寫成 INIF=""
# This is your LAN NIC. If you don't have a LAN, input INIF="" please.
INNET="" # 若有兩個以上的網域,可以用 NNET="192.168.1.0/24 192.168.100.0/24"
# 若無內部網域介面,請填寫成 INNET=""
# This is your LAN's Network. If you have to private network,
# input as INNET="192.168.1.0/24 192.168.100.0/24".
export EXTIF INIF INNET
# 個人化設定啊!請自行填寫您自己想要預先啟動的一些基礎資料。
# These settings is about yourself's paramters.
allowname='' # 允許登入本機的 hostname ,必須是 Internet 找的到的 hostname。
allowip=""
if [ "$allowname" != "" ]; then
for siteiptmp in `echo $allowname`
do
siteip=`/usr/bin/host $siteiptmp 168.95.1.1 | grep address|tail -n 1 | awk '{print $4}'`
testip=`echo $siteip | grep [^0-9.]`
if [ "$testip" == "" ]; then
allowip="$allowip $siteip"
fi
done
fi
export allowip
# 第一部份,針對本機的防火牆設定!#########################################################
# First, your server's firewall settings.
# 1. 先設定好核心的網路功能:
# 1. the kernel's firewall settings.
# 開啟 TCP Flooding 的 DoS 攻擊抵擋機制,但這個設定不適合 loading 已經很高的主機!!!
# TCP Flooding's setting. this setting is no good for high loading servers
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
# 取消 ping 廣播的回應;
# unset reply of ping.
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# 開啟逆向路徑過濾,以符合 IP 封包與網路介面的設定;
#
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo "1" > $i
done
# 開啟記錄有問題的封包
# record some problems packets.
for i in /proc/sys/net/ipv4/conf/*/log_martians; do
echo "1" > $i
done
# 取消來源路由,這個設定值是可以取消的;
for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do
echo "0" > $i
done
# 取消重新宣告路徑的功能。
for i in /proc/sys/net/ipv4/conf/*/accept_redirects; do
echo "0" > $i
done
# 取消傳送重新宣告路徑的功能。
for i in /proc/sys/net/ipv4/conf/*/send_redirects; do
echo "0" > $i
done
# 2. 清除規則、設定預設政策及開放 lo 與相關的設定值
# 2. clear rule, set the policy rule and allow lo connect.
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin; export PATH
iptables -F
iptables -X
iptables -Z
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# 3. 啟動額外的防火牆 script 模組
# 3. other shell scripts, written by VBird.
# 預設抵擋的主機
if [ -f /usr/local/virus/iptables/iptables.deny ]; then
sh /usr/local/virus/iptables/iptables.deny
fi
# 預設開放的主機
if [ -f /usr/local/virus/iptables/iptables.allow ]; then
sh /usr/local/virus/iptables/iptables.allow
fi
# 透過 WWW 砍站軟體分析的抵擋機制
if [ -f /usr/local/virus/httpd-err/iptables.http ]; then
sh /usr/local/virus/httpd-err/iptables.http
fi
# 4. 允許某些類型的 ICMP 封包進入
# 4. allow some types of ICMP
AICMP="0 3 3/4 4 11 12 14 16 18"
for tyicmp in $AICMP
do
iptables -A INPUT -i $EXTIF -p icmp --icmp-type $tyicmp -j ACCEPT
done
# 第二部份,針對後端主機的防火牆設定!#########################################################
# Second, the NAT settings.
# 1. 先載入一些有用的模組
# 1. loading some good modules of iptables.
modules="ip_tables iptable_nat ip_nat_ftp ip_nat_irc ip_conntrack ip_conntrack_ftp ip_conntrack_irc"
for mod in $modules
do
testmod=`lsmod | grep "^${mod} " | awk '{print $1}'`
if [ "$testmod" == "" ]; then
modprobe $mod
fi
done
# 3. 開放成為路由器,且為 IP 分享器!
# 3. NAT server's settings
if [ "$INIF" != "" ]; then
iptables -A INPUT -i $INIF -j ACCEPT
echo "1" > /proc/sys/net/ipv4/ip_forward
if [ "$INNET" != "" ]; then
for innet in $INNET
do
iptables -t nat -A POSTROUTING -s $innet -o $EXTIF -j MASQUERADE
done
fi
fi
# 如果你的 MSN 一直無法連線,或者是某些網站 OK 某些網站不 OK,可能是 MTU 的問題,
# 那你可以將底下這一行給他取消註解來啟動 MTU 限制範圍
# iptables -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1400:1536 -j TCPMSS --clamp-mss-to-pmtu