谷歌云平台堆栈驱动程序TCP端口正常运行时间检查:3306



我确实在GCP stackdriver上设置了一个正常运行时间检查,以监控TCP端口3306,如果我通过打开IP范围为0.0.0.0/0的端口3306来在GCP中设置防火墙规则,它就会起作用,但这会让很多黑客机器人试图攻击我们的MySQL服务器。

有人知道stackdriver运行正常运行时间检查的IP范围是多少吗?这样我就可以加入防火墙规则了。

谢谢,

Google Cloud通过TXT DNS资源记录发布IP地址范围。

[更新12/18/2018]。谷歌现在发布了一种获取StackDriver IP地址的方法:

client = monitoring_v3.UptimeCheckServiceClient()
ips = client.list_uptime_check_ips()
print(tabulate.tabulate(
[(ip.region, ip.location, ip.ip_address) for ip in ips],
('region', 'location', 'ip_address')
))

获取正常运行时间检查IP地址

[结束更新]

谷歌会更改IP地址,因此您需要一个自动工具来处理更新。下面我展示了获取CIDR块的手动方法。在实践中,我会用Python编写一个云函数来处理这个列表,然后更新防火墙规则集。

我的信息来源是谷歌Qwiklabs。我在一个实验室记录了这件事——我不记得是哪一个了。

nslookup -q=TXT _cloud-netblocks.googleusercontent.com  8.8.8.8

这将返回TXT记录:

usercontent.com  8.8.8.8
Server:  google-public-dns-a.google.com
Address:  8.8.8.8
Non-authoritative answer:
_cloud-netblocks.googleusercontent.com  text =
"v=spf1 include:_cloud-netblocks1.googleusercontent.com include:_cloud-netblocks2.googleusercontent.com include:_cloud-netblocks3.googleusercontent.com include:_cloud-netblocks4.googleusercontent.com include:_cloud-netblocks5.googleusercontent.com ?all"

最后一行包括许多要处理的其他记录,从以下开始:_cloud-netblocks1.googleusercontent.com

nslookup -q=TXT _cloud-netblocks1.googleusercontent.com 8.8.8.8

它返回一个您感兴趣的信息块。请注意,您需要对上面返回的每个_cloud-xxxx记录重复此操作。

Server:  google-public-dns-a.google.com
Address:  8.8.8.8
Non-authoritative answer:
_cloud-netblocks1.googleusercontent.com text =
"v=spf1 include:_cloud-netblocks6.googleusercontent.com include:_cloud-netblocks7.googleusercontent.com ip4:8.34.208.0/20 ip4:8.35.192.0/21 ip4:8.35.200.0/23 ip4:108.59.80.0/20 ip4:108.170.192.0/20 ip4:108.170.208.0/21 ?all"

注意上面的最后一行。这包含多个CIDR块。重复我上面提到的内容。

ip4:8.34.208.0/20 ip4:8.35.192.0/21 ip4:8.35.200.0/23 ip4:108.59.80.0/20 ip4:108.170.192.0/20 ip4:108.170.208.0/21

最新更新