#! /bin/sh #サーチエンジンで直接このページにきた人向け文章: # http://www.flatray.com/~hiramoto/linux/adsl/ # に、このファイルについての簡単な解説があります。 #E=echo ############################################################################### Accept () { srcs=$1 type=$2 protocols=$3 for src in `echo $srcs | sed 's/,/ /g'` do for port in `echo $protocols | sed 's/,/ /g'` do # $E iptables -A INPUT -s $src -p $type -dport $port -j ACCEPT if [ x"$src" = x"0.0.0.0" ] then $E iptables -A INPUT -p $type --destination-port $port -j ACCEPT else $E iptables -A INPUT -s $src -p $type --destination-port $port -j ACCEPT fi done done } ############################################################################### ### $E modprobe -r ipchains for i in `yes y | head -20` do iptables -D block 1 iptables -D INPUT 1 iptables -D OUTPUT 1 iptables -D FORWARD 1 iptables -t nat -D POSTROUTING 1 iptables -t nat -D PREROUTING 1 done > /dev/null 2>&1 ## コネクション追跡モジュールの挿入(カーネル直組み込みの場合は不要) $E modprobe ip_conntrack $E modprobe ip_conntrack_ftp # Load the NAT module (this pulls in all the others). $E modprobe iptable_nat ## 内部からのもの以外の新しいコネクションをブロックするチェインの作成 $E iptables -N block $E iptables -A block -m state --state ESTABLISHED,RELATED -j ACCEPT $E iptables -A block -m state --state NEW -i ! ppp0 -j ACCEPT # あんまり嬉しくないものはログに残す $E iptables -A block -p tcp -j LOG --log-level info --log-prefix 'iptables: ' $E iptables -A block -p udp -j LOG --log-level info --log-prefix 'iptables: ' $E iptables -A block -p icmp -j LOG --log-level info --log-prefix 'iptables: ' # 捨てる $E iptables -A block -j DROP # In the NAT table (-t nat), Append a rule (-A) after routing # (POSTROUTING) for all packets going out ppp0 (-o ppp0) which says to # MASQUERADE the connection (-j MASQUERADE). $E iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE ## どこからでも接続を受け付ける (外部向けサービスなど) # www,smtp,domain,ident Accept 0.0.0.0 tcp 80,25,53,113 Accept 0.0.0.0 udp 53 ## 特定の所からのみ接続を受け付ける # NNTP feed # nntp Accept 10.0.0.1,172.16.0.1 tcp 119 ## Send incoming port-80 web traffic to our squid (transparent) proxy $E iptables -t nat -A PREROUTING -i eth0 -p tcp --destination-port 80 -j REDIRECT --to-port 8080 ## IRC dcc send $E iptables -t nat -A PREROUTING -i ppp0 -p tcp --destination-port 6666 -j DNAT --to-destination 192.168.0.1:6666 $E iptables -A FORWARD -p tcp --destination 192.168.0.1 --destination-port 6666 -j ACCEPT ## INPUT および FORWARD チェインから上記のチェインへジャンプする $E iptables -A INPUT -j block $E iptables -A FORWARD -j block echo 1 > /proc/sys/net/ipv4/ip_forward