16

How can I allocate a fixed IP address for an Ubuntu Server 12.04 guest OS running in Virtual Box?

I've seen this question but it doesn’t address using a “Bridged Adapter.”

The virtual machine is currently getting an IP in the range 192.168.10.x and I want it always to be 192.168.10.99.

2
  • You could literally copy and paste that answer but substitute 'Host-only' for 'Bridged'.
    – rtf
    Jul 31, 2012 at 23:44
  • Does the VM get its IP address via DHCP from the router? If so, what model router is it?
    – Paul
    Aug 1, 2012 at 6:55

3 Answers 3

14

When you give a VM a Bridged Adapter, it's effectively like giving it its own NIC connected directly to your network.

The Ubuntu installation inside of the VM needs to be set to use a static IP address. This is done in the /etc/network/interfaces file. Some information about the interfaces file can be found on this page: https://help.ubuntu.com/12.04/serverguide/network-configuration.html

Here is an example interfaces file configured to match your question:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
        address 192.168.10.99
        netmask 255.255.255.0
        broadcast 192.168.10.255
        network 192.168.10.0
        gateway 192.168.10.1

After making modifications to /etc/network/interfaces, restart your VM for the changes to take effect.

1
2

As a follow-on to he previous answer, the Guest OS does have a virtual Network Interface Card (NIC). This "guest NIC" has a MAC address which differs from that of the host OS.

An alternative would, if you have access to the router settings, to let the router allocate the the same IP address to that MAC address every time it requests one via DHCP. NB I haven't tried this myself but it should work.

It comes down to where you prefer to do the configuration, in the router or in the guest OS.

0

For Ubuntu server 18.04.3 LTS, the setting would be done under /etc/netplan. In my case, it's /etc/netplan/50-cloud-init.yaml like below:

network:
    ethernets:
    enp0s3:
        dhcp4: no
        addresses: [10.10.5.130/24]
        gateway4: 10.10.5.10
        nameservers:
            addresses: [10.10.20.13,10.10.20.23]
    version: 2

After making the modifications, it also needs to restart the VM for the changes to take effect.

1
  • Is this also the case for bridged network adapter? I think you also need to run sudo netplan apply for applying.
    – axtck
    Apr 7, 2021 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .