What combination of UFW rules would deny all outbound connections except for those which are required to install Ubuntu security updates?
What combination of UFW rules would deny all outbound connections except for those which are required to install Ubuntu security updates?
My answer is for a more general case, not only for
apt-get
.To deny all outgoing IPs except one IP
To quickly revert, allow again all outgoing IPs
To deny all outgoing except HTTP and HTTPS on one IP
You can be more restrictive:
The above two rules allow TCP only, you do need to specify the protocol (tcp or udp). You can even be more restrictive specifying the interface as eth0, for example to avoid using the WiFi... But I think this is not useful...
Check/Clean your UFW rules
If another IP is still accessible, the origin may be some residual rules. It is a good practice, to check the current UFW rules:
You may have to delete some polluting rules:
Also allow DNS
Your software may use domain name instead of numeral IP address.
As UFW uses numeral IP address, the following manual example should be scripted to be easily performed again when IPs change.
Retrieve your DNS IP Allow DNS (TCP and UDP) for only your DNS servers Allow DNS (TCP and UDP) for only your DNS serversI don't usually use ufw. I use iptables directly.
Ubuntu usually gets updates using http protocol. So, you need to have outbound HTTP port open. If you want to restrict your rules on specific hosts, you need to figure out the Ubuntu repositories IPs
/etc/apt/sources.list
.A better solution is to redirect HTTP traffic to web proxy and allow only specific domains/URLs. This is more accurate than resolving names to IPs to block them using firewall.
Expanding on Khaled's answer with a brief example:...
Python program to list the IP addresses associated with software updates:
Sample output (as of January 2014):
whois 91.189.92.201
says that 91.189.91.0/24 belongs to Canonical, so if we're configuring a firewall then that might be a useful address-range to remember.