Читать книгу Windows Server 2022 & Powershell All-in-One For Dummies - Sara Perrott - Страница 84

Configure networking

Оглавление

Before you can set the IP address for the adapter with PowerShell, you need to find out what the index of your interface is. You can do this by typing the following:

Get-NetAdapter

The output lists all network adapters. In this case, you want the one that says Ethernet. After you have the index number, you can set the IP address and the DNS servers. On my server, the index is 4.

Use the following command to set the static IP address. InterfaceIndex is the index number for my network card, IPAddress is the IP address I want to assign, PrefixLength is the subnet mask that I want to use, and DefaultGateway is the gateway address for the local network (see Figure 4-4).

New-NetIPAddress -InterfaceIndex 4 -IPAddress 192.168.1.50 -PrefixLength 24 -DefaultGateway 192.168.1.1

I haven't discussed PowerShell much at this point, and this is a more complex bit of PowerShell. The New-NetIPAddress is a cmdlet that allows you to work with IP addresses on Windows Server systems. The parameters that come afterward, like -InterfaceIndex, help to identify the object you want to work with (the network adapter, in this case) or to make changes to the settings, like the -IPAddress parameter where you specify the IP address you want to set on the network adapter.


FIGURE 4-4: Setting the IP address with PowerShell.

To set the DNS Server after that, the command uses the same index number for my network card. ServerAddresses is used to identify the DNS servers that the system should use (see Figure 4-5). If you have more than one, you can separate them with a comma.

Set-DNSClientServerAddress -InterfaceIndex 4 -ServerAddresses 8.8.8.8, 8.8.4.4


FIGURE 4-5: Setting the DNS servers with PowerShell.

Windows Server 2022 & Powershell All-in-One For Dummies

Подняться наверх