2008年7月24日木曜日

自宅サーバ構築 No.009(パケットフィルタ )

順番が逆ですが、公開する前にいわゆるパケットフィルタ系の設定をしておく必要があります。基本は TCP Wrapper と xinetd による対策と、iptables(Netfilter) による対策です。

それぞれの関係ですが、TCP Wrapper で判定された通信が、xinetd に渡されます。また、TCP Wrapper に渡る前に、iptables で判定されるようになっています。

外から入ってくるパケットは、iptables → TCP Wrapper → xinetd というルートで目的のアプリケーション(ssh/telnet/ftp 等)と通信します。

初期状態で、CentOS 5.2 の iptables は以下の状態です。

# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere

Chain FORWARD (policy ACCEPT)
target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Chain RH-Firewall-1-INPUT (2 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT icmp -- anywhere anywhere icmp any
ACCEPT esp -- anywhere anywhere
ACCEPT ah -- anywhere anywhere
ACCEPT udp -- anywhere 224.0.0.251 udp dpt:mdns
ACCEPT udp -- anywhere anywhere udp dpt:ipp
ACCEPT tcp -- anywhere anywhere tcp dpt:ipp
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
REJECT は、reject-with icmp-host-prohibited の1行だけで、適切なエラーだけです。また、RH-Firewall-1-INPUT は、INPUT と FORWARD で使用されています。極々最低限の定義で、ほとんど許した後に、それ以外を拒否としているルールなので、iptables を適用していない状態と、ほとんど変わりません。

TCP Wrapper の初期設定は以下の状態です。
# cat /etc/hosts.allow
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#

# cat /etc/hosts.deny
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!

何も定義されていません。

iptables や TCP Wrapper は、例を元に、だいたいで設定をすることが多いのですが、ちょっと時間を掛けて、設定をじっくりやります。

0 件のコメント: