Windows Server 2022 のスタティックルートを設定しよう

Windows Server 2022
Windows Server 2022

サーバーの通信先が必ずしもデフォルトゲートウェイの先に存在しているとは限りません。そんなときはスタティックルートを設定し、通信経路を示す必要があります。ここではWindows Server 2022 のスタティックルートを設定する方法について記載します。操作はGUIが主体となるWindowsですが、この設定はCUIで行う方が手っ取り早いです。

1.スタティックルートの設定

1.スタティックルートを追加するPowerShellコマンド

#現在のルーティング情報の取得
Get-NetRoute
#ネットワークインターフェース情報の取得
Get-NetIPConfiguration
#ルーティングの追加
New-NetRoute -InterfaceAlias "Service" -DestinationPrefix "192.168.30.0/24" -NextHop 192.168.10.100

出力結果

PS C:\Users\Administrator> Get-NetRoute

ifIndex DestinationPrefix                              NextHop                                  RouteMetric ifMetric PolicyStore
------- -----------------                              -------                                  ----------- -------- -----------
10      255.255.255.255/32                             0.0.0.0                                          256 25       ActiveStore
14      255.255.255.255/32                             0.0.0.0                                          256 25       ActiveStore
1       255.255.255.255/32                             0.0.0.0                                          256 75       ActiveStore
10      224.0.0.0/4                                    0.0.0.0                                          256 25       ActiveStore
14      224.0.0.0/4                                    0.0.0.0                                          256 25       ActiveStore
1       224.0.0.0/4                                    0.0.0.0                                          256 75       ActiveStore
10      192.168.20.255/32                              0.0.0.0                                          256 25       ActiveStore
10      192.168.20.201/32                              0.0.0.0                                          256 25       ActiveStore
10      192.168.20.0/24                                0.0.0.0                                          256 25       ActiveStore
14      192.168.10.255/32                              0.0.0.0                                          256 25       ActiveStore
14      192.168.10.201/32                              0.0.0.0                                          256 25       ActiveStore
14      192.168.10.0/24                                0.0.0.0                                          256 25       ActiveStore
1       127.255.255.255/32                             0.0.0.0                                          256 75       ActiveStore
1       127.0.0.1/32                                   0.0.0.0                                          256 75       ActiveStore
1       127.0.0.0/8                                    0.0.0.0                                          256 75       ActiveStore
14      0.0.0.0/0                                      192.168.10.1                                     256 25       ActiveStore
1       ff00::/8                                       ::                                               256 75       ActiveStore
1       ::1/128                                        ::                                               256 75       ActiveStore


PS C:\Users\Administrator> Get-NetIPConfiguration


InterfaceAlias       : Management
InterfaceIndex       : 10
InterfaceDescription : Intel(R) 82574L Gigabit Network Connection #2
NetProfile.Name      : 識別されていないネットワーク
IPv4Address          : 192.168.20.201
IPv4DefaultGateway   :
DNSServer            :

InterfaceAlias       : Service
InterfaceIndex       : 14
InterfaceDescription : Intel(R) 82574L Gigabit Network Connection
NetProfile.Name      : ネットワーク
IPv4Address          : 192.168.10.201
IPv4DefaultGateway   : 192.168.10.1
DNSServer            : 192.168.10.1



PS C:\Users\Administrator> New-NetRoute -InterfaceAlias "Service" -DestinationPrefix "192.168.30.0/24" -NextHop 192.168.10.100

ifIndex DestinationPrefix                              NextHop                                  RouteMetric ifMetric PolicyStore
------- -----------------                              -------                                  ----------- -------- -----------
14      192.168.30.0/24                                192.168.10.100                                   256 25       ActiveStore
14      192.168.30.0/24                                192.168.10.100                                   256          Persiste...


PS C:\Users\Administrator>

ルーティング先IPアドレスやサブネットマスクを間違えるとエラーになります。

2.スタティックルートを削除するPowerShellコマンド

#現在のルーティング情報の取得
Get-NetRoute
#ルーティングの削除
Remove-NetRoute -DestinationPrefix "192.168.30.0/24" -Confirm:$false -PassThru

出力結果

PS C:\Users\Administrator> Get-NetRoute

ifIndex DestinationPrefix                              NextHop                                  RouteMetric ifMetric PolicyStore
------- -----------------                              -------                                  ----------- -------- -----------
10      255.255.255.255/32                             0.0.0.0                                          256 25       ActiveStore
14      255.255.255.255/32                             0.0.0.0                                          256 25       ActiveStore
1       255.255.255.255/32                             0.0.0.0                                          256 75       ActiveStore
10      224.0.0.0/4                                    0.0.0.0                                          256 25       ActiveStore
14      224.0.0.0/4                                    0.0.0.0                                          256 25       ActiveStore
1       224.0.0.0/4                                    0.0.0.0                                          256 75       ActiveStore
14      192.168.30.0/24                                192.168.10.100                                   256 25       ActiveStore
10      192.168.20.255/32                              0.0.0.0                                          256 25       ActiveStore
10      192.168.20.201/32                              0.0.0.0                                          256 25       ActiveStore
10      192.168.20.0/24                                0.0.0.0                                          256 25       ActiveStore
14      192.168.10.255/32                              0.0.0.0                                          256 25       ActiveStore
14      192.168.10.201/32                              0.0.0.0                                          256 25       ActiveStore
14      192.168.10.0/24                                0.0.0.0                                          256 25       ActiveStore
1       127.255.255.255/32                             0.0.0.0                                          256 75       ActiveStore
1       127.0.0.1/32                                   0.0.0.0                                          256 75       ActiveStore
1       127.0.0.0/8                                    0.0.0.0                                          256 75       ActiveStore
14      0.0.0.0/0                                      192.168.10.1                                     256 25       ActiveStore
1       ff00::/8                                       ::                                               256 75       ActiveStore
1       ::1/128                                        ::                                               256 75       ActiveStore


PS C:\Users\Administrator> #ルーティングの削除
>> Remove-NetRoute -DestinationPrefix "192.168.30.0/24" -Confirm:$false -PassThru

ifIndex DestinationPrefix                              NextHop                                  RouteMetric ifMetric PolicyStore
------- -----------------                              -------                                  ----------- -------- -----------
14      192.168.30.0/24                                192.168.10.100                                   256 25       ActiveStore


PS C:\Users\Administrator> Get-NetRoute

ifIndex DestinationPrefix                              NextHop                                  RouteMetric ifMetric PolicyStore
------- -----------------                              -------                                  ----------- -------- -----------
10      255.255.255.255/32                             0.0.0.0                                          256 25       ActiveStore
14      255.255.255.255/32                             0.0.0.0                                          256 25       ActiveStore
1       255.255.255.255/32                             0.0.0.0                                          256 75       ActiveStore
10      224.0.0.0/4                                    0.0.0.0                                          256 25       ActiveStore
14      224.0.0.0/4                                    0.0.0.0                                          256 25       ActiveStore
1       224.0.0.0/4                                    0.0.0.0                                          256 75       ActiveStore
10      192.168.20.255/32                              0.0.0.0                                          256 25       ActiveStore
10      192.168.20.201/32                              0.0.0.0                                          256 25       ActiveStore
10      192.168.20.0/24                                0.0.0.0                                          256 25       ActiveStore
14      192.168.10.255/32                              0.0.0.0                                          256 25       ActiveStore
14      192.168.10.201/32                              0.0.0.0                                          256 25       ActiveStore
14      192.168.10.0/24                                0.0.0.0                                          256 25       ActiveStore
1       127.255.255.255/32                             0.0.0.0                                          256 75       ActiveStore
1       127.0.0.1/32                                   0.0.0.0                                          256 75       ActiveStore
1       127.0.0.0/8                                    0.0.0.0                                          256 75       ActiveStore
14      0.0.0.0/0                                      192.168.10.1                                     256 25       ActiveStore
1       ff00::/8                                       ::                                               256 75       ActiveStore
1       ::1/128                                        ::                                               256 75       ActiveStore


PS C:\Users\Administrator>

以上

コメント