How to assign Public IP to KVM Virtual Machine from /29 subnet
Solution 1
You need to put eth0 in the same bridge as virtual machine interfaces.
Host1, Host2, VM1, VM2, VM3 are on the same L2 network and can communicate without routing. The Ip address to join Host1 is the IP adress of the bridge (eth0 don't have IP anymore)
Here is some information : from ubuntu wiki
Solution 2
This is how i configure my VMs. whether you are using KVM or Bhyve-vm a switch or bridge interface will be created while setting it up.
Give that switch/bridge an ip like: ifconfig vm-public inet 172.30.1.0/16
(vm-public is the switch name).
Afterwards log in to those VMs and configure ip in /etc/network/interfaces
.
And lastly configure a PF rule(or whichever firewall you use) like this:
nat on igb0 inet from 172.30.0.0/16 -> (igb0)
This way all the VMs in that subnet will have internet connectivity through the host machine.
Solution 3
Using a bridge will work, but it's easier to just use macvtab with eth0 instead. Easy to configure in virt-manager, go to the NIC config and change the source. Then setup the static ip in the guest.
Related videos on Youtube
Nithi2023
Mechanical Engineer. Web & Software Enthusiast! Home: https://www.nithi2023.com
Updated on September 18, 2022Comments
-
Nithi2023 over 1 year
I have got a dedicated server running Ubuntu and I got IPv4 assignment of
XX.30.240.90/29
. I have created a KVM Virtual Machine running Ubuntu withvirt-manager
and it is connect to internet via NAT.This is the current network configuration in the host:
~$ cat /etc/network/interfaces auto lo iface lo inet loopback auto eth0 iface eth0 inet static address XX.30.240.90 netmask 255.255.255.248 gateway XX.30.240.89
I want to assign remaining free IPs i.e, XX.30.240.91, XX.30.240.92, .. to virtual machines. I know, there are lot of tutorials online, but I am bit confused with this subnet. Need your help folks
-
hookenz about 7 yearsYou should be routing those IP's not NAT'ing! If you give the VM the IP then it will be available if a suitable route exists to the VM and the internet.
-
Nithi2023 about 7 years@Matt So, I should create a bridge in host and select that as NIC while configuring the VM and then setup the available static IP in the VM ?
-
hookenz about 7 yearsActually there are a couple of ways to do it. But given that you only have a /29 you might be best after all to use a 1:1 NAT
-
-
Nithi2023 about 7 yearswhat about the gateway in guest when i use macvtab as NIC?
-
Gerd Hoffmann about 7 yearsidentical to the host machine, i.e. XX.30.240.89