Chapter 4
IN THIS CHAPTER
Understanding the Basics of the Windows Defender Firewall
Configuring and Managing the Windows Defender Firewall in Windows Server 2019
There are few things more basic to security than the principle of keeping bad things out and letting good things in. You may choose to block or restrict inbound traffic from risky protocols or port numbers. You might even lock down outbound traffic to only approved protocols and port numbers. Defining the acceptable forms of inbound and outbound traffic is typically accomplished with the Windows Defender Firewall.
In this chapter, I introduce you to the Windows Defender Firewall, including the configuration and usage tasks that every System Administrator should know.
The Windows Defender Firewall is a stateful firewall. This means that you can create a rule to allow inbound traffic, and established traffic will automatically be let back out. If you create an outbound rule, traffic going out will automatically be allowed back in. It can inspect all traffic passing through it and track the state of the connection. This is a great improvement over the older, traditional firewalls, referred to as stateless firewalls, for which you had to create a rule to allow traffic in both directions in an access control list. Stateless firewalls do not inspect traffic; they only allow or block based on source and destination IP addresses or ports.
The Windows Defender Firewall, like most of the firewalls out there, operates on a default deny for inbound connections. Essentially, if there is not a rule allowing traffic in, then it will be blocked. Outbound connections are typically allowed by default.
The Windows Defender Firewall uses profiles to define trust levels of network traffic. The profiles can be assigned to specific network adapters, though by default all the profiles are enabled for each network adapter. As an example, the domain profile is used when a system is connected to a domain and will typically be more permissive than the public profile, which is designed to be used when a network adapter is connected to an untrusted network like the Internet.
The Windows Defender Firewall has three profiles:
When you’re troubleshooting connectivity issues, the typical request is, “Can we disable the firewall?” I can’t tell you how often I was asked to do this by a vendor when troubleshooting connectivity issues with their applications. Technically, it is possible to disable the Windows Defender Firewall, but you should check your organization’s policy as to whether you’re allowed to do so.
With that disclaimer out of the way, let’s look at how to disable and enable the Windows Defender Firewall. There are three ways to enable and disable the firewall. You can do it through the graphical user interface (GUI), through PowerShell, or through the command line.
Disabling the firewall through the GUI is definitely the longest process of the three. You can’t simply disable all at once; instead, you have to turn it off for each individual profile.
Here are the steps involved with turning off the firewall for the Domain profile (the steps are the same for the Public and Private profiles, just substitute the desired profile in Step 4):
Click Domain Network (Active).
If you don’t see a domain profile, it’s because the system is not connected to a domain. This profile does not show up unless the system is domain joined.
One of the methods to disable or enable the firewall is with PowerShell. It’s a simple one-line command to turn it off for all the Windows Defender Firewall profiles or to turn it off for a specific profile. Here’s the command to disable the firewall for all profiles:
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
To re-enable the firewall for all profiles, use the following:
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True
If you only want to disable/enable one of the profiles, you would use just that profile name instead of Domain,Public,Private
.
Disabling and enabling via the Command Prompt is a one-line command that can be used to disable or enable all or specific profiles. Here's how to disable the firewall for all profiles:
netsh advfirewall set allprofiles state off
To re-enable the firewall for all profiles, use the following:
netsh advfirewall set allprofiles state on
If you only want to disable/enable one of the profiles, you would use just that profile name (domain
, public
, or private
) instead of allprofiles
.
To configure Windows Defender Firewall, you need to get into the Advanced Settings. Follow these steps:
The Advanced Settings screen looks familiar if you’ve worked with Windows Defender Firewall in the past. It shows you, at a glance, which profiles are enabled, as well as a basic overview of what kind of blocking state the firewall is in (see Figure 4-3).
The left side of the screen give you several options:
For most people, the default profile settings work well. But what if you work for an employer who wants to be very strict about outbound connections not allowing traffic out unless it’s explicitly allowed? You can change the behavior of the profile.
From inside the Advanced Settings screen, right-click Windows Defender Firewall with Advanced Security and select Properties. You see tabs for each of the profiles and a tab for IPSec. Start with the tab for the Public Profile, shown in Figure 4-4.
There are a few settings that I want to call your attention to:
Inbound Connections: You have three options here:
The default setting for this is Block.
Outbound Connections: You have two options:
The default setting for this is Allow.
As you can probably tell, you can get very specific in terms of how you want a profile to behave and where you want that profile to apply to.
Windows Server 2019 has quite a few firewall rules already created for you. The ones that are essential to the server to allow it to function properly are already enabled. Rules that support core networking functions and file and print sharing are great examples of that. When you install new roles and features, the firewall rules for these roles and features are automatically enabled as well.
Enabling the prebuilt rules is very simple: Simply right-click the rule that you want to enable and choose Enable Rule, as shown in Figure 4-5.
To disable the rule, simply right-click it and choose Disable Rule.
The prebuilt rules are convenient, but they tend to be very specific to Microsoft services. What if you need to install a vendor product with specific port needs?
Let’s create a rule from a use case: You’re a system administrator, and you’ve been asked to allow inbound connections to a domain-connected system hosting a MySQL database. You know that MySQL needs TCP port 3306, so let’s create a rule to allow this traffic:
In Figure 4-6, you can see the rule that I created at the top. You can tell that it’s already enabled because it has the green check mark beside it.
I can hear the voice inside your head saying, “That was easy, but where is the granularity?” You can get exceptionally granular on the rule. Let’s take a peek at the settings. Double-click a rule. I’ll use the MySQL rule that I just created.
There are eight tabs in all. Each tab allows for you to make a change to the rule. Some of the settings are the basic stuff that you set when you initially created the rule; others allow for more granularity than what was inside the rule wizard:
Protocols and Ports: The Protocols and Ports tab allows more depth than the wizard does when Port is selected. When I created the rule, I had the choice between TCP and UDP because I chose a Port rule. On this screen, however, I have many more options, shown in Figure 4-7. I could get these through the wizard if I chose Custom instead of Port.
I can change the local and remote ports on this tab as well. Currently, in my rule, I have TCP 3306 allowed.
You could have made all these settings through the wizard if you had selected Custom instead of Port. I like to take you through the exercise of looking at the individual tabs, though, because I’ve met quite a few system administrators who don’t understand what the tabs mean or how to edit the rule properly after it’s created.
IP Security (IPSec) is used to secure communications over an IP-based network. It’s typically set up to support and secure network-to-network, host-to-host, or host-to-network communication. For businesses that deal with sensitive information, IPSec provides a method to encrypt data while it’s in transit. There are a few terms you should understand when talking about IPSec:
The IPSec tunnel can be configured through the Connection Security Rules section in Windows Defender Firewall. For this section, I’m going to create a server-to-server tunnel.
On the Endpoints screen, define which endpoints will meet the criteria for the tunnel, and click Next.
I’m going to leave both of these on Any IP Address. In a production environment, you would want this to be more specific.
On the Requirements screen, you can select whether you want to request or require authentication, and click Next.
I’ll leave it on Request Authentication for Inbound and Outbound Connections.
On the Authentication Method screen, you can select Computer Certificate if you have an internal public key infrastructure (PKI) that can support this use.
I’ll click Advanced, and then click Customize.
Now you have the connection security rule finished. This needs to be set up on any system on which you want to use IPSec. As an example, I set it up on one of my other systems and the SA came up for it right away, as shown in Figure 4-9.