Note: If you are using a Scale or HG server, please refer to the following guide instead: How to Configure the Network on Windows Server with Hyper-V with SCALE and HG Servers
With OVHcloud Additional IPs, connecting your virtual machines to the Internet can be a breeze. Follow this tutorial to connect your VM to the Internet in Hyper-V.
Prerequisites
- Dedicated Server running Windows Server 2019
- Additional IP through OVHcloud
Topics
- Creating a Virtual MAC for a Additional IP in the OVHcloud Control Panel
- Configuring the VM with the Virtual MAC Address
- Configuring Network Settings in a Debian 10/11 VM
- Configuring Network Settings in an Ubuntu 18.04+ VM
- Configuring Network Settings in an Ubuntu 16.04 VM
- Configuring Network Settings in a CentOS 7 VM
- Configuring Network Settings in a CentOS 6.x VM
- Configuring Network Settings in a Windows Server 2019 VM
Creating a Virtual MAC for a Additional IP in the OVHcloud Control Panel
In this section, we will be creating a virtual MAC address to be used by the NIC (Network Interface Card) which Hyper-V assigns to a VM. To begin, log in to the OVHcloud Control Panel. Click Bare Metal Cloud at the top of the page. Then, on the left-hand sidebar click the IP option.
Choose the additional IP you wish to configure to your VM and click the ellipses (...) button next to it. Then, select the Add a virtual MAC option from the drop-down menu.
In the popup menu, change the "Type" to "ovh" and enter the name of your virtual machine.
Note: Please allow up to three minutes for the virtual MAC to populate in the OVHcloud Manager.
Configuring the VM with the Virtual MAC Address
We will first create a virtual switch in Hyper-V Manager before we configure our VM. From the command line of your dedicated server, run ipconfig /all
and note the name of the network adapter that contains the server’s main IP address.
In Hyper-V Manager, click the name of your server on the left-hand column, then click Virtual Switch Manager... in the right-hand column.
Select External in the Virtual Switch Manager and then click Create Virtual Switch.
Select the external network that we found at the beginning of this section and click OK.
Your server will momentarily lose connection. Give it up to a minute to reconnect.
Next, we will be pairing the virtual MAC, which we generated in the first section, to the interface that Hyper-V has assigned to the VM. To complete this step, your VM must be powered off.
In Hyper-V Manager, right-click your VM and select the Settings... option from the drop-down menu.
On the left-hand column, click the + next to "Network Adapter" and click Advanced Features. Select Static for the MAC address and enter your virtual MAC here. Click OK to save the settings.
You are now ready to configure the network interface on your VM. In the next step, we will be configuring network settings within the OS of our VM. These steps can be different depending on the OS you are using. Click the correct link below to take you to instructions for your OS of choice:
Debian 10/11 | Ubuntu 18.04+ | Ubuntu 16.04 | CentOS 7 | CentOS 6.x | Windows Server 2019
Configuring Network Settings in a Debian 10/11 VM
In this step, we will be configuring our interface settings. To do this, you must first open your interface configuration file. Do so in a text editor of your choice using the following command:
$ sudo vi /etc/network/interfaces
Edit the interfaces file to make it appear as follows:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto ens192 iface ens192 inet static address 192.0.2.1 netmask 255.255.255.255 gateway 203.0.113.254 dns-nameservers 208.67.222.222 208.67.220.220
In this file, replace the following pieces of information as instructed:
- 1. If you don't know the name of your interface, you can find it using the following command:
$ ip add
- 2. Next to "address", replace "192.0.2.1" with the additional IP to which you have added the vMAC in the OVHcloud Manager.
- 3. Next to "gateway", replace the "203.0.113.254" with the IPv4 Gateway of your server, found in the OVHcloud Control Panel. (See more here.)
- 4. The DNS name servers listed are from OpenDNS. Feel free to use other name servers if you choose.
Now you will need to bring your NIC online. To do so, enter the following command:
$ sudo ip link set ens192 up
Finally, restart your networking service using the following command:
$ sudo systemctl restart networking
To test that the VM is fully connected to the Internet, ping example.com. If you get a response, you are good to go. If you do not, restart your VM and attempt the ping again.
Configuring Network Settings in an Ubuntu 18.04+ VM
Canonical, the developer of Ubuntu, implemented the use of Netplan for easy-to-use network configuration as of version 17.x.
To configure the network interface, open the 01-netcfg.yaml
file in a text editor of your choice using the following command:
$ sudo vi /etc/netplan/01-netcfg.yaml
Edit the file to make it appear as follows:
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network: version: 2 renderer: networkd ethernets: ens160: dhcp4: no dhcp6: no addresses: [192.0.2.1/32] gateway4: 203.0.113.254 nameservers: addresses: [208.67.222.222,208.67.220.220] routes: - to: 203.0.113.254/32 via: 0.0.0.0 scope: link
In this file, replace the following pieces of information as instructed:
- 1. If you replace the VMXNET3 NIC with another one, your NIC may use a different naming convention. If it does, replace "ens160" in the file with the name of your interface. If you don't know the name of your interface, you can find it using the following command:
$ ip add
- 2. Next to "addresses", replace "192.0.2.1" with the additional IP to which you have added the vMAC in the OVHcloud Manager plus the subnet you wish to use in CIDR notation.
- 3. Next to "gateway4" and in the "routes" section, replace the "203.0.113.254" with the IPv4 Gateway of your server, found in the OVHcloud Control Panel. (See more here.)
- 4. The DNS name server addresses listed are from OpenDNS. Feel free to use other name servers if you choose.
Now apply the Netplan settings with the following command:
$ sudo netplan apply
To test that the VM is fully connected to the Internet, ping example.com. If you get a response, you are good to go. If you do not, restart your VM and attempt the ping again.
Configuring Network Settings in an Ubuntu 16.04 VM
In this step, we will be configuring our interface settings. To do this, you must first open your interface configuration file. Do so in a text editor of your choice using the following command:
$ sudo vi /etc/network/interfaces
Edit the interfaces file to make it appear as follows:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto ens160 iface ens160 inet static address 192.0.2.1 netmask 255.255.255.0 gateway 203.0.113.254 dns-nameservers 208.67.222.222 208.67.220.220
In this file, replace the following pieces of information as instructed:
- 1. If you don't know the name of your interface, you can find it using the following command:
$ ip add
- 2. Next to "address", replace "192.0.2.1" with the additional IP to which you have added the vMAC in the OVHcloud Manager.
- 3. Next to "gateway", replace the "203.0.113.254" with the IPv4 Gateway of your server, found in the OVHcloud Control Panel. (See more here.)
- 4. The DNS name servers listed are from OpenDNS. Feel free to use other name servers if you choose.
Now you will need to bring your NIC online. To do so, enter the following command:
$ sudo ip link set ens160 up
Finally, restart your networking service using the following command:
$ sudo systemctl restart networking
To test that the VM is fully connected to the Internet, ping example.com. If you get a response, you are good to go. If you do not, restart your VM and attempt the ping again.
Configuring Network Settings in a CentOS 7 VM
In this step, we will be configuring our interface settings. To do this, first navigate to the network-scripts
directory using the following command:
$ cd /etc/sysconfig/network-scripts
Use the ls
command to view the content of the directory.
$ ls -al
Locate your interface file (e.g. ifcfg-ensXXX) and then open it in a text editor of your choice using the following command:
Note: In our example the interface file is ifcfg-ens192
.
$ sudo vi ifcfg-ens192
Edit the interfaces file to make it appear as follows, changing only what is in red:
TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens192 UUID=*DO NOT edit this field!* DEVICE=ens192 ONBOOT=yes IPADDR=192.0.2.1 NETMASK=255.255.255.0 GATEWAY=203.0.113.254 DNS1=208.67.222.222 DNS2=208.67.220.220
In this file, check/replace/add the following pieces of information as instructed:
- For "IPADDR", replace "192.0.2.1" with the additional IP that you added a vMAC to in the OVHcloud Manager.
- For "GATEWAY", replace the "203.0.113.254" with the IPv4 Gateway of your server, found in the OVHcloud Control Panel. (See more here.)
Note: The DNS name servers listed are from OpenDNS. Feel free to use whichever name servers you prefer.
Next, enable the NIC by restarting the network service:
$ sudo systemctl restart network
To test that the VM is fully connected to the Internet, ping example.com. If you get a response, you are good to go. If you do not, restart your VM and attempt the ping again.
Configuring Network Settings in a CentOS 6.x VM
In this step, we will be configuring our interface settings. To do this, first navigate to the network-scripts
directory using the following command:
$ cd /etc/sysconfig/network-scripts
Use the ls
command to view the content of the directory.
$ ls -al
Locate your interface file (e.g. ifcfg-ethX) and then open it in a text editor of your choice using the following command:
Note: In our example the interface file is ifcfg-eth0
.
$ sudo vi ifcfg-eth0
Edit the interfaces file to make it appear as follows, changing only what is in red:
DEVICE=eth0
HWADDR=*Verify this matches the vMAC created and assigned to the VM!*
TYPE=Ethernet
UUID=*DO NOT edit this field!* ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none IPADDR=192.0.2.1 NETMASK=255.255.255.0 GATEWAY=203.0.113.254 DNS1=208.67.222.222 DNS2=208.67.220.220
In this file, check/replace/add the following pieces of information as instructed:
- For "IPADDR", replace "192.0.2.1" with the additional IP that you added a vMAC to in the OVHcloud Manager.
- For "GATEWAY", replace the "203.0.113.254" with the IPv4 Gateway of your server, found in the OVHcloud Control Panel. (See more here.)
Note: The DNS name servers listed are from OpenDNS. Feel free to use whichever name servers you prefer.
Next, create a new file, route-eth0
, in the /etc/sysconfig/network-scripts/
directory and define the following default routes for the interface using the gateway we defined above:
$ sudo vi /etc/sysconfig/network-scripts/route-eth0
203.0.113.254 dev eth0 default via 203.0.113.254 dev eth0
Lastly, enable the NIC by restarting the network service:
$ sudo /etc/init.d/network restart
To test that the VM is fully connected to the Internet, ping example.com. If you get a response, you are good to go. If you do not, restart your VM and attempt the ping again.
Configuring Network Settings in a Windows Server 2019 VM
In this step, we will be configuring our interface settings. To do this, navigate to the Server Manager. From the left-hand column, click the Local Server option.
By default, the "Ethernet0" option will read, IPv4 address assigned by DHCP, IPv6 enabled. This is exactly what we want to change, so click on this text.
Next, right-click on Ethernet0 and select the Properties option from the drop-down menu. From the ensuing menu, double-click the Internet Protocol Version 4 (TCP/IPv4) option.
This will allow you to configure your interface to use the IP address, gateway, and DNS name servers of your choice. Configure it as follows:
In this file, replace the following pieces of information from the picture as instructed:
- 1. Next to "IP address", replace "203.0.113.32" with the additional IP to which you have added the vMAC in the OVHcloud Manager.
- 2. Next to "Subnet mask", replace "255.255.255.248" with the correct netmask depending on the size of the block of IPs you have purchased. For instance, if you are using a /28 block, put "240" in the last octet.
- 3. Next to "Default gateway", replace the "147.135.0.254" with the IPv4 Gateway of your server, found in the OVHcloud Control Panel. (See more here.)
- 4. The DNS nameservers listed are from OpenDNS. Feel free to use other name servers here, if you choose.
Click OK after making these changes. To test that the VM is fully connected to the Internet, ping example.com. If you get a response, you are good to go. If you do not, restart your VM and attempt the ping again.
Conclusion
Connecting your VM to the Internet is an essential task before it can be used as a web server, a mail server, or whatever other use you have in mind. Having read this article, you should be familiar with the first steps that are required to connect a VM to the Internet using Microsoft Hyper-V.