How to Configure the Firewall on Windows Server 2019

Windows Server 2019 contains a firewall program called Windows Defender Firewall with Advanced Security. The firewall filters incoming and outgoing traffic on your Windows Server 2019 instance to safeguard it from common network attacks. By default, the firewall is configured to allow access to all pre-installed system programs.

However, several programs may use multiple different ports for operation, and these will be automatically blocked because they don’t match with the rules in your firewall configuration. In this case, you need to open the specific port on Windows Server.

Prerequisites #

  • Deploy a Windows Server 2019 Instance on VPS
  • A Remote Desktop Connection App

Establish a connection to your server by logging in through any remote desktop app or click the console on your VPS dashboard to access your server. After you connect you can start configuring your Windows server 2019 firewall rules.

Turn Windows Firewall ON #

By default, Windows Defender Firewall is turned on, but in any case, you should confirm the current status and turn on firewall. To do this, click the tools node under server manager and select Windows Defender Firewall with Advanced Security from the drop down list.

From the open group policy management window, check the current status of Windows Firewall profiles if it is set to ON; otherwise, click the Windows Defender Firewall properties option and turn the service on per profile.

Firewall Rules #

Windows Firewall rules allow you to either permit or block specific incoming and outgoing network packets on your server. You can choose multiple parameters for each inbound or outbound rule. A rule can consist of a TCP or UDP port, program name, service, or a protocol to filter for every server profile.

Windows server profiles are grouped into, Domain, Private and Public. Domain represents your server’s connection to a corporate domain network, Private applies to your home or workplace network connection, and Public represents non-secure public network locations.

Open an Inbound Port (Incoming connections) #

Launch windows defender firewall from the tools sub-menu under server manager. Then, select Inbound Rules on the left panel of the Firewall console.

A list of current rules will be displayed. Now, on the left Inbound Rules sub-menu under actions, click New Rule

Select Port as the rule type in the rule wizard and click Next.

Now, choose whether the new rule applies to a TCP or UDP port on your server. Then, select Specific porrts and enter your target port number, you can enter a ports range, or multiple ports separated byand , respectively, then click Next.

Define your TCP or UDP port rule.

  • Allow the connection will allow incoming connections to the specified server port
  • Allow the connection if it is secure will authenticate with IP security and either deny or allow the connection. For example, https connections will be allowed and http blocked.
  • Block the connection will block all incoming connections to your server through the specified port

In this case, choose to Allow the connection to open the port.

Click Next to assign the new rule to one or more profiles. You can select between Domain, Private, and Public, or choose all to apply the firewall rule on multiple profiles.

Next, give your new firewall rule a custom name and description for easy identification. Then, Click finish to enable the new rule. Your new Inbound (Incoming) port rule will be enabled, and all connections to the server that match the port will be accepted.

Open an Outbound Port (Outgoing connection) #

From the Windows Defender Firewall console, click Outbound Rules on the left pane, and a list of available outgoing connection rules will be displayed.

Now, click New Role on the right pane under the outbound rules node.

In the new outbound rule wizard, select Port as the rule type and click Next.

Now, let’s choose whether the new rule applies to a TCP or UDP port. Then, select specific remote ports and enter the target server port number; you can enter a range of ports, a single port, or multiple different ports you intend to open.

Next, on the Action page, select Allow the connection, then click next to select the server profile on which the rule should be enabled.

Give the new outbound rule a name and description that uniquely describes it. Then, click Finish to enable the outbound rule for the target port to be open on all selected server profiles.

Open a Port through Windows PowerShell #

From the Windows start menu, open PowerShell. Then, edit the following command and replace it with your settings.

New-NetFirewallRule  -Enabled:True  -LocalPort 21  -Protocol TCP  -Direction Inbound  -Profile Domain  -Action Allow  -DisplayName example opening a port rule"  
  • New-NetFirewallRule : Creates a new Firewall rule.
  • Enabled : This enables the new rule, by default, it will be set to True.
  • LocalPort  : Your target port number.
  • Protocol  : Specifies the protocol associated with your port number.
  • Direction  : Sets your target direction to either Inbound (Incoming) or Outbound (Outgoing).
  • Profile  : Assigns the new rule to a server profile; you can choose domain, private, or public.
  • Action  : defines the state for the new firewall rule, enter allow.
  • DisplayName  : sets a custom name for the new firewall rule

Your Output should be similar to the one below.

PS C:\Users\Administrator> New-NetFirewallRule  -Enabled:True  -LocalPort 21  -Protocol TCP  -Direction Inbound  -Profile Domain  -Action Allow  -DisplayName "example opening a port rule"
Name                  : {427a1b12-ece6-4d54-847d-de482b227c6c}
DisplayName           : example opening a port rule
Description           :
DisplayGroup          :
Group                 :
Enabled               : True
Profile               : Domain
Platform              : {}
Direction             : Inbound
Action                : Allow
EdgeTraversalPolicy   : Block
LooseSourceMapping    : False
LocalOnlyMapping      : False
Owner                 :
PrimaryStatus         : OK
Status                : The rule was parsed successfully from the store. (65536)
EnforcementStatus     : NotApplicable
PolicyStoreSource     : PersistentStore
PolicyStoreSourceType : Local

Congratulations, you just opened a network port on your Windows Server 2019. The server will accept incoming and outgoing connections through the selected ports, but the firewall will block connections from a profile that doesn’t match the port rule.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.