Hyper-V and a static IP address for Ubuntu VM

I have read numerous SO posts with this one being almost identical but I cannot get this to work.

I have a single wireless NIC in my notebook running Windows 10 Pro 1803. This is configured with a static IP address of 192.168.40.111.

I want the VM to have a static IP address of 192.168.40.101 and be accessible to other machines on the 192.168.40/24 network. It will ultimately get Internet access via a host 192.168.40.2.

So based on what I have read I need to use Hyper-V's virtual switch manager to create an "External" switch which I have done called "Virtual Switch - Static" as follows:

enter image description here

and then use that for the VM. So far so good. However when I look at what is in the network adapters I see:

enter image description here

However if I change the IP address of the highlighted connection it changes the IP address of the wireless card as well which is what I don't want.

So how do I configure things so that the VM has its static address of 192.168.40.101 and the wireless card maintains its static address of 192.168.40.111?


Solution 1:

IP addresses need to be unique on a subnet and each device needs it's own. When you assign the IP to the virtual switch, that gives the host PC running Hyper-V its IP address on your network, the 192.168.40.111 address.
To assign an IP to a VM on the same subnet as the virtual switch, you need to assign the IP, the 192.168.40.101 address, directly in the VM's OS, i.e. Ubuntu.

You will also need to assign the subnet or netmask and gateway manually in the VM. You can choose to manually assign the DNS as well. You can get all this information from your Windows 10 host via the ipconfig command.

  1. Open a PowerShell or command prompt (cmd) by clicking Start and typing the name of either.
  2. Click to launch PowerShell or the command prompt
  3. type ipconfig /all and press enter
  4. You may need to scroll to see the results from your wifi card, but you can find all the information you need. Highlighted in the example. You will want to use your information, not the information highlighted. enter image description here

Assuming you're using Ubuntu 18.04, here's how: https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-04-bionic-beaver-linux

  1. Click on top right network icon and select settings corresponding to the network interface you wish to assign with the static IP address.
  2. Next, click on the gear box icon next to your network connection you wish to configure. This could be wired or wireless connection.
  3. Select IPv4 from the top menu.
  4. Select Manual for the IPv4 settings, enter your desired configuration and hit Apply
  5. Restart your network by ON/OFF switch.

Solution 2:

I know I'm late to the party, but I had this issue too and landed on this page after Googling it. What worked for me was to set a static MAC address:

Using the default switch: VM Settings -> Hardware -> Network Adapter -> Advanced Features -> MAC address -> Static