3

Is it possible to set a static IP address for Hyper-V's default switch adapter? Every time I reboot my PC the address has changed.

  • 2
    No, the default switch isn't configurable. I believe this still works in the newer versions of Win 10: petri.com/using-nat-virtual-switch-hyper-v – essjae Feb 18 at 18:57
  • Can you set a static address in Control Panel > Network Connections > Change adapter settings via right-clicking the vEthernet switch? – harrymc Mar 26 at 9:01
  • @harrymc yes I can set a static address, but it will be automatically overwritten to some random address after system reboot – Vladimir Mar 26 at 12:26
2
+50

You can set a static address in Control Panel > Network Connections > Change adapter settings by right-clicking the vEthernet switch, but Windows will reset it to a random address after the reboot, and that action cannot be disabled.

A solution could be to reset it always to the same value by using the netsh command or its PowerShell alternatives. Netsh needs to be run as Administrator.

The command syntax is:

netsh interface ip set address [name=]InterfaceName [source=]{dhcp | static [addr=]IPAddress[mask=]SubnetMask [gateway=]{none | DefaultGateway [[gwmetric=]GatewayMetric]}}

An example command to set the switch to static IP of 192.168.100.1, mask 255.255.255.0 and gateway none is:

netsh interface ip set address name="vEthernet (Default Switch)" static 192.168.100.1 255.255.255.0 none

If necessary, you could set a script containing the command to run when Windows is started or on user logon.

Another solution would be to create a new switch, whose IP address will stay, unlike the default switch.

  • 192.168.100.1 should be avoided since it's the standard IP of cable modems' WebUI. – JW0914 Mar 26 at 13:36
  • @JW0914: It's just the first thing that came into my mind. – harrymc Mar 26 at 14:10
0

I'm aware that it may be a little off topic, but since we're setting this IP in order to e.g connect via SSH to our Hyper-V instance, then it's possible to assign static MAC address and then write some "self-discovery" script so we will dont have to use assign ip to vEthernet everytime

Assign static MAC:

Right click on Hyper-V instance -> Settings > NetworkCard > Advanced Functions -> Choose Static MAC and FILL MAC

enter image description here

In my case it is powershell script which extracts IP from arp discovery basing on that static MAC and then connects to it via SSH

$str = ((arp -a | findstr /i 00-15-5D-01-83-0B)[0]); 
$ip = $str.Split(" ")[2].Trim()
ssh root@$ip

Explaination:

arp

Displays and modifies the IP-to-Physical address translation tables used by
address resolution protocol (ARP).

ARP -s inet_addr eth_addr [if_addr]
ARP -d inet_addr [if_addr]
ARP -a [inet_addr] [-N if_addr] [-v]

  -a            Displays current ARP entries by interrogating the current
                protocol data.  If inet_addr is specified, the IP and Physical
                addresses for only the specified computer are displayed.  If
                more than one network

arp -a | findstr /i 00-15-5D-01-83-0B

/i = ignore case

Returns:

 192.168.1.31          00-15-5d-01-83-0b     dynamic
 192.168.43.170        00-15-5d-01-83-0b     static

[0] Index

Picks:

192.168.1.31          00-15-5d-01-83-0b     dynamic

$str.Split(" ")[2].Trim()

Returns:

192.168.1.33

then ssh connects to it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.