When creating a Virtual Machine in Cloud, you can choose to create it with multiple interfaces, meaning you’ll have more then one network on your machine working at the same time and interacting. Here, we’ll check how multiple network interfaces can interact with each other and what you can do to avoid any interruptions and/or issues.
When creating a VM with two or more network interfaces, you will be able to choose between creating one public and multiple private interfaces, or simply multiple private interfaces.
A public interface means you will be allocated a public IP address that has Internet access and can communicate with the outside network.
A private interface means that you will be allocated a private IP address with no access to the outside network. You can use the private network to set up communication between your virtual machines. To gain access to public network on private interface, you may simply add a floating IP to it.
Let’s check what happens once you create a virtual machine with two or more interfaces.
After you’ve created your machine with one public and one private interface, you might see your public network looking like this:
As mentioned before already, if the virtual server has two or more interfaces, they work at the same time and at the same rate. This can create a conflict that could lead to interruptions or packet loss in the network.
You can fix this behavior in a few ways.
The first way:
- Go to Cloud – Networks and click on the chosen network:
- Click on the three dots next to the chosen subnetwork and click on Edit:
- Disable router gateway and reboot your instance:
After these actions, your public network will stabilize and look something like this:
You can also fix this behaviour from inside your OS.
- Log into your VM, and perform the following command: ip r. With the output of ip r, you’ll be able to see that both interfaces are configured in the same way, and both have default routes with the same metrics:
- We can edit this through netplan. Open /etc/netplan/50-cloud-init.yaml with the help of nano command:
- With the help of dhcp4-overrides, we change the metrics of the private interface to 200. That way, the interface with lower metrics will be more preferable:
- Apply the configurations with sudo netplan apply, and you’re done!
- You can check whether the configuration has taken by checking ip r output once again:
And you’ll see that your network will become stable once again:
One more way to re-configure your network would be to pre-configure it using a script via user-data.
#cloud-config
write_files:
- path: /opt/set-route-metrics
content: |
#!/usr/bin/env bash
netplan_config="/etc/netplan/99-custom-overrides.yaml"
metric=200
iface=$(ip r | awk '/172.25.9.0\/24.*link./ {print $3}')
echo "network:" > $netplan_config
echo " ethernets:" >> $netplan_config
echo " $iface:" >> $netplan_config
echo " dhcp4-overrides:" >> $netplan_config
echo " route-metric: $metric" >> $netplan_config
chmod 600 $netplan_config
netplan apply
runcmd:
- [ bash, /opt/set-route-metrics ]
Here, please, note that:
- Any directory of your liking can be chosen;
- Default 'metric' value for Ubuntu is 100, so specifying 200 is enough to override it. But other OSes get different values from DHCP, for example, the default 'metric' value for CentOS is 400. This should be considered while using the script;
- In this part "awk '/172.25.9.0\/24.*link./ {print $3}')" 172.25.9.0\/24 should be changed to the mask of the subnet that is going to be used on the private interface of your VM.
Comments
0 comments
Please sign in to leave a comment.