Disable or enable windows firewall on cmd

Hello everyone, I’m going to share a few efficient commands for windows or server operating systems in this article. This article name is how to disable or enable windows firewall on cmd.

How to disable or enable windows firewall on cmd

Disable or enable windows firewall on cmd
Disable or enable windows firewall on cmd

Windows firewall can be enabled/disabled from the command line using the command netsh.

Let’s see the syntax of netsh advfirewall to configure the firewall on these Windows versions.  Firewall settings are different for each of the 3 networks (Domain, private, public). So based on which network firewall you want to enable/disable, the command would vary.

1. Windows 10 / Windows 8/ Windows 7 / Server 2008,2012,2016 /Vista:

You can turn on fthe irewall for the current network profile(does not matter if it’s domain/private/public network) using the below command.

netsh advfirewall set currentprofile state on

Turn off the firewall for the current profile:

netsh advfirewall set  currentprofile state off

These commands should be run from an elevated administrator command prompt. Otherwise, you would get the below error.

C:\>netsh advfirewall set  currentprofile state on
The requested operation requires elevation (Run as administrator).

To enable/disable firewall for a specific network profile, you can use the below commands.

2. Domain network

Turn on Domain network firewall:

netsh advfirewall set domainprofile state on

Turn off domain network firewall:

netsh advfirewall set domainprofile state off

3. Private network

Turn on private network firewall:

netsh advfirewall set privateprofile state on

Turn off private network firewall:

netsh advfirewall set privateprofile state off

4. Public network

Turn on public network firewall:

netsh advfirewall set publicprofile state on

Turn off public network firewall:

netsh advfirewall set publicprofile state off

5. Configure for all networks

Turn on the firewall for all networks

netsh advfirewall set allprofiles state on

Turn off the firewall for all networks

netsh advfirewall set  allprofiles state off

6. Older Windows versions – XP / Server 2003:

Below is the command to turn on the firewall.

netsh firewall set opmode mode=ENABLE

The command to turn off the firewall is:

netsh firewall set opmode mode=DISABLE

Administrator privileges are required to configure the firewall so above command can be run only from admin accounts.

netsh firewall is deprecated in new versions.

In Windows 10/ 8 / 7 / Vista/ Server 2008, ‘netsh firewall‘ command prints message like below.

c:\>netsh firewall set opmode mode=ENABLE
IMPORTANT: "netsh firewall" is deprecated;
use "netsh advfirewall firewall" instead. Though the command still works,
 it's preferable to use the new set of commands provided with netsh command.

Thanks for reading the article.

See you later in another article.

Hasan

Sources: https://support.microsoft.com/en-us/help/947709/how-to-use-the-netsh-advfirewall-firewall-context-instead-of-the-netsh

Published by Hasan Altin

I don't see any difference between the one who doesn't share its knowledge or the one who doesn't share its bread.

Leave a Reply

Your email address will not be published. Required fields are marked *