LoginSignup
1
2

More than 5 years have passed since last update.

gmailからのアクセスを許可するホワイトリストを作成する。

Last updated at Posted at 2018-06-27

メールサーバの防衛対策

 ipsetとiptabableで特定亜細亜権からのアクセスは拒否していたけれど、それ以外からも
 大量にメールが送られてくるようになってきたので、根本対処をするためにホワイトリスト
 に登録したアドレス帯域からのメールしか受信できないように対策した。
 基本設定は、日本国内からアクセスのみをホワイトリストに設定した。

改善しないといけないところ

 国内のみで良いかというとそうでもない、特に活用させていただいている。
 下記からのメールは許可しておきたい。

 ① Google mail
 ② マイクロソフト社からのメール
 ③ Amazonからのメール

 Google mailのからのIPアドレス一覧作成

Googleで公式に公開されている、下記のページを参照して、自動的に
 ホワイトリストを登録するShellを作成しました。
 必要な方もいそうな気がしますので、添付しておきます。

 情報参照元:https://support.google.com/a/answer/60764?hl=ja

GetGmailIPtoIPset.sh
#! /bin/bash

Val=`nslookup -q=txt _spf.google.com 8.8.8.8 | tr ":" "\n" | tr " " "\n"| grep -v text | grep google.com`

(
for i in $Val
do
   nslookup -q=TXT $i 8.8.8.8 | tr " " "\n" | grep ip4 | sed -e "s=ip4:=ipset add WHITE =g"
done
) > /tmp/googleip.sh

sh -x /tmp/googleip.sh

マイクロソフト社からのメール

マイクソフトの下記のページに情報がまとまっているようです。
 「Exchange Online Protection の IP アドレス」
  ※EOP の IP アドレスの範囲の完全な一覧 (2018 年 3 月 1 日現在)
上記、データを使って力ずくで、Shell作成

GetOutlookIPtoIPset.sh
#! /bin/bash
ipset add WHITE 23.103.132.0/22
ipset add WHITE 23.103.136.0/21
ipset add WHITE 23.103.144.0/20
ipset add WHITE 23.103.198.0/23
ipset add WHITE 23.103.200.0/22
ipset add WHITE 23.103.212.0/22
ipset add WHITE 40.92.0.0/14
ipset add WHITE 40.107.0.0/17
ipset add WHITE 40.107.128.0/18
ipset add WHITE 52.100.0.0/14
ipset add WHITE 65.55.88.0/24
ipset add WHITE 65.55.169.0/24
ipset add WHITE 94.245.120.64/26
ipset add WHITE 104.47.0.0/17
ipset add WHITE 157.55.234.0/24
ipset add WHITE 157.56.110.0/23
ipset add WHITE 157.56.112.0/24
ipset add WHITE 207.46.100.0/24
ipset add WHITE 207.46.163.0/24
ipset add WHITE 213.199.154.0/24
ipset add WHITE 213.199.180.128/26
ipset add WHITE 216.32.180.0/23

Amazonからのメール

既に、公開されている素敵な情報がありましたので、活用させていただきます。
https://qiita.com/iharakenji/items/81d84bb76a97a54478d7

情報の公開ありがとうございます! @iharakenji さん

GetAmazonIPtoIPset.sh
#! /bin/bash

Val=`curl https://ip-ranges.amazonaws.com/ip-ranges.json | jq '.prefixes[] | select(.servi
ce=="AMAZON") | .ip_prefix' | tr -d '\"'`

for i in $Val
do
      ipset add WHITE $i
done
```   

以上で、目的達成しました。


1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2