Free tech learning for everyone, from basics to pro

Network SecurityNetworking SecurityIntermediate

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.

Default allow out compared with egress filteringAllow all outboundAnything can leaveMalware calls home freelyData can leave on any portSimple to runEgress filteringOnly needed traffic leavesC2 and tunnels blockedLogs show attemptsNeeds planning and upkeep
Figure 1. Controlling what leaves the network is as important as controlling what comes in.

A sensible starting policy

SourceAllow outbound
User devicesWeb (80/443) through the proxy or secure web gateway; DNS only to internal resolvers; VPN and collaboration tools as needed
ServersOnly specific destinations: update servers, named APIs, backup targets. Most servers need no general internet access
DNS resolversDNS to upstream resolvers or the internet
Mail serversSMTP (25) outbound
IoT, CCTV, building systemsOnly their vendor cloud endpoints, or nothing
Everything elseDeny 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

  1. Log all outbound traffic for a few weeks and see what really leaves each zone.
  2. Write allow rules for the legitimate flows, with owners.
  3. Switch the final rule to deny, starting with servers and IoT, then users.
  4. 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?
So all lookups go through filtered and logged resolvers, and malware cannot use outside DNS servers or tunnelling freely.
Which zone usually gives the biggest quick win for egress filtering?
Server networks, because servers need only a short, predictable list of outbound destinations.
Name two protocols that should almost always be blocked outbound from user networks.
SMB (445) and SMTP (25), plus direct DNS to outside servers.

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.
Tracks your learning on this device only. See your progress on the learning paths.
Verified author✓ Valid
Issued to
Mohamed Fayas
Role
Founder of FM TecHub
Credentials
CCNABTEC HND Network EngineeringBEng (Hons) Computer Networking & Cloud Security
Issuer
FM TecHub · fmtechub.com

He writes practical, plain-English guides on networking, security and cloud.

More about the author →

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.

Email updates: coming soon

New notes, tools and security news from FM TecHub by email, explained simply. Free. We're not collecting email addresses yet; see our privacy policy.

PortServiceStatus
SMTP/25Email updatesopening soon

Meanwhile, stay connected: