iptables の設定確認

前前回前回で、iptables/ip6tables の設計・設定を行った。今回は、iptables/ip6tables の設定を確認していく。

確認はすべてsu で root になって実施している。

対象
内部用サーバー
外部用サーバー
OS
CentOS release 5.10

iptables/ip6tables の設定内容を確認する

iptables/ip6tables の設定内容の確認は、iptables/ip6tables にインターフェースを表示する詳細オプション(-v)と、チェインを表示するオプション(-L)、アドレス等を数値で表示するオプション(-n)をつけて行った。インターフェースの表示が不要であれば、起動スクリプトに「status」オプションを渡して表示することもできる。

設計した設定と、確認結果が一致していれば問題ない。なお、出力結果はブラウザで見やすいように整形している。

IPv4の設定確認

[root@server ~]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target               prot opt in out source    destination
1069K  120M RH-Firewall-1-INPUT  all  --  *  *   0.0.0.0/0 0.0.0.0/0

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target               prot opt in out source    destination
    0     0 RH-Firewall-1-INPUT  all  --  *  *   0.0.0.0/0 0.0.0.0/0

Chain OUTPUT (policy ACCEPT 1392K packets, 1591M bytes)
 pkts bytes target prot opt in out source destination

Chain RH-Firewall-1-INPUT (2 references)
 pkts bytes target prot opt in out source    destination
26836   13M ACCEPT all  --  lo *   0.0.0.0/0 0.0.0.0/0
 1971  116K ACCEPT icmp --  *  *   0.0.0.0/0 0.0.0.0/0 icmp type 255
    0     0 ACCEPT esp  --  *  *   0.0.0.0/0 0.0.0.0/0
    0     0 ACCEPT ah   --  *  *   0.0.0.0/0 0.0.0.0/0
    0     0 ACCEPT udp  --  *  *   0.0.0.0/0 224.0.0.251 udp dpt:5353
 961K  102M ACCEPT all  --  *  *   0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
   14   728 ACCEPT tcp  --  *  *   0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:[port]
10294 1253K REJECT all  --  *  *   0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

IPv6の設定確認

[root@server ~]# ip6tables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target               prot opt in out source destination
   57  5672 RH-Firewall-1-INPUT  all      *  *   ::/0   ::/0

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target               prot opt in out source destination
    0     0 RH-Firewall-1-INPUT  all      *  *   ::/0   ::/0

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

Chain RH-Firewall-1-INPUT (2 references)
 pkts bytes target prot opt in  out source destination
   38  3952 ACCEPT all      lo  *   ::/0   ::/0
   19  1720 ACCEPT icmpv6   *   *   ::/0   ::/0
    0     0 ACCEPT esp      *   *   ::/0   ::/0
    0     0 ACCEPT ah       *   *   ::/0   ::/0
    0     0 ACCEPT udp      *   *   ::/0   ff02::fb/128 udp dpt:5353
    0     0 ACCEPT all      *   *   ::/0   ::/0 state RELATED,ESTABLISHED
    0     0 ACCEPT tcp      *   *   ::/0   ::/0 state NEW tcp dpt:[port]
    0     0 REJECT all      *   *   ::/0   ::/0 reject-with icmp6-adm-prohibited

外部から nmap で確認する

設定した内容が正しく適用できているかどうか、外部から確かめるためには nmap を利用すればよい。nmap は、広く利用されているポートスキャンツールで、ポートスキャンを行うとともに、利用している OS や動作しているアプリケーションのバージョンを簡単に調べることができる。

自分の管理しているホスト以外に、ポートスキャンを行ってはならない。ポートスキャンは攻撃を行う前に行う準備作業であり、ホストに対する攻撃を行おうとしていると判断される可能性がある。

IPv4の設定確認

IPv4の場合は、特別なオプションは必要ない。ポート番号を1~65535まで調べるようにしておけば、すべてをチェックできる。

nmap -p1-65535 [host]

結果は、以下の通りだ。

Starting Nmap 5.51 ( http://nmap.org ) at 2013-10-30 17:01 JST
Nmap scan report for [host] ([host ip address])
Host is up (0.060s latency).
Not shown: 65531 filtered ports
PORT      STATE SERVICE
[port]/tcp open  unknown

Nmap done: 1 IP address (1 host up) scanned in 245.11 seconds

なお「-A」オプションをつけると、利用している OS や動作しているアプリケーションのバージョンを推測する。iptables で開けているポートが、 OpenSSH 4.X がサービスしていると判断された。

nmap -A -p[port] [host]

Starting Nmap 5.51 ( http://nmap.org ) at 2013-10-30 17:12 JST
Nmap scan report for [host] ([host ip address])
Host is up (0.016s latency).
PORT      STATE SERVICE VERSION
[port]/tcp open  ssh     OpenSSH 4.X (protocol 2.0)
| ssh-hostkey: 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx (DSA)
|_2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx (RSA)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose|specialized|WAP|storage-misc
Running (JUST GUESSING): Linux 2.6.X|2.4.X (91%), Crestron 2-Series (90%), Netgear embedded (90%), IBM embedded (89%), Ruckus embedded (89%), TP-Link embedded (89%), Linksys Linux 2.4.X (89%), Asus Linux 2.6.X (89%)
Aggressive OS guesses: Linux 2.6.9 - 2.6.18 (91%), Crestron XPanel control system (90%), Netgear DG834G WAP (90%), Linux 2.6.9 (89%), IBM System Storage DS4700 NAS device (89%), Linux 2.6.18 (89%), Linux 2.6.21 (89%), Linux 2.6.22 (89%), Linux 2.6.28 (Gentoo) (89%), Linux 2.6.5 (SUSE Enterprise Server 9) (89%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 13 hops

TRACEROUTE (using port [port]/tcp)
HOP RTT      ADDRESS
1   1.81 ms  ...
2   5.95 ms  ...
...
13  15.83 ms [host] ([host ip address])

OS and Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 13.03 seconds

IPv6の設定確認

前回記述したように、リンクローカルアドレスしか持っていないので、外部から調査することはできなかった。該当のサーバーにインストールできる nmap も古いため(バージョン6でフルサポート)、IPv6の環境を整えてから実施する。


1 thoughts on “iptables の設定確認

  1. ピンバック: パッケージ(アプリケーション)の整理 | UB Lab.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Time limit is exhausted. Please reload CAPTCHA.