さくらの専用サーバー : iptables 設定。
まずは、設定をミスっても(無料)再起動で対応可能にしておく。
# /sbin/chkconfig iptables –list
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# /sbin/chkconfig iptables off
# /sbin/chkconfig iptables –list
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
接続不能になったら再起動してもらいましょう。
設定完了確認後 on にしておきましょう。
または、起動後は自分でiptablesを実行することをお忘れなく。
まずは、つながらなくなると困るので
ポリシー設定 INPUT ACCEPT
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -P FORWARD DROP
確認
/sbin/iptables -L
ルールを消す。
/sbin/iptables -F
/sbin/iptables -L
ローカルはすべて許可
/sbin/iptables -A INPUT -i lo -j ACCEPT
使うポートを設定
/sbin/iptables -A INPUT -p tcp –dport 80 -j ACCEPT
/sbin/iptables -A INPUT -p tcp –dport 22 -j ACCEPT
/sbin/iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
22は大丈夫かな?
/sbin/iptables -L
* 他は拒否する。
/sbin/iptables -P INPUT DROP
/sbin/iptables -L
外部から接続して問題なければ保存
/etc/init.d/iptables save
# /sbin/iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp — anywhere anywhere tcp dpt:http
ACCEPT tcp — anywhere anywhere tcp dpt:ssh
ACCEPT all — anywhere anywhere state RELATED,ESTABLISHED
ACCEPT all — anywhere anywhere
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
この状態で sshはつながるが ping は通らないのでOK