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.
Bind the network card to the corresponding virtual machine.
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.
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.
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