標籤:
netsh firewall set portopening protocol = TCP port = 9998 name = ssssssssssssssssssssssss mode = ENABLE scope = SUBNET profile = CURRENTnetsh advfirewall firewall add rule name = SQLPort dir = in protocol = tcp action = allow localport = 1433 remoteip = localsubnet profile = DOMAIN
Old command 針對win7以下版本<包含win7>
Example 1: 啟用一個程序
Old command |
New command |
netsh firewall add allowedprogram C:\MyApp\MyApp.exe "My Application" ENABLE |
netsh advfirewall firewall add rule name=”My Application” dir=in action=allow program=”C:\MyApp\MyApp.exe” enable=yes |
netsh firewall add allowedprogram program=C:\MyApp\MyApp.exe name="My Application" mode=ENABLE scope=CUSTOM addresses=157.60.0.1,172.16.0.0/16,LocalSubnet profile=Domain |
netsh advfirewall firewall add rule name=”My Application” dir=in action=allow program=”C:\MyApp\MyApp.exe” enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=domain |
netsh firewall add allowedprogram program=C:\MyApp\MyApp.exe name="My Application" mode=ENABLE scope=CUSTOM addresses=157.60.0.1,172.16.0.0/16,LocalSubnet profile=ALL |
Run the following commands:
netsh advfirewall firewall add rule name=”My Application” dir=in action=allow program=”C:\MyApp\MyApp.exe” enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=domain
netsh advfirewall firewall add rule name=”My Application” dir=in action=allow program=”C:\MyApp\MyApp.exe” enable=yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet profile=private |
Example 2: 啟用連接埠
Old command |
New command |
netsh firewall add portopening TCP 80 “Open Port 80” |
netsh advfirewall firewall add rule name=”Open Port 80” dir=in action=allow protocol=TCP localport=80 |
Example 3: 刪除已啟用的程式或連接埠
Old command |
New command |
netsh firewall delete allowedprogram C:\MyApp\MyApp.exe |
netsh advfirewall firewall delete rule name=rule name program=”C:\MyApp\MyApp.exe” |
delete portopening protocol=UDP port=500 |
netsh advfirewall firewall delete rule name=rule name protocol=udp localport=500 |
Example 4: ICMP配置
Old command |
New command |
netsh firewall set icmpsetting 8 |
netsh advfirewall firewall add rule name=”ICMP Allow incoming V4 echo request” protocol=icmpv4:8,any dir=in action=allow |
netsh firewall set icmpsetting type=ALL mode=enable |
netsh advfirewall firewall add rule name=”All ICMP V4” protocol=icmpv4:any,any dir=in action=allow |
Example 5: 設定日誌
Old command |
New command |
netsh firewall set logging %systemroot%\system32\LogFiles\Firewall\pfirewall.log 4096 ENABLE ENABLE |
Run the following commands:
netsh advfirewall set currentprofile logging filename %systemroot%\system32\LogFiles\Firewall\pfirewall.log
netsh advfirewall set currentprofile logging maxfilesize 4096 netsh advfirewall set currentprofile logging droppedconnections enable
netsh advfirewall set currentprofile logging allowedconnections enable |
Example 6:啟動防火牆
Old command |
New command |
netsh firewall set opmode ENABLE |
netsh advfirewall set currentprofile state on |
netsh firewall set opmode mode=ENABLE exceptions=enable |
Run the following commands:
Netsh advfirewall set currentprofile state on
netsh advfirewall set currentprofile firewallpolicy blockinboundalways,allowoutbound |
netsh firewall set opmode mode=enable exceptions=disable profile=domain |
Run the following commands:
Netsh advfirewall set domainprofile state on
netsh advfirewall set domainprofile firewallpolicy blockinbound,allowoutbound |
netsh firewall set opmode mode=enable profile =ALL |
Run the following commands:
netsh advfirewall set domainprofile state on
netsh advfirewall set privateprofile state on |
For more information, run the following command:
netsh advfirewall set currentprofile ?
Example 7: 恢複預設防火牆策略
Old command |
New command |
netsh firewall reset |
netsh advfirewall reset |
查看更多的資訊,運行以下命令
netsh advfirewall reset ?
Example 8: 啟用特定的服務
Old command |
New command |
netsh firewall set service FileAndPrint |
netsh advfirewall firewall set rule group=”File and Printer Sharing” new enable=Yes |
netsh firewall set service RemoteDesktop enable |
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes |
netsh firewall set service RemoteDesktop enable profile=ALL |
Run the following commands:
netsh advfirewall firewall set rule group="remote desktop " new enable=Yes profile=domain
netsh advfirewall firewall set rule group="remote desktop " new enable=Yes profile=private |
windows防火牆命令詳解(程式啟用命令列執行即可)