Here are some examples of how to use the `netsh advfirewall mainmode delete rule` command:
Delete a rule by name:
This command deletes a firewall rule with the specified name from Windows Firewall with Advanced Security. This is useful for removing specific rules by name.
netsh advfirewall mainmode delete rule name="MyRule"
Delete a rule by program or service:
These commands allow you to delete firewall rules that target a specific program (by specifying the program file path) or service (by specifying the service name). This is useful for removing rules associated with specific applications or services.
netsh advfirewall mainmode delete rule program="C:\Program Files\MyApp\MyApp.exe"
netsh advfirewall mainmode delete rule servicename="MyService"
Delete a rule by port:
This command deletes a firewall rule based on a specific TCP port (port 8080 in this case). Clearing rules based on ports is important to control network communications.
netsh advfirewall mainmode delete rule protocol=TCP localport=8080
Delete a rule by direction:
These commands allow deleting firewall rules based on their communication direction. A rule can be set for incoming (IN) or outgoing (OUT) traffic.
netsh advfirewall mainmode delete rule name="MyRule" direction=IN
netsh advfirewall mainmode delete rule name="MyRule" direction=OUT
Delete a rule by interface type:
These commands allow clearing firewall rules based on the type of network interface (IPv4 or IPv6) over which traffic flows.
netsh advfirewall mainmode delete rule name="MyRule" interfacetype=V4
netsh advfirewall mainmode delete rule name="MyRule" interfacetype=V6
Delete a rule by profile type:
These commands allow deleting firewall rules based on network profile type (DOMAIN, PRIVATE, or PUBLIC). Deleting rules depending on the profile type is important to tailor security policies for different network scenarios.
netsh advfirewall mainmode delete rule name="MyRule" profile=DOMAIN
netsh advfirewall mainmode delete rule name="MyRule" profile=PRIVATE
netsh advfirewall mainmode delete rule name="MyRule" profile=PUBLIC
You can also use wildcards to delete multiple rules at once. For example, the following command deletes all rules that start with the name
"MyRule":
netsh advfirewall mainmode delete rule name="MyRule*"
Using wildcards allows multiple rules that match a specific pattern to be deleted efficiently. However, it is important to be careful with wildcards to avoid accidental deletion.
Be careful when using wildcards as you could accidentally delete rules.