netsh ファイアウォールの代わりに netsh advfirewall ファイアウォールを使用して Windows ファイアウォールの動作を制御する

この記事では、コンテキストではなくファイアウォール コンテキストを netsh advfirewall 使用して Windows ファイアウォールの動作を netsh firewall 制御する方法について説明します。

適用対象: Windows Server 2012 R2
元の KB 番号: 947709

概要

netsh advfirewallファイアウォールのコマンド ライン コンテキストは、Windows Server 2012 R2 で使用できます。 このコンテキストは、ファイアウォール コンテキストによって提供された Windows ファイアウォールの動作を制御するための機能を netsh firewall 提供します。

このコンテキストは、ファイアウォール規則をより正確に制御するための機能も提供します。 これらのルールには、プロファイルごとの次の設定が含まれます。

  • ドメイン
  • プライベート
  • パブリック

コマンド ライン コンテキストは netsh firewall 、将来のバージョンの Windows オペレーティング システムで非推奨になる可能性があります。 ファイアウォールの動作を制御するには、 netsh advfirewall ファイアウォール コンテキストを使用することをお勧めします。

重要

Administrators グループのメンバーであり、コンピューターでユーザー アカウント制御が有効になっている場合は、管理者特権のアクセス許可を持つコマンド プロンプトからコマンドを実行します。 管理者特権でコマンド プロンプトを起動するには、コマンド プロンプト セッションを開始するために使用するアイコンまたは [スタート] メニュー エントリを見つけて右クリックし、[ 管理者として実行] をクリックします。

次の表では、よく使用されるコマンドの例をいくつか示します。 これらの例を使用すると、古い netsh firewall コンテキストから新しい netsh advfirewall ファイアウォール コンテキストに移行するのに役立ちます。

さらに、 netsh advfirewall 詳細なインライン ヘルプを取得するために使用できるコマンドも提供されます。

コマンド例 1: プログラムを有効にする

古いコマンド 新しいコマンド
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 以下のコマンドを実行します。
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

ファイアウォール規則を追加する方法の詳細については、次のコマンドを実行します。

netsh advfirewall firewall add rule ?

コマンド例 2: ポートを有効にする

古いコマンド 新しいコマンド
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

ファイアウォール規則を追加する方法の詳細については、次のコマンドを実行します。

netsh advfirewall firewall add rule ?

コマンド例 3: 有効なプログラムまたはポートを削除する

古いコマンド 新しいコマンド
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

ファイアウォール規則を削除する方法の詳細については、次のコマンドを実行します。

netsh advfirewall firewall delete rule ?

コマンド例 4: ICMP 設定を構成する

古いコマンド 新しいコマンド
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
netsh firewall set icmpsetting 13 disable all netsh advfirewall firewall add rule name="Block Type 13 ICMP V4" protocol=icmpv4:13,any dir=in action=block

ICMP 設定を構成する方法の詳細については、次のコマンドを実行します。

netsh advfirewall firewall add rule ?

コマンド例 5: ログ記録の設定

古いコマンド 新しいコマンド
netsh firewall set logging %systemroot%\system32\LogFiles\Firewall\pfirewall.log 4096 ENABLE ENABLE 以下のコマンドを実行します。
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

詳細については、次のコマンドを実行します。

netsh advfirewall set currentprofile ?

特定のプロファイルのログ記録を設定する場合は、オプションの代わりに次のいずれかのオプションを currentprofile 使用します。

  • Domainprofile
  • Privateprofile
  • Publicprofile

コマンド例 6: Windows ファイアウォールを有効にする

古いコマンド 新しいコマンド
netsh firewall set opmode ENABLE netsh advfirewall set currentprofile state on
netsh firewall set opmode mode=ENABLE exceptions=enable 以下のコマンドを実行します。
Netsh advfirewall set currentprofile state on
netsh advfirewall set currentprofile firewallpolicy blockinboundalways,allowoutbound
netsh firewall set opmode mode=enable exceptions=disable profile=domain 以下のコマンドを実行します。
Netsh advfirewall set domainprofile state on
netsh advfirewall set domainprofile firewallpolicy blockinbound,allowoutbound
netsh firewall set opmode mode=enable profile=ALL 以下のコマンドを実行します。
netsh advfirewall set domainprofile state on
netsh advfirewall set privateprofile state on

詳細については、次のコマンドを実行します。

netsh advfirewall set currentprofile ?

特定のプロファイルのファイアウォールの状態を設定する場合は、オプションの代わりに次のいずれかのオプションを currentprofile 使用します。

  • Domainprofile
  • Privateprofile
  • Publicprofile

コマンド例 7: ポリシーの既定値を復元する

古いコマンド 新しいコマンド
netsh firewall reset netsh advfirewall reset

詳細については、次のコマンドを実行します。

netsh advfirewall reset ?

コマンド例 8: 特定のサービスを有効にする

古いコマンド 新しいコマンド
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 以下のコマンドを実行します。

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