UFW规则的组合会拒绝所有出站连接,除了安装Ubuntu安全更新所需的那些外。
我通常不使用ufw。 我直接使用iptables。
Ubuntu通常使用http协议获取更新。 所以,你需要打开出站HTTP端口。 如果你想限制你的规则在特定的主机上,你需要找出Ubuntu的存储库IP /etc/apt/sources.list 。
更好的解决scheme是将HTTPstream量redirect到Web代理,并只允许特定的域/ URL。 这比使用防火墙对IP进行parsing更加准确。
通过一个简单的例子扩展Khaled的答案:…
Python程序列出与软件更新关联的IP地址:
#!/usr/bin/env python import re, subprocess re1 = re.compile("deb http://(.+?)/") re2 = re.compile("Address:\s*(\d+\.\d+\.\d+\.\d+)") IPv4 = {} with open("/etc/apt/sources.list") as f: for line1 in f: m1 = re1.match(line1) if(m1): url = m1.group(1) p = subprocess.Popen(["nslookup", url], stdout=subprocess.PIPE) out,err = p.communicate() # Parse the output of nslookup: next_line_is_address = False for line2 in out.split("\n"): if(line2.startswith("Name:")): next_line_is_address = True elif(next_line_is_address): m2 = re2.match(line2) if(m2): IPv4[m2.group(1)] = True next_line_is_address = False print "\n".join(sorted(IPv4.keys())) # or call "ufw allow..." to allow port 80 outbound to these addresses
样本产出(截至2014年1月):
user@pc:~$ ./ubuntu_servers.py 194.169.254.10 91.189.91.13 91.189.91.14 91.189.91.15 91.189.92.156 91.189.92.190 91.189.92.200 91.189.92.201
whois 91.189.92.201表示91.189.91.0/24属于Canonical,所以如果我们正在configuration防火墙,那么这可能是一个有用的地址范围。