Giving the VM an own ip address

Posted on

Giving the VM an own ip address – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, networking, openvpn, virtual-machines, virtualbox.

I have a dedicated server running Ubuntu at a hosting provider. I already configured OpenVPN and VirtualBox and installed a Windows 7 VM using VirtualBox. The server has the following interfaces:

  • Interface eth0 is assigned the public IP address
  • Loopback interface
  • Tun interface from OpenVPN

Is it somehow achievable to have the Win7-VM to get an IP address from the VM-Range ( I want this to be possible so that the system is up and reachable by a public IP and if I connect to the VPN to have access to the VM with for example the IP

I’ve heard of network bridging and already tried several configurations, but when I did that it made the whole server unreachable. Maybe someone can explain me if it is realistic and which approach would be the most suitable.


Solution :

Changing the network adapter settings to bridged should put your VM in the same newtork as the host, using the first available IP address. From now on you can configure a static IP as you would do with physical machine, or you can use DHCP to pin your VM’s MAC address to an IP address (for example using router, or nameserver).

Network config in VM

Hope this helps!

In general, the solution with the least trouble may be to have the VM on a network reachable from the host and use routing between the external net and the vm net.

This gives you most control, while its not visible to the outside net. This avoid for example problems with dhcp requests from the vm going into the net of the hosting provider and similiar issues.

a sample configuration would for example use iptables:

iptables -t nat -I PREROUTING -i external-net -p tcp --dport 80 -j DNAT --to-destination win7vm # route http traffic into the vm
iptables -t nat -I POSTROUTING -i vmnet-interface -j MASQUERADE # replace vm-ip with external ip
iptables -A FORWARD -j ACCEPT
echo 1 >/proc/sys/net/ipv4/ip_forward

Your vm needs to use the host on interface vmnet-interface as (default) gateway, but this should be default if you didn’t change many network settings.

When you setup routing, you probably want to add some more iptables rules i.e. to prevent forwarding between other interfaces.

You need to use a tap device and mode bridge in your OpenVPN configuration.

Then you need to make a bridge which has the tap device configured in OpenVPN and the virtual internal network adapter as members.

You need to assign the host IP address to the bridge interface on the host.

After this, your OpenVPN tunnel and virtual machine network adapter are in the same subnet, and once you connect to the OpenVPN server, you will be connected to the same network.

You must leave the interface having the public IP address as it currently is.

Leave a Reply

Your email address will not be published. Required fields are marked *