banner
LAPLACE

LAPLACE By 王友元

那些娇艳欲滴姿态万千的花朵其实都依赖于某种神秘的养料——那就是人类幽微而真挚的情感故事
telegram
x
email

Hyper-V: Allocate static internal IP for virtual machines.

Idea#

First, let's talk about the idea: create a new network card on the host machine, bind it to the corresponding virtual machine, and then configure it in the virtual machine system.

Let's get started!#

Outside the virtual machine:#

In Hyper-V settings, create a new network card and set it to be used for internal network.

image
 

Bind the network card to the corresponding virtual machine.

image
 
Then, find the network card in the control panel (Control Panel\Network and Internet\Network Connections) and set a static IPv4 address in the properties.

image

Can I fill in the IP address in the above picture with any value, such as 192.168.88.1?
I initially filled it in this way, but the host machine couldn't connect to my virtual machine. Later, I set it to 192.168.172.2 and it worked fine (maybe because I restarted the virtual machine network?).
So I recommend setting it to 192.168.172.2 (please do not set it to 192.168.172.1 because 192.168.172.2 is already occupied by another network card by default!)

Inside the virtual machine:#

Taking CentOS 7 as an example, access SSH.

cd /etc/sysconfig/network-scripts
vi ifcfg-eth0

 
Modify the network card configuration file, change DHCP to static, and write the IP address into the file.

image

BOOTPROTO=static
IPADDR=192.168.137.100 // Set it to any value like 192.168.137.xxx
GATEWAY=192.168.137.1
NETMASK=255.255.255.0

 
Restart the network service to apply the settings:

systemctl restart network
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.