リッスンポートによるLOGの分離
去年7月から続くしつこい付きまといアクセスが終息に向かっている為、7月1日より正規サイトへの国内限定制限を解除している。
解除時の記事はこちら。
野良アクセス観測再開!?
制限解除以前は、正規サイト(Main Server)については国内ネットワークからのアクセスと主要サーチエンジンのクローラのみを通し、それ以外はすべて Others に振り分け、アクセスログも分離していた。
また、Others 側のコンテンツは正規サイト(Main Server)とは全く異なる内容としていた。
●過去の振り分けイメージ
Internet
|
v
+----------------------------+
| Router |
| iptables / NAT |
+----------------------------+
| |
| |
Normal Suspicious
/ Allowed / Unknown
| |
v v
+----------------+ +----------------+
| 192.168.1.1:80 | |192.168.1.1:9080|
| 192.168.1.1:443| |192.168.1.1:9443|
| Main Server | | Others |
+----------------+ +----------------+
7月1日以降は、すべてのアクセスを正規サイト(Main Server)側へ通し、Others への振り分けを廃止したため、Others 側の構成は役目を終えていた。
何か活用できないか検討した結果、国内ネットワークからのアクセスのみを正規サイト(Main Server)へ通し、それ以外のWebアクセスはすべて Others 側へ振り分けることで、アクセスログを分離する目的に利用することにした。
Others 側の公開ディレクトリには、正規サイト(Main Server)のディレクトリへのシンボリックリンクを作成し、両者で同一のコンテンツを公開している。
サーチエンジンのクローラも Others 側へ振り分けられるが、コンテンツは正規サイトと完全に同一であるため、実用上の問題はない。
iptables構成
●PREROUTINGチェイン
PREROUTINGチェインにて、Main Server と Others への振り分けを完結させる。
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 0 0 DNAT tcp -- ppp0 any anywhere anywhere tcp dpt:ssh match-set jpnet src to:192.168.1.1:22
2 93 5272 DNAT tcp -- ppp0 any anywhere anywhere tcp dpt:smtp to:192.168.1.1:25
3 0 0 DNAT tcp -- ppp0 any anywhere anywhere tcp dpt:http match-set jpnet src to:192.168.1.1:80
4 3 156 DNAT tcp -- ppp0 any anywhere anywhere tcp dpt:https match-set jpnet src to:192.168.1.1:443
5 0 0 DNAT tcp -- ppp0 any anywhere anywhere tcp dpt:submission match-set jpnet src to:192.168.1.1:587
6 0 0 DNAT tcp -- ppp0 any anywhere anywhere tcp dpt:imaps match-set jpnet src to:192.168.1.1:993
7 139 7230 DNAT tcp -- ppp0 any anywhere anywhere tcp dpt:http to:192.168.1.1:9080
8 369 19120 DNAT tcp -- ppp0 any anywhere anywhere tcp dpt:https to:192.168.1.1:9443
・jpnet
日本国内からのアクセスを Main Server(80 / 443)へ振り分け
・上記に該当しないWebアクセス
Others(9080 / 9443)へ振り分け
●FORWARDチェイン
Chain FORWARD (policy DROP 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 13M 12G ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
2 0 0 DROP tcp -- br0 ppp0 anywhere anywhere tcp dpts:137:netbios-ssn
3 0 0 DROP udp -- br0 ppp0 anywhere anywhere udp dpts:netbios-ns:139
4 0 0 DROP tcp -- br0 ppp0 anywhere anywhere tcp dpt:microsoft-ds
5 0 0 DROP udp -- br0 ppp0 anywhere anywhere udp dpt:445
6 0 0 DROP tcp -- br0 ppp0 anywhere anywhere tcp dpt:sunrpc
7 0 0 DROP udp -- br0 ppp0 anywhere anywhere udp dpt:sunrpc
8 15524 9653K ACCEPT all -- br0 ppp0 192.168.1.0/24 anywhere
9 97 4818 DROP all -- ppp0 br0 anywhere anywhere match-set firehol_level3 src
10 131 5752 DROP all -- ppp0 br0 anywhere anywhere match-set firehol_level2 src
11 3 120 DROP all -- ppp0 br0 anywhere anywhere match-set firehol_level1 src
12 44 2476 DROP all -- ppp0 br0 anywhere anywhere match-set gcloud src
13 30 1800 DROP all -- ppp0 br0 anywhere anywhere match-set aws_block src
14 39 1988 ACCEPT tcp -- ppp0 br0 anywhere 192.168.1.1 tcp dpt:9080
15 239 13664 ACCEPT tcp -- ppp0 br0 anywhere 192.168.1.1 tcp dpt:9443
16 24 1284 ACCEPT all -- ppp0 br0 anywhere 192.168.1.1
・firehol_level1~3
FireHOL公開のブラックリストIPを遮断(Main / Others 共通)
・gcloud
スパム傾向の強い Google Cloud からのアクセスを遮断(Main / Others 共通)
・aws_block
必要に応じてAWSのスパムアクセスを遮断(Main / Others 共通)
この構成により、国内からの通常アクセスと海外・不特定アクセスのログを完全に分離できるようになった。
Webサーバー側の設定を変更することなく、iptables のリッスンポート振り分けだけで管理できるため、構成も比較的シンプルで運用しやすい。