/etc/hosts.allow /etc/hosts.denyファイルでアクセス制限設定をする

 Linuxサーバでアクセス制限を行いたい場合には,大きく分類すると次のような手段がある。

1. アクセス元の条件を決める
 hosts.allow,hosts.denyファイルでは,IPやドメインを指定してアクセス元を限定することができる。

2. どのサービスを起動許可するかを決める
 デーモン起動以外のinetサービスでは,inetdでサービスの起動許可を設定する。

3. TCP,UDPごとのフィルタ設定を行う
 tcp wrapperなどによって,特定のポート番号でのアクセスを制限する。一般的にファイアウォールと呼ばれるアクセス制限の手段。

 ここでは,1番の/etc/hosts.allow,/etc/hosts.denyの記述例を挙げてみよう。

・hosts.allow
 アクセス許可条件を設定するファイル
・hosts.deny
 アクセス不可条件を設定するファイル

 2つのファイル共に,基本的に次のような記述フォーマットになっている。

デーモン名:ホスト名またはIPアドレス
例:in.telnetd: 192.168.0.

 実際のファイル例を挙げてみよう。次のように各ファイルを編集することで,各サービスのアクセスを制御することが可能だ。

1. まず最初にすべてのアクセスを禁止する

# vi /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!
ALL : ALL

2. アクセス許可をするサービスとIP(ドメイン名)を指定する

# vi /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.
#
in.telnetd: 192.168.0. sora.umi.ne.jp
in.ftpd: 192.168.0. sora.umi.ne.jp
in.popper: 192.168.0. sora.umi.ne.jp

※上記の設定では,telnet,ftp,POPのアクセスを許可するが「192.168.0.*」と「sora.umi.ne.jp」からのアクセスのみを許可している。この設定以外のサービスは,hosts.deny設定ですべて拒否される。