おもちゃ環境備忘録 その2

さっそくブログ書くのもめんどくなってきた今日この頃ですが
アルコール飲んだ勢いで書き残します。

ファイアウォールの設定

さくらVPSはF/W無しですので
(本当はおもちゃ環境なので全部開けておきたいのですが)
念のため設定することにします。

現在の設定確認

CentOS 5.xの場合

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination  

CentOS 6.0の場合

hain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  405 35807 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED ←既存コネクションに関連するパケットを許可
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere ←icmpの着信を全て許可
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere ←loインターフェースからの接続を全て許可
    3   192 ACCEPT     tcp  --  any    any     anywhere             anywhere            state NEW tcp dpt:sshsshの新規接続を許可
   49  6616 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-host-prohibited ←拒否されたパケットとしてICMPエラーパケットを返す(REJECT)

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-host-prohibited ←拒否されたパケットとしてICMPエラーパケットを返す(REJECT)

Chain OUTPUT (policy ACCEPT 246 packets, 30139 bytes)
 pkts bytes target     prot opt in     out     source               destination 
(CentOS6のみ)既存のルールが邪魔なので消す
# iptables -F
# iptables -t nat -F
# iptables -X
# iptables -Z
# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
用途が決まってないので適当に使いそうなポート追加

local

# iptables -A INPUT -i lo -j ACCEPT

ssh

# iptables -A INPUT -p tcp --dport 22 -j ACCEPT -m state --state NEW

dns

# iptables -A INPUT -p tcp --dport 53 -j ACCEPT -m state --state NEW
# iptables -A INPUT -p udp --dport 53 -j ACCEPT -m state --state NEW

応答パケットの許可

#iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
INPUTとFORWARDをDROPするように変更する

INPUTチェーンとFORWARDチェーンは意図してないパケットが飛んできた時にドロップするようにします。

# iptables -P INPUT DROP
# iptables -P FORWARD DROP
せーぶ
# /etc/init.d/iptables save
Saving firewall rules to /etc/sysconfig/iptables:          [  OK  ]
設定確認
# iptables -L -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere            
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:ssh state NEW 
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:domain state NEW 
    0     0 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:domain state NEW 
  111  8412 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED 

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 39 packets, 3884 bytes)
 pkts bytes target     prot opt in     out     source               destination    

いじょー