If you're new to PowerShell and need to change the gateway address of a Hyper-V VM, follow these steps. It'll be easier for you to understand what are you doing:
- Open PowerShell as Administrator from Hyper-V machine:
- Click on the Start menu, type
PowerShell
, right-click on Windows PowerShell
, and select Run as administrator
.
- Find the VM Network Adapter:
- First, you need to know the network adapter's name for your VM. Use the following command to list the network adapters of your VM:
Get-VMNetworkAdapter -VMName "YourVMName"
- Replace
"YourVMName"
with the name of your virtual machine. This command will show you the network adapters connected to the VM.
- Get the Current Network Configuration:
- To see the current IP configuration of the network adapter, use:
Get-VMNetworkAdapter -VMName "YourVMName" | Get-VMNetworkAdapterConfiguration
- This will display the current IP settings, including the gateway.
- Change the Gateway Address:
- Use the following command to change the gateway address:
Set-VMNetworkAdapterGateway -VMName "YourVMName" -Gateway "NewGatewayAddress"
- Replace
"NewGatewayAddress"
with the new gateway address you want to set.
- Verify the Changes:
- After changing the gateway, you can verify the new settings by running the
Get-VMNetworkAdapterConfiguration
command again:
Get-VMNetworkAdapter -VMName "YourVMName" | Get-VMNetworkAdapterConfiguration
If my answer helped you, please click on "Accept Answer" to help others in the community easily find the solution. Thank you!