TL;DR
CVE-2021-44228 (Log4Shell) allows attackers to execute code on your servers. Blocking outbound connections can prevent compromised systems from communicating with attacker-controlled infrastructure, limiting damage. This guide shows you how.
Blocking Outbound Connections
- Understand the Risk: Log4j vulnerabilities allow remote code execution. Even if you patch, blocking outbound traffic adds a layer of defence against potentially compromised systems attempting to connect to malicious servers.
- Identify Potential Outbound Traffic: Attackers often use DNS and standard HTTP/HTTPS ports (80, 443) for command-and-control. Look for unusual connections from your servers.
- Use network monitoring tools to identify outbound traffic patterns.
- Check firewall logs for suspicious destinations.
- Firewall Rules (iptables – Linux): Use iptables to block outbound connections to known malicious IPs or ranges.
sudo iptables -A OUTPUT -p tcp --dport 80 -j DROPsudo iptables -A OUTPUT -p tcp --dport 443 -j DROPsudo iptables -A OUTPUT -p udp --dport 53 -j DROPImportant: These rules block *all* outbound traffic on those ports. Refine them to only block suspicious destinations.
- Firewall Rules (ufw – Linux): If you use UFW, the commands are simpler.
sudo ufw deny 80sudo ufw deny 443sudo ufw deny 53Again, refine these rules to avoid blocking legitimate traffic.
- Windows Firewall: Use the Windows Defender Firewall with Advanced Security.
- Open ‘Windows Defender Firewall with Advanced Security’.
- Create a new Outbound Rule.
- Select ‘Port’ and specify TCP ports 80, 443, and UDP port 53.
- Choose ‘Block the connection’.
- Apply the rule to appropriate profiles (Domain, Private, Public).
- Cloud Provider Firewalls: If you’re using AWS, Azure, or Google Cloud, use their respective firewall services (Security Groups, Network Security Groups, Firewall Rules).
- AWS Security Groups: Modify inbound and outbound rules for your EC2 instances.
- Azure Network Security Groups: Create rules to block traffic to specific destinations.
- Google Cloud Firewall Rules: Define rules based on IP ranges, ports, and protocols.
- DNS Filtering: Consider using a DNS filtering service that blocks known malicious domains.
- Services like Quad9 or OpenDNS can help prevent connections to attacker infrastructure.
- Regularly Update Blocklists: Malicious IPs and domains change frequently. Keep your blocklists updated from reputable sources.
- Automate the update process if possible.
- Monitor Firewall Logs: Continuously monitor firewall logs for blocked connections to identify potential compromises or false positives.
- Test Your Rules: After implementing rules, test connectivity to ensure legitimate traffic isn’t affected. Use tools like
pingortraceroute.
Blocking outbound connections is a temporary mitigation measure. Patching Log4j and addressing the root cause of the vulnerability are crucial for long-term security.

