You've to create a bridged network between the Host and VM. The configuration varies on Hypervisor vendor.
In case you're using Oracle Virtual Box
- Open
Oracle VM VirtualBox Manager
, select the VM and go to network section.
- In
Adopter 1
tab change the default NAT
to Bridged Adopter
and chose host's Network Adopter from Name
drop-down. Apply it.
- Now configure network inside VirtualBox as per your ISP's configuration like static dynamic etc.
If you're using QEMU-KVM
- Open
Virtual Machine Manager
GUI tool (In case you're using GUI)
- Select the specific Virtual machine and
Open
it. Then select the NIC
- Chnage default
NAT
to Host Device xxxxxx: macvtap
apply and then configure network inside Virtual Machine as per ISP's configuration.
- If you don't have GUI tool then use
virsh edit virtual-machine-name
and modify the configuration as described previously.
A third alternate is creating iptable
NAT
rule in host. Then forward all traffic towards that IP (which you want to assign to VM) to VM's internal IP address. You've to write a few iptables
line, please google for it. But for me it's the least preferred method.
NOTE-1 Bridged Network
and macvtap
doesn't work with most of the WiFi
adopters in host.
NOTE-2 In case of macvtap
your host will be unreachable from VM and vice versa. Both of them will be reachable from outside network. Further, if you've multiple VM they will remain reachable to each other. This is the way macvtap
works. To access VM's from host and vice versa create one more NAT adopter in case of Oracle VirtualBox and one more NIC with NAT for QEMU-KVM.
NOTE-3 For both Bridged Network
and macvtap
the host's network adopter must have an IP address reserved per VM, as the question already mentioned.