Foreword
In this guide, we will install an Exchange Server 2019 with the latest CU15 and configure it as securely as possible. We will create our own WAF rules on the Sophos XG and configure functions such as SPF, DMARC, DKIM and more.
Prerequisites
- Active Directory
- In possession of your own domain
- Optional: DMZ domain (recommended, but not mandatory, significantly higher management effort)
- Separate VLAN/network
- Optional, but recommended: Separate zone (e.g. “EXCH”) on the Sophos
- Wildcard certificate for your own domain (Can be mapped with Let’s Encrypt, but it’s better to buy a certificate for 1 year. I bought mine from https://www.ssl2buy.com/ for example. Costs only 42$ for 1 year).
Preparation of the VM
For our small environment, 16GB RAM is sufficient for the Exchange Server. Microsoft officially recommends 128GB RAM for Exchange Server 2019.
After a lot of research, I decided on the following constellation:
- One hard disk for the operating system (36GB)
- One hard disk for the Windows swap file (17GB)
- One hard disk for the Exchange (82GB)
You may be wondering why the second hard disk for the swap file has 17GB. This is for the following reason: The VM gets 16GB RAM. 10MB should be used as an additional buffer. This results in the following calculation: 16 x 1024 + 10 = 16394MB RAM. However, as the formatting also results in a loss of storage space, the disk has to be slightly larger. I then decided on 17GB.
Please install the server in a separate VLAN and select the NIC accordingly during installation.
Installation of the OS
As there have been problems in the past regarding the installed language for updates, I generally recommend installing all servers in English. Otherwise, error messages are often poorly translated and not easy to find on the Internet.
You can then adjust the time and currency format to your country accordingly.
In this guide, I am following Microsoft’s best practice guidelines and best practices. According to Microsoft, a headless Windows server is recommended for Exchange Server 2019 - i.e. a server without a GUI. This is what we will do in this guide. When installing the Windows Server, select the top option “Windows Server 2025 Standard” for this reason.
For the operating system, we select the hard disk with 36GB.
Basic configuration of the Windows server
Configure IP, join domain, etc.
A password must be set after installation. We then log on to the server. After logging in, we are greeted with the following image. We can navigate through the various menus using the numbers.
You now name your server properly, add it to the domain, assign it a static IP address with DNS server, adjust the time/time zone if necessary and restart it. I think the steps are self-explanatory. It should look like that in the end.
Install VMware Tools
In addition, the VMware Tools should now be installed. As always, you mount these via the vCenter. We can then change to the directory in which the ISO was mounted. For me it was D:. Then simply run the setup.exe.
Then simply click through the setup (in my case it is now in German on the screenshots).
The server must be restarted after installation.
Configure Disks
Initialize Disks
In the sconfig menu, we select the number 15 to switch to Powershell. With the command “Get-Disk” we can display all hard disks.
|
|
Disk 0 is our OS disk.
With the command “Initialize-Disk -Number 1” we can initialize the hard disk with the ID 1.
|
|
We have to do the same for the hard disk with ID 2.
|
|
Parition Disks
We now partition the hard disks. We can partition the hard disks with the “New-Partition” command. I give the disk with 17GB, i.e. the disk for our swap file, the drive letter F.
|
|
We now have to do the same for the other hard disk. I give it the drive letter E for Exchange.
|
|
We can now check everything with the “Get-Partition” command.
|
|
Format Disks
Now we have to format the partitions with NTFS. This can be done with the “Format-Volume” command.
|
|
Do the same for the other partition.
|
|
Configure Swap File
We enter “cmd” to open the command prompt.
We disable the automatic page file.
|
|
We delete the current page file.
|
|
We create a new page file on our dedicated page file drive.
|
|
We adjust the size of the page file.
|
|
We check the settings we have made.
|
|
Preparation for Exchange installation
Install needed Features
Open Powershell on your server and install the following prerequisites.
|
|
This can take some minutes to complete.
It should display “Success” when it’s done.
Install VCRedist 2012
Enter the following command to download VCRedist C++ 2012 in x64.
|
|
Run the setup and just install it.
|
|
Install VCRedist 2013
Enter the following command to download VCRedist C++ 2013 in x64.
|
|
Run the setup and just install it.
|
|
Install IIS-Rewrite
Enter the following command to download IIS-Rewrite.
|
|
Run the setup and just install it.
|
|
Download Exchange 2019 ISO
Enter the following command to download Exchange 2019 CU15.
|
|
Mount the ISO
|
|
Install UCMARedist
The UCMARedist setup is located on the Exchange ISO. In my case, the ISO was mounted with the letter G. I change the directory to G: and then to the “UCMARedist” folder. In this folder we simply execute the Setup.exe.
|
|
Install Exchange
Create Folders
Before the actual Exchange installation, we now create three folders on the hard disk intended for the Exchange, in my case drive E. This can be done with the mkdir command.
We create a folder with the name “Exchange”.
|
|
We create a folder with the name “Database”.
|
|
We create a folder with the name “Logs”.
|
|
It should look like this.
Run the setup
Now we switch back to the drive with the mounted Exchange ISO. Here we now start the Exchange installation.
Change the “Organization Name” accordingly. Keep quotation marks.
|
|
The setup will start.
This will take around 15-20 minutes on SSD/NVMe.
It should look like this when the setup is finished. We need to reboot the server now.
Test OWA and ECP
OWA and ECP should now be accessible after the reboot.
OWA
OWA can be accessed at https://fqdn.of.your.server/owa.
ECP
ECP can be accessed at https://fqdn.of.your.server/ecp.
DNS Records
A-Record, MX-Record, SRV-Record
We will now configure DNS records. In my case, my domain is with Cloudflare. But it should actually be similar for other providers.
Login to cloudflare and click on your domain.
You should be here now. Click on “DNS” in the left-hand menu.
And then on “Records”.
Click on “Add record” and select “A” as the record type. Now enter a name for the A-Record under which your mail server should be accessible. A common name is “mail”. This is also the name I choose in my case. The IPv4 address field is self-explanatory.
Create another A-Record with the name “autodiscover”.
Create another record but select “MX” as the type. Enter “@” for the name and enter the previously created A-record for your mail server in the “Mail server” field. Select one hour for the TTL and 10 for the priority.
Create another record but select “SRV” as the type. You must enter the following in the “Name” field:
|
|
The target is again your previously created A-Record for your mail server. You can copy the other settings from the screenshot.
RDNS Configuration
You must now configure the reverse DNS entry with your server host. Please check whether your server provider has this option. My servers are at Hetzner, where this is configurable.
In my case, I change the reverse DNS entry for the IP address 144.76.105.35 to “mail.nobrac.ch”.
Renaming and moving the mailbox database and the log directory
Open Powershell on your Exchange Server and enter “LaunchEMS” to start the Exchange Management Console.
|
|
I call my mailbox database “MBXDB01”. You can call it whatever you like. Hostname of the server must of course be adapted to yours.
|
|
We then move the database and the log directory to the dedicated folders we created previously.
|
|
Confirm the prompts with “Y”.
Exchange Configuration
Open your ECP and login.
Log in with the domain administrator. When you log in for the first time, you must configure the language and time zone.
You should see the following page after the login.
Configure “Accepted Domains”
Select “mail flow” in the menu on the left and then click on “accepted domains” at the top of the bar.
Then click on the plus symbol. The following window opens. We then assign any name here. It is best to enter the name of your domain here. We then also enter our domain in the “Accepted domains” field. We select “Authoritative” in the lower selection and click on “Save”.
It should look like this.
Configure “E-Mail Address Policy”
In the top menu bar, click on “email address policies”. You should be here.
Click again on the plus symbol. Enter a name for your policy.
Then click again on the plus next to “Email address format”. Select the accepted domain that you created in the previous step. In my case, I select “alias@contoso.com” for the e-mail address format. This is name.surname@domain.com. Make sure that “Make this format the reply email address” is checked.
It should look like this. Click on save.
You will receive a warning that the policy is not yet active. Simply confirm.
The overview should now look like this.
On the right side we see the status “Not Applied”. Here we now click on “Apply”. We receive another warning, which we simply confirm.
Click on close when it’s done.
Configure “Send Connectors”
In the top menu bar, click on “send connectors”. You should be here. Click on the plus symbol.
Enter a name of your choice. In my case, I use “Route-To-Internet”. We select “Internet” as the type.
In this guide we will guide the mailflow through our Sophos XG Firewall. For this reason, we select the option “Route mail through smart hosts” in the “Network settings”.
Then click on the plus symbol again and enter the IP of the gateway of the Exchange Server VLAN as the smart host.
It should look like this.
We don’t need authentication, so just click on next.
Click on the plus symbol for the “Address space” option.
Simply copy all the options from the screenshot.
It should look like this.
For the “Source server” option, click on the plus symbol again.
Select your Exchange Server and click on “Add”.
It should look like this. Click on finish.
The newly created send connector should now be displayed in the overview.
We select the entry and click on the pencil icon to edit the entry. The following window opens.
Click on “scoping” in the left bar and scroll all the way down. Enter the address of your mail server in the “FQDN” field.
Configuration “Virtual Directories”
Open notepad.exe on your Exchange server.
Paste the following into the document. The following variables must be adjusted:
- $servername
- $internalhostname
- $externalhostname
- $autodiscoverhostname
It is recommended by Microsoft that the internal and external hostnames are identical.
|
|
It should look like this.
Then save the text document e.g. under drive E with a name of your choice. Make sure you save it as a .ps1 file as we want to run it with Powershell.
Open an Exchange Management Console with “LaunchEMS” if you don’t have one open.
Then change to the path where you saved the script and execute it.
|
|
It should then run through without any problems.
Configure Certificates
Back in ECP, we click on “servers” in the left-hand navigation bar and then on “certificates” in the top menu bar. The following overview page should be visible.
Now click on the symbol with the three dots and select “Import Exchange Certificate”.
The following window opens. Click on “Choose File” to select your certificate.
Select your certificate.
Also enter the password for the certificate.
Now click on the plus.
Select the Exchange server on which you want to install the certificate. Mark your Exchange and click on “Add”.
It should look like this.
We should then see our imported certificate on the overview page.
Bind Services
Select your imported certificate and click on the pencil icon to edit it.
The following window opens.
Click on “services” in the menu bar on the left.
Check the “SMTP” and “IIS” boxes.
Click on save and confirm the warning.
In the overview we can now see that the services “IIS” and “SMTP” are assigned to the certificate.
Open the Exchange Management Console on your Exchange server and enter the following commands for certificate POP and IMAP settings.
For POP:
|
|
For IMAP:
|
|
Back at the ECP, click again on the pencil icon to edit the certificate again.
Click on “services” again in the left menu.
Check the “IMAP” and “POP” boxes.
An error message appears stating that the certificate cannot be used and that we should configure the settings using the commands in Powershell. We have done this and the message can be ignored. This is a very old bug that has not yet been fixed. The POP and IMAP services are then also not displayed in the overview page for the certificate that the services are bound with the certificate. This is also normal (unfortunately).
Configure Receive Connectors
Select “mail flow” in the left menu bar and “receive connectors” in the top navigation bar. Select “Client Frontend” and then click on the pencil icon to edit it.
Click on “scoping” in the left menu bar and scroll all the way down. Change the FQDN accordingly. That’s it.
Configure Sophos XG
Enable SMTP-Relay for Zones
In your Sophos XG, navigate to “Administration” -> “Device Access” and activate the option “SMTP Relay” for your WAN zone and for the zone that you have created for your Exchange.
Create IP-Host
In your Sophos XG, navigate to “Hosts and Services” -> “IP host” and create a new host for your Exchange server.
Upload Certificate
In your Sophos XG, navigate to “Certificates” and upload your wildcard certificate.
Create Web Server
In your Sophos XG, navigate to “Web server” and click on “Add” to create a new object.
Assign a name, select your previously created Exchange host under “Host”. Select HTTPS for the “Type” and 443 as the “Port”. Set the “Time-out” option to 1850.
Create Protection Policies
Create Protection Policy for Autodiscover
In your Sophos XG, navigate to “Web server” -> “Protection policies”. There are ready-made protection policies for Exchange from Sophos, but these are extremely outdated. They are unusable.
Create a new protection policy and apply the settings from the screenshot.
“Entry URLs” to copy:
- /autodiscover
- /Autodiscover
“Skip filter rules” to copy:
- 960015
- 960911
Create Protection Policy for Webservices
Create another protection policy and apply the settings from the screenshot.
“Entry URLs” to copy:
- /ecp
- /ECP
- /ews
- /EWS
- /Microsoft-Server-ActiveSync
- /oab
- /OAB
- /owa
- /OWA
- /
- /mapi
- /MAPI
“Skip filter rules” to copy:
- 920420
- 920440
- 960010
- 960015
- 960018
- 960032
- 981176
We should then see our new two protection policies in the overview.
Create Firewall Rules
Firewall Rule for Webservices
In your Sophos XG, navigate to “Rules and policies” -> “Firewall rules”. Create a new firewall rule.
Under “Action”, select the option “Protect with web server protection”. The other settings can be taken from the screenshot. Make sure that you select your port with the public IP address for “Hosted address”. For the domain, enter your domain for your mail server. I have also created a dedicated group for WAF-Rules to make administration simpler.
Path-specific Routing
Under “Protected servers” -> “Path-specific routing”, click on the pencil icon to edit the entry. You can copy the settings from the screenshot. I have also entered a few countries directly under “Blocked countries”. This at least blocks all the bots.
It should look like that.
Exceptions
Click on “Add new exception” under “Exceptions”. Enter the following paths.
“Paths” to copy:
- /ews/*
- /EWS/*
- /Microsoft-Server-ActiveSync*
- /oab/*
- /OAB/*
- /owa/*
- /OWA/*
- /Microsoft-Server-ActiveSync
- /Microsoft-Server-ActiveSync?*
- /ecp/*
- /ECP/*
Check the options “Static URL hardening” and “Never change HTML during static URL hardening or form hardening”.
The overview should now look something like this.
Click again on “Add new exception”.
“Paths” to copy:
- /owa/ev.owa*
- /OWA/ev.owa*
Check the option “Antivirus”.
The overview should now look something like this.
Click once again on “Add new exception”.
“Paths” to copy:
- /rpc/*
- /RPC/*
- /mapi/*
- /MAPI/*
- /Rpc/*
Check all options except “Never change HTML during static URL hardening or form hardening” and “Accept unhardened form data”.
The overview should now look something like this.
Now select your previously created protection policy under “Advanced” in the “Protection” option. In addition, check the “Pass host header” option.
Firewall Rule for Autodiscover
In your Sophos XG, navigate to “Rules and policies” -> “Firewall rules”. Create another firewall rule.
Under “Action”, select the option “Protect with web server protection”. The other settings can be taken from the screenshot. Make sure that you select your port with the public IP address for “Hosted address”. For the domain, enter your “autodiscover” domain.
Path-specific Routing
Under “Protected servers” -> “Path-specific routing”, click on the pencil icon to edit the entry. You can copy the settings from the screenshot. I have also entered a few countries directly under “Blocked countries”. This at least blocks all the bots.
It should look like that.
Exceptions
Click on “Add new exception” under “Exceptions”. Enter the following paths.
“Paths” to copy:
- /autodiscover/*
- /Autodiscover/*
Check the options “Static URL hardening” and “Never change HTML during static URL hardening or form hardening”
It should look like this.
Now select your previously created protection policy under “Advanced” in the “Protection” option. In addition, check the “Pass host header” option.