Geo Firewall configuration for Microsoft Exchange Server
This article covers the following on-premises email servers:
- Microsoft Exchange Server Subscription Edition (SE)
- Microsoft Exchange Server 2019
- Microsoft Exchange Server 2016
- Hybrid deployments of these versions with Microsoft 365 / Exchange Online Protection (EOP)
This article describes how to configure Geo Firewall 2027 on a Windows server running on-premises Microsoft Exchange Server so that inbound mail keeps arriving from the whole world, while client and administrative entry points are reachable only from the territories where your users actually are. The steps use the Geo Firewall 2027 rules model (Default Rule and Port Rules). Geo Firewall v4 uses a different model (Port Exceptions). For v4, see Geo Firewall v4 configuration for 3CX PBX with NGINX and Geo Firewall v4 exclusion of traffic from blocking.
If you run hMailServer, MailEnable, or SmarterMail, see Geo Firewall configuration for hMailServer, MailEnable, and SmarterMail. If you run MDaemon, Kerio Connect, IceWarp, or Axigen, see Geo Firewall configuration for MDaemon, Kerio Connect, IceWarp, and Axigen.
Why geo-restrict an Exchange server
An internet-facing Exchange server exposes a large pre-authentication surface on TCP port 443. Outlook on the web (OWA), the Exchange admin center (EAC at /ecp), Exchange Web Services (EWS), Exchange ActiveSync, MAPI over HTTP, offline address book (OAB) distribution, and Autodiscover all share that single port. That surface was at the center of the 2021 mass-exploitation waves against on-premises Exchange. The ProxyLogon zero-day chain (CVE-2021-26855 and related CVEs) began with untrusted connections to port 443, and CISA urged emergency action against the ProxyShell vulnerabilities the same year. Exposed OWA, ActiveSync, and authenticated SMTP are also standing targets for password spraying, and Microsoft's own password-spray playbook notes that most such attacks use legacy authentication protocols and that low-and-slow, distributed sprays stay under rate-based lockout thresholds.
Restricting which territories can reach those entry points does not replace patching or multi-factor authentication, and a determined attacker can route through a VPN in an allowed country. What geographic restriction does is eliminate the automated scanning and opportunistic login noise from regions where your organization has no users, and it shrinks the population of hosts that can even attempt the next zero-day against your server. This matters even more for Exchange Server 2019 and 2016, whose Microsoft support ended on October 14, 2025. Servers that no longer receive regular security fixes benefit most from a smaller exposed surface while a migration to Exchange Server SE or Microsoft 365 is completed.
What Exchange exposes to the internet
The port surface below is from Microsoft's Network ports for clients and mail flow in Exchange (applies to Exchange 2016, 2019, and SE). Note that Microsoft does not support restricting traffic between internal Exchange servers or between Exchange and Active Directory domain controllers. Geographic rules belong on the internet-facing boundary, which is exactly what the host-based rules below implement.
| Purpose | TCP port | Notes |
| Inbound mail from the internet (SMTP) | 25 | "Default Frontend" Receive connector accepts anonymous SMTP from any sender's mail server. |
| Authenticated client submission (SMTP) | 587 | "Client Frontend" Receive connector. Port 465 is not part of the documented on-premises defaults. |
| OWA, EAC (/ecp), EWS, ActiveSync, MAPI over HTTP, Outlook Anywhere, OAB, Autodiscover | 443 | All HTTPS client services are consolidated on one port. The EAC has no separate port. Its external URL is unconfigured by default. |
| HTTP redirect / fallback | 80 | Redirects to 443. It is also used for internet calendar publishing. |
| POP3 / secure POP3 | 110 / 995 | Disabled by default in Exchange. |
| IMAP4 / secure IMAP4 | 143 / 993 | Disabled by default in Exchange. |
| Outbound delivery + DNS | 25 out, 53 out | The server connects out to remote port 25 to deliver mail and performs DNS lookups for MX resolution. |
How Geo Firewall 2027 rules apply here
Three behaviors of the Geo Firewall 2027 rules model make the whole configuration:
- The Default Rule (Rules tab -> Default Rule) is the whole-server baseline. Its per-territory Incoming/Outgoing actions apply to any traffic no other rule decides.
- A Port Rule (Rules tab -> Port Rules) takes precedence over the Default Rule for the ports it matches, but only for territories explicitly set to Allowed or Blocked in that rule. Territories left Unaffected in a Port Rule fall through to the Default Rule. This is what lets port 25 stay open to the world while the same countries are blocked everywhere else.
- The Whitelist (Tools -> Settings... -> Policy -> Whitelist) has the highest precedence of all rules. Entries there stay reachable regardless of any Block below. That is where management addresses and Microsoft 365 / EOP ranges belong.
- Every rule's Actions tree also contains the [Private Networks IPv4] and [Private Networks IPv6] groups (the RFC 1918 and similar local ranges), the [Unknown Networks] group (its entry Unknown geography (catch-all)) for addresses the database cannot place, and any user-defined networks. Set Incoming/Outgoing Action for All applies to the [Unknown Networks] group and the user-defined networks too (it is the icon on the toolbar above the tree, and each click sets all the territories and networks it covers to the next action in the order Unaffected, Blocked, Allowed, so "-> Blocked" in the steps below means that you click it until it shows Blocked). By default it leaves the two Private Networks groups as they are (Settings -> User Interface -> Set Action for All).
Geo Firewall tracks connections directionally. When a connection starts in an allowed direction, the reply traffic for that connection is allowed automatically. Outbound mail delivery therefore only needs the outgoing direction open, and the SMTP responses come back on the same connection.
Before you begin
- Protect your own access first. Add your management workstation or VPN egress IP to Tools -> Settings... -> Policy -> Whitelist -> IPv4 networks. On cloud VMs, Geo Firewall shows the Remote Access Lockout Prevention dialog at first start and offers to add the address of the connected Remote Desktop user to the whitelist. Click OK, then keep the pre-added entry and close the Settings window with OK. If RDP access is ever lost on an Azure VM, see Restoring Remote Desktop (RDP) connectivity to an Azure VM after a user lockout.
- Keep "Automatically whitelist DNS Servers..." enabled (Settings -> Policy -> Whitelist). Exchange resolves MX records constantly, and blocking the configured DNS servers stops mail flow.
- Update the geographical database (Networks & Geography -> Geo Database -> Pull and Build) so territory mappings are current.
Step 1 — Keep inbound SMTP (port 25) open worldwide
Legitimate mail servers anywhere in the world deliver to your MX host on TCP port 25, so blocking countries there means losing their mail, not just their attacks.
- On the Rules tab, open Port Rules and click New.
- On the Filter tab: Title = "SMTP inbound mail", Protocol = TCP, Port Endpoint = Local, and add port 25 to the Ports list.
- On the Actions tab, use Set Incoming Action for All -> Allowed. Leave Outgoing unaffected.
- Click Apply.
If your organization has a policy of not accepting mail from specific countries, set those territories to Blocked in this rule instead of Allowed. This Port Rule is where mail-acceptance geography lives from now on.
Step 2 — Set the baseline in the Default Rule
On the Rules tab, select Default Rule and set the Incoming action to Blocked for the territories your organization has no business with (or, for a strict allow-list posture, use Set Incoming Action for All -> Blocked and then set your operating countries back to Allowed. Set the [Private Networks IPv4] / [Private Networks IPv6] groups to Allowed as well, and the country allow-list guide compares the two postures). Decide the [Unknown Networks] entry deliberately. It covers IP addresses whose territory the database cannot determine. Click Apply on the Default Rule tab.
On its own, this baseline would also block inbound mail from those territories on port 25. The Port Rule from Step 1 keeps mail delivery open worldwide.
Step 3 — Geo-restrict the HTTPS surface (OWA, EAC, EWS, ActiveSync, Autodiscover)
- Create a second Port Rule titled "Exchange HTTPS".
- Filter: Protocol = TCP, Port Endpoint = Local, ports 443 and 80 (two entries).
- Actions: use Set Incoming Action for All -> Blocked, then set the territories where your users live and travel to Allowed, and set [Private Networks IPv4] / [Private Networks IPv6] to Allowed so office-network clients keep reaching OWA.
- Click Apply.
Because every HTTPS client service shares port 443, this one rule restricts OWA, the EAC, EWS, ActiveSync, MAPI over HTTP, OAB, and Autodiscover together. Port-level rules cannot separate them. Plan the allowed-territory list around roaming users. A traveling employee's phone syncs via ActiveSync and Autodiscover from wherever they are, so either include expected travel destinations or have travelers connect through the corporate VPN. In hybrid deployments, complete Step 5 before applying blocks on 443, since Exchange Online also calls these endpoints.
If POP3 or IMAP4 are enabled on your server (they are off by default), give them the same treatment. Add port 587 (authenticated client submission) to the Step 3 rule as its third entry, and create one Port Rule for POP3 (110, 995) and one for IMAP4 (143, 993) with the same actions. These are pure client protocols, so they never need to be reachable from territories without users.
Step 4 — Keep outbound delivery working
If the Default Rule from Step 2 blocks Outgoing traffic to some territories, your server cannot deliver mail to recipients there (it connects out to their MX hosts on remote port 25). Either keep Outgoing unaffected/allowed in the Default Rule for territories you send mail to, or create a Port Rule with Port Endpoint = Remote, port 25, and Set Outgoing Action for All -> Allowed. Replies to those connections are allowed automatically by the direction-aware connection tracking.
Step 5 — Whitelist the Microsoft 365 ranges (hybrid and EOP)
In a hybrid deployment or whenever inbound mail routes through Exchange Online Protection, connections from Microsoft to your server (SMTP on 25, plus EWS/Autodiscover on 443 for free/busy and mailbox migrations) originate from Microsoft's published ranges. Add them at Tools -> Settings... -> Policy -> Whitelist (tabs IPv4 networks and IPv6 networks):
- IPv4: 40.92.0.0/15, 40.107.0.0/16, 52.100.0.0/14, 104.47.0.0/17
- IPv6: 2a01:111:f400::/48, 2a01:111:f403::/48
These are the "Exchange Online" mail-flow ranges from Microsoft's Microsoft 365 URLs and IP address ranges document. Microsoft updates that list monthly with 30 days notice. Treat the document (or its web service) as the source of truth and re-check it when Microsoft announces changes, rather than treating the ranges above as permanent.
Step 6 (optional, strict) — Accept SMTP only from your cloud filter
When all inbound mail flows through EOP or a third-party filtering service (the same pattern applies to services such as Proofpoint, Mimecast, or Barracuda using their published delivery ranges), port 25 does not need to be open to the world at all:
- Add each of the filter's delivery ranges as a user-defined network. Open the Networks & Geography tab -> User-Defined Networks -> IPv4 (or IPv6). Type the range's address in IP and its width in mask, click Add for each range, then Apply.
- In the Step 1 Port Rule, use Set Incoming Action for All -> Blocked, then expand [User-Defined IP Networks] and set those ranges' Incoming action to Allowed. A user-defined network decides only for addresses where it is the narrowest matching network (the editor's hint says "The greater the mask the higher its priority"). Check a few of the filter's addresses with Tools -> IP Geo Lookup, where the first (bold) network in the list is the narrowest matching one. If a territory of the database is listed first, add the filter's ranges to the Whitelist instead, as in Step 5. Keep [Private Networks IPv4] / [Private Networks IPv6] on Allowed if internal devices or applications submit mail to the server on port 25.
With this posture, direct-to-MX delivery attempts (a common spam and reconnaissance path that bypasses cloud filtering) are dropped at the packet level before Exchange ever sees the connection.
Step 7 — Verify and monitor
- Use Tools -> IP Geo Lookup to confirm which territory a given address resolves to, including your own management addresses and a few known sender addresses.
- Watch the Log tab. Records show the territory and whether it was allowed or blocked. On the Ultimate edition they also show the triggering rule, and the context menu Go to Triggered Rule navigates straight to it. The Statistics tab shows allowed-versus-blocked packets per territory (Geo) and per IP (IP), plus per process (Process) on the Ultimate edition.
- For long-term evidence, enable the file log, or on the Ultimate edition stream events into Event Tracing for Windows for SIEM collection. See SIEM & ETW traffic logging.
- When the rule set is final, turn on Tools -> Read Only Policy Mode, and export a backup of the policy (File -> Export Policy..., a .vgf file) so the configuration can be restored or replicated on another Exchange server.
What Exchange provides natively, and what this adds
On-premises Exchange has no built-in geographic blocking. Its connection filtering exists only on the Edge Transport role and matches literal IP addresses, ranges, and DNS blocklists. IIS's dynamic IP restrictions are rate-based per address. Windows Firewall scopes rules to explicit addresses and subnets without any IP-to-country database. Geo Firewall supplies the geography dimension at the network-driver level, below Exchange and IIS, and its blocking covers every service on the host, including RDP and anything else the server exposes alongside Exchange (see RDP brute-force protection).
Last updated: November 20, 2026.
Shopping Cart