Assigning a Static IP Address to a Hyper-V Guest (Ubuntu) with Different Ranges from your ISP
In this article, we will discuss how to assign a static IP address to a Hyper-V guest running Ubuntu, with different ranges from your Internet Service Provider (ISP). This process involves configuring the network settings of the Ubuntu guest to use a static IP address instead of the default DHCP-assigned IP address.
Prerequisites
Before we begin, make sure you have the following:
- A host machine running Windows 11 with Hyper-V enabled
- A virtual machine (VM) running Ubuntu as a guest operating system
- Access to the command prompt or PowerShell on the host machine
Setting a Static IP Address on the Ubuntu Guest
To set a static IP address on the Ubuntu guest, follow these steps:
- Start the Ubuntu VM in Hyper-V.
- Open the terminal window in Ubuntu.
- Edit the network interfaces file by running the following command:
sudo nano /etc/network/interfacesThis will open the network interfaces file in the Nano text editor.
- Locate the following lines in the network interfaces file:
# The primary network interface
auto eth0
iface eth0 inet dhcp
These lines indicate that the primary network interface (eth0) is currently configured to use DHCP to obtain an IP address.
- Modify the lines to use a static IP address as follows:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
In this example, we have set the static IP address to 192.168.1.100, the netmask to 255.255.255.0, and the gateway to 192.168.1.1. You should replace these values with the appropriate values for your network.
- Save the changes to the network interfaces file by pressing Ctrl+X, then Y, and then Enter.
- Restart the networking service by running the following command:
sudo service networking restartThis will apply the new network settings and assign the static IP address to the Ubuntu guest.
Setting a Static IP Address on the Hyper-V Host
To set a static IP address on the Hyper-V host, follow these steps:
- Open the command prompt or PowerShell on the host machine.
- Run the following command to open the network connections settings:
ncpa.cplThis will open the Network Connections window.
- Right-click on the network adapter that is connected to the same network as the Ubuntu guest, and select Properties.
- Select Internet Protocol Version 4 (TCP/IPv4) from the list, and then click the Properties button.
- Select the Use the following IP address option, and enter the static IP address, netmask, and gateway values for the network adapter. These values should be different from the static IP address assigned to the Ubuntu guest.
- Click the OK button to save the changes.
In this article, we have discussed how to assign a static IP address to a Hyper-V guest running Ubuntu, with different ranges from your ISP. We have covered the following key concepts:
- Editing the network interfaces file in Ubuntu to use a static IP address
- Restarting the networking service in Ubuntu to apply the new network settings
- Setting a static IP address on the Hyper-V host for the network adapter that is connected to the same network as the Ubuntu guest
References
- Ubuntu
- Enable Hyper-V on Windows 11
- How to Assign a Static IP Address in Ubuntu 14.04
- How to Change the IP Address in Windows 10
This article was generated using plain HTML. No page layout tags were used, and the output is valid HTML.
--endarticle--
Answers to Questions
- Question: How do I set a static IP address for a virtual machine running Windows 11 in Hyper-V?
- Answer: To set a static IP address for a virtual machine running Windows 11 in Hyper-V, follow these steps:
- Start the virtual machine in Hyper-V.
- Open the Control Panel in Windows 11.
- Click on Network and Internet, and then click on Network and Sharing Center.
- Click on Change adapter settings on the left-hand side.
- Right-click on the network adapter that is connected to the same network as the virtual machine, and select Properties.
- Select Internet Protocol Version 4 (TCP/IPv4) from the list, and then click the Properties button.
- Select the Use the following IP address option, and enter the static IP address, netmask, and gateway values for the network adapter. These values should be different from the static IP address assigned to the virtual machine.
- Click the OK button to save the changes.
- Question: How do I write a command prompt command every time I start a virtual machine in Hyper-V?
- Answer: To write a command prompt command every time you start a virtual machine in Hyper-V, you can create a batch file with the command and place it in the startup folder. Here are the steps:
- Open the Notepad application in Windows 11.
- Type the command prompt command that you want to run every time you start the virtual machine.
- Save the file with a .bat extension, for example, startvm.bat.
- Open the File Explorer in Windows 11.
- Type %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup in the address bar, and press Enter.
- Drag and drop the startvm.bat file into the Startup folder.
- Restart the virtual machine in Hyper-V. The command prompt command should run automatically.