2008年9月5日金曜日

ubuntuでiptables

ubuntuは大変良いのだけど,FedoraやらRHやらと違って,ファイアウォールなどがデフォルトでは入らない.自分で設置してみよう. iptable を呼び出すスクリプトを書く. このサイトを参考に.設定としては,とりあえずsshのみを通すことに.必要ならその都度あければいい.
#!/bin/sh

ssh_port='22'

# Flush & Reset
iptables -F
iptables -X

# Deafult Rule
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

# loopback is OK
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# The response of the packet which connection established is OK
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# ICMP(ping)
iptables -A INPUT -p icmp -j ACCEPT

# ssh
iptables -A INPUT -p tcp --dport $ssh_port -j ACCEPT    
自動でこれが実行されるように,/etc/rc3.d と /etc/rc5.dからリンクをはればいい.ほんとうは,start/stopを解釈するようにしなければいけないのだが,面倒なので省略.

0 件のコメント: