Egress filtering: controlling outbound traffic to stop malware and data theft
In short: Many networks block inbound traffic carefully but let anything leave. Malware uses that freedom to contact its controllers and send stolen data out. Egress filtering allows only the outbound traffic each group needs, forces DNS and web through approved resolvers and proxies, blocks risky protocols such as outbound SMB and SMTP, and logs denied attempts as early warning signs.
Why outbound matters
Once malware or an attacker is inside, they need to get out: to receive commands (command and control, or C2), download tools and upload stolen data. If the firewall allows "inside to internet, any", they have an open road. Egress filtering will not stop every technique, since attackers also use HTTPS to popular cloud services, but it makes their life harder, closes easy paths and generates useful alerts.
A sensible starting policy
| Source | Allow outbound |
|---|---|
| User devices | Web (80/443) through the proxy or secure web gateway; DNS only to internal resolvers; VPN and collaboration tools as needed |
| Servers | Only specific destinations: update servers, named APIs, backup targets. Most servers need no general internet access |
| DNS resolvers | DNS to upstream resolvers or the internet |
| Mail servers | SMTP (25) outbound |
| IoT, CCTV, building systems | Only their vendor cloud endpoints, or nothing |
| Everything else | Deny and log |
Block these outbound in almost every network
- SMB (TCP 445) and NetBIOS (137 to 139): there is rarely a reason for SMB to the internet, and it can leak password hashes.
- SMTP (25) from anything except mail servers: stops infected PCs sending spam.
- DNS (53) and DoT (853) from anything except your resolvers: forces lookups through filtered, logged DNS and blocks DNS tunnelling via outside servers.
- Telnet, RDP and SSH to the internet from user networks, unless needed for specific roles.
- Known bad destinations from threat intelligence feeds and newly registered domains.
Servers: the biggest quick win
Servers usually talk to a short, predictable list of outside services. Blocking all other outbound traffic from server networks stops many attack chains, such as a web server being exploited and then downloading a tool from the internet, or a compromised server sending data straight out. Use a proxy with an allow-list of update domains if servers need patches from the internet.
Detect as well as block
- Alert on denied outbound attempts from servers: they should be rare.
- Look for unusual volumes, uploads to rarely used destinations and long-lived connections at odd hours (NetFlow and NDR tools help).
- Watch DNS logs for tunnelling patterns.
Rolling out
- Log all outbound traffic for a few weeks and see what really leaves each zone.
- Write allow rules for the legitimate flows, with owners.
- Switch the final rule to deny, starting with servers and IoT, then users.
- Keep a fast process for adding new rules when a legitimate need appears.
Real-world example: the server that phoned home
An attacker exploited an unpatched web application on a company's public web server and tried to download a remote access tool from their own server. The company had recently applied egress filtering to its DMZ: the web server could only reach its update repository and the database. The download was denied and logged, the alert reached the security team within minutes, and the server was patched and rebuilt before the attacker got any further.
Practice
Why should outbound DNS be allowed only from internal resolvers?
Which zone usually gives the biggest quick win for egress filtering?
Name two protocols that should almost always be blocked outbound from user networks.
Key takeaways
- Control outbound traffic, not just inbound.
- Allow only what each zone needs; servers and IoT need very little.
- Force DNS and web through approved resolvers and proxies; block SMB and SMTP out.
- Log and alert on denied outbound attempts; roll out after observing real traffic.
Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.