Configuring a network bridge

Find out how to configure your virtual machines for access to the public internet

Last updated 13th January 2021

Objective

Bridged networking can be used to configure your virtual machines. Some tweaking is necessary to make the network configuration work on our network.

This guide will explain how to use network bridging to configure internet access for your virtual machines.

Requirements

Instructions

The basic steps are always the same, independent of the underlying system:

  • creating a virtual MAC address for a failover IP
  • setting the MAC of the VM to that new virtual MAC address
  • configuring the IP address, netmask, gateway and route to the gateway inside the VM

Code samples in the following instructions have to be replaced with your own values:

  • SERVER_IP = The main IP address of your server
  • FAILOVER_IP = The address of your failover IP
  • GATEWAY_IP = The address of your default gateway

Step 1: Assign a virtual MAC address

Log in to the OVHcloud Control Panel and switch to the Bare Metal Cloud section. Then click on IP in the menu on the left-hand side and locate your failover IP address in the table.

Failover IP

Click on ... in the relevant row to open the context menu, and select Add a virtual MAC.

Add a virtual MAC

Choose ovh from the "Type" drop-down menu unless you are using VMware ESXi - in that case choose vmware. Type a name in the “Name of virtual machine” field, and click on Confirm.

Add a virtual MAC

Step 2: Determine the gateway address

To configure your virtual machines for internet access, you will need to know the gateway of your host machine (i.e. your dedicated server). The gateway IP address is made up of the first three octets of your server's main IP address, with 254 as the last octet. For example, if your server's main IP address was:

  • 169.254.10.20

Your gateway address would therefore be:

  • 169.254.10.254

Step 3: Prepare the host

For all operating systems and distributions, you must configure your virtual machine with the virtual MAC address you have created in the OVHcloud Control Panel.

Proxmox

After creating the VM and while it is still powered off, right-click the VM and click Edit settings.

1. Select the VM.
2. Open the Hardware section.
3. Select Network Device.
4. Click the Edit button.

navigate to Network Device

Then add the vMAC address created previously.

open Network Device

Now you can start the VM and proceed with the configuration steps, depending on the operating system installed.

VMware ESXi

After you've created the virtual machine and while it's powered off, right click the VM and click Edit settings.

VM context menu

Fold out Netwok Adapter 1, change the value in the MAC Address drop-down menu to Manual and enter the MAC address created previously.

Edit settings

Now you can start the VM and proceed with the configuration steps, depending on the operating system installed.

Step 4: Configure the virtual machines

Debian

Connect to the shell of your virtual machine. Open the virtual machine's network configuration file located in /etc/network/interfaces. Edit the file so that it reflects the configuration below (please remember to fill in your own values).

  • For older distributions:
auto lo eth0
iface lo inet loopback
iface eth0 inet static
    address FAILOVER_IP
    netmask 255.255.255.255
    broadcast FAILOVER_IP
    post-up route add GATEWAY_IP dev eth0
    post-up route add default gw GATEWAY_IP
    pre-down route del GATEWAY_IP dev eth0
    pre-down route del default gw GATEWAY_IP
  • For the latest distributions:
auto lo eth0
iface lo inet loopback
iface eth0 inet static
    address FAILOVER_IP
    netmask 255.255.255.255
    broadcast FAILOVER_IP
    post-up ip route add GATEWAY_IP dev eth0
    post-up ip route add default via GATEWAY_IP
    pre-down ip route del GATEWAY_IP dev eth0
    pre-down ip route del default via GATEWAY_IP

Also replace eth0 if your system uses Predictible Network Interface Names. You can find the network interface names with the following command:

ls /sys/class/net

Save and close the file, then restart your network or reboot the virtual machine.

Red Hat and Red Hat-based operating systems (CentOS 6, Scientific Linux, ClearOS, etc.)

Open a terminal on your virtual machine. Open the virtual machine's network configuration file located in /etc/network/interfaces. Edit the file so that it reflects the configuration below (please remember to fill in your own values).

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
IPV6INIT=no
PEERDNS=yes
TYPE=Ethernet
NETMASK=255.255.255.255
IPADDR=FAILOVER_IP
GATEWAY=GATEWAY_IP
ARP=yes
HWADDR=MY:VI:RT:UA:LM:AC

Save and close the file.
Next, open the virtual machine's routing file, which is located in /etc/sysconfig/network-scripts/route-eth0. Edit the file so that it reflects the configuration below (please remember to fill in your own values).

GATEWAY_IP dev eth0
default via GATEWAY_IP dev eth0

Save and close the file, then reboot your virtual machine.

CentOS 7

For CentOS 7, the name of the network adapter will vary, depending on the installation options. You will need to verify the adapter name and use it to configure your virtual machine. You can find the Network interface names with the command ls /sys/class/net.

Open a terminal on your virtual machine. Open the virtual machine's network configuration file located in /etc/sysconfig/network-scripts/ifcfg-(interface-name). Edit the file so that it reflects the configuration below (please remember to fill in your own values).

DEVICE=(interface-name)
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
IPV6INIT=no
PEERDNS=yes
TYPE=Ethernet
NETMASK=255.255.255.255
IPADDR=FAILOVER_IP
GATEWAY=GATEWAY_IP
ARP=yes
HWADDR=MY:VI:RT:UA:LM:AC

Save and close the file.
Next, open the virtual machine's routing file, which is located in /etc/sysconfig/network-scripts/route-(interface-name). Edit the file so that it reflects the configuration below (please remember to fill in your own values).

GATEWAY_IP - 169.254.10.254 (interface-name)
NETWORK_GW_VM - 255.255.255.0 (interface-name)
default GATEWAY_IP

Save and close the file.
Next, open the virtual machine's DNS configuration file, which is located in /etc/resolv.conf and add this line:

nameserver 213.186.33.99

After saving and closing the file, restart your network or reboot the VM.

FreeBSD 12.0

Open a terminal on your virtual machine. Open the virtual machine's network configuration file located in /etc/rc.conf. Edit the file so that it reflects the configuration below (please remember to fill in your own values). In this example, the interface name is em0. Replace this value if it does not apply.

ifconfig_em0="inet FAILOVER_IP netmask 255.255.255.255 broadcast FAILOVER_IP"
static_routes="net1 net2"
route_net1="-net GATEWAY_IP/32 -interface em0"
route_net2="default GATEWAY_IP"

Save and close the file.
Next, edit or create the file /etc/resolv.conf and add this line.

nameserver 213.186.33.99

Save and close the file, then reboot your virtual machine.

Ubuntu 18.04

First, open a terminal on your virtual machine and open the network configuration file located in /etc/netplan/ with the following command. For demonstration purposes, our file is called 50-cloud-init.yaml.

# nano /etc/netplan/50-cloud-init.yaml

Once the file is open for editing, amend it with the following code:

network:
    ethernets:
        (interface-name):
            addresses:
                - FAILOVER_IP/32
            nameservers:
                addresses:
                    - 213.186.33.99
                search: []
            optional: true
            routes:
                - to: 0.0.0.0/0
                  via: GATEWAY_IP
                  on-link: true
    version: 2

Save and close the file, then run the following command:

# netplan try
Warning: Stopping systemd-networkd.service, but it can still be activated by:
  systemd-networkd.socket
Do you want to keep these settings?

Press ENTER before the timeout to accept the new configuration

Changes will revert in 120 seconds
Configuration accepted.

Windows Server 2012 / Hyper-V

Before configuring your virtual machine, you need to create a virtual switch.

From the command line of your dedicated server, run ipconfig /all and note the name of the network adapter that contains the server's main IP address.

In the Hyper-V Manager, create a new virtual switch and set the connection type to External.

Select the adapter with the server’s IP, then tick the option Allow management operating system to share this network adapter.

networkbridging

This step is only required once for a Hyper-V server. For all VMs, a virtual switch is required to connect the VM’s virtual network adapters to the server’s physical adapter.

Next, select the VM you wish to add the failover IP to. Use the Hyper-V Manager to change the settings of the VM and shut it down.

Expand the network adapter in the left-hand menu and click on Advanced Features. Change the MAC address to Static, and enter the virtual MAC address for the failover IP. Once you have entered these settings, press OK to apply the changes.

networkbridging

Next, start the VM and log in as an administrator, then go to the Control Panel's Network and Sharing Center. Click on Ethernet to open the settings and click on the Properties button to view the Ethernet Properties.

Select Internet Protocol Version 4 (TCP/IPv4), and then click on the Properties button.

networkbridging

In the IPv4 Properties window, select Use the following IP address. Enter the failover IP into the IP address field, and enter 255.255.255.255 into the subnet mask.

Fill in your server’s gateway IP address in the appropriate field below and enter 213.186.33.99 into the Preferred DNS Server field.

Finally, click OK, and ignore the warning message about the gateway IP and the assigned IP not being in the same subnet.

networkbridging

After rebooting the server, the VM should be connected to the internet using the failover IP.

Troubleshooting

If you are unable to establish a connection from your VM to the public network and you suspect a networking problem, please reboot the server in rescue mode and set up the bridging network interface directly on the host.

Enter the following command in the rescue mode terminal, in which you replace MAC_ADDRESS with the vMAC address that you have generated in the Control Panel and FAILOVER_IP with your failover IP address:

ip link add name test-bridge link eth0 type macvlan
ip link set dev test-bridge address MAC_ADDRESS
ip link set test-bridge up
ip addr add FAILOVER_IP/32 dev test-bridge

Next, ping your failover IP address from an external device.

  • If it responds, that probably means that there is a configuration error either on the VM or the host that prevents the failover IP from working in normal mode.

  • If the IP address is still not working, please create a ticket in your OVHcloud Control Panel to relay your test results to our support teams.

Go further

Join our community of users on https://community.ovh.com/en/.


Did you find this guide useful?

Please feel free to give any suggestions in order to improve this documentation.

Whether your feedback is about images, content, or structure, please share it, so that we can improve it together.

Your support requests will not be processed via this form. To do this, please use the "Create a ticket" form.

Thank you. Your feedback has been received.


These guides might also interest you...

OVHcloud Community

Access your community space. Ask questions, search for information, post content, and interact with other OVHcloud Community members.

Discuss with the OVHcloud community