Enable/disable firewall from command line

by admin on April 17, 2011

We can enable or disable Windows firewall from command line using netsh command. The commands are different for XP and Vista/Windows 7.

XP / Server 2003:

Below is the command to turn on firewall.

netsh firewall set opmode mode=ENABLE

The command to turn off firewall is:

netsh firewall set opmode mode=DISABLE

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

Vista / Windows 7 / Server 2008:

 ”netsh firewall”  is deprecated

In Vista / Windows7 / Server 2008, ‘netsh firewall‘ command prints the below message.

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.

Let’s see the syntax of netsh advfirewall to configure firewall on these Windows editions.  In these editions, 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.

You can turn on firewall 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 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.

Turn on Domain network firewall:

netsh advfirewall set domainprofile state on

Turn off domain network firewall:

netsh advfirewall set domainprofile state off

Turn on private network firewall:

netsh advfirewall set privateprofile state on

Turn off private network firewall:

netsh advfirewall set privateprofile state off

Turn on public network firewall:

netsh advfirewall set publicprofile state on

Turn on public network firewall:

netsh advfirewall set publicprofile state off

Turn on firewall for all networks:

netsh advfirewall set  allprofiles state on

Turn off firewall for all networks

netsh advfirewall set  allprofiles state off

Related Posts:
How to turn off firewall in Windows 7

{ 0 comments… add one now }

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: