Este conteúdo não está disponível na sua linguagem... Então se você não entende a linguagem... bem, você pelo ou menos pode apreciar as imagens da postagem, né?
Este conteúdo não está disponível na sua linguagem... Então se você não entende a linguagem... bem, você pelo ou menos pode apreciar as imagens da postagem, né?
If you have a dedicated server with OVHcloud, you can purchase additional IPs, also known as "Fallback IPs", for your server. Because I have enough resources on my dedicated servers, I wanted to give/rent VPSes for my friends for them to use for their own projects, but I wanted to give them the real VPS experience, with a real external public IP that they can connect and use.
So I figured out how to bind an external IP to your LXD container/LXD VM! Although there are several online tutorials discussing this process, none of them worked for me until I stumbled upon this semi-unrelated OVHcloud guide that helped me go in the right direction.
First, launch the container/VM with lxc launch
root@divine-doge:/etc/netplan# lxc launch ubuntu:22.04 fallbackiptest
Creating fallbackiptest
Starting fallbackiptest
Add a macvlan
device to the container with lxc config device add fallbackiptest eth0 nic nictype=macvlan parent=YOUR_HOST_NETWORK_INTERFACE_HERE
.
Check your host's network interface name with ip a
. If you only have a single network interface, it will probably be enp1s0f0
.
root@divine-doge:/etc/netplan# lxc config device add fallbackiptest eth0 nic nictype=macvlan parent=enp1s0f0
Device eth0 added to fallbackiptest
Go to OVHcloud's Dashboard, go to the "Bare Metal Cloud" tab, click on the "IP" section, find your Additional IP, click on the three dots and click to "Add a virtual MAC".
On the popup, select ovh
as the type, and the name can be anything.
After the Virtual MAC is created, it will be shown in the "Virtual MAC" column, copy it.
Set the container's MAC address with lxc config set fallbackiptest volatile.eth0.hwaddr YOUR_VIRTUAL_MAC_HERE
root@divine-doge:/etc/netplan# lxc config set fallbackiptest volatile.eth0.hwaddr YOUR_VIRTUAL_MAC_HERE
Restart the container
root@divine-doge:/etc/netplan# lxc restart fallbackiptest
Now we'll need to configure the IP within the container, so let's connect to the container
root@divine-doge:/etc/netplan# lxc exec fallbackiptest bash
root@fallbackiptest:~#
Then open netplan's cloud init config
root@fallbackiptest:~# nano /etc/netplan/50-cloud-init.yaml
The default setting is this, if you are using a VM, the interface name may be enps5
or something different.
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
eth0:
dhcp4: true
Now we'll replace everything after the eth0:
section with the following:
addresses:
- YOUR_FALLBACK_IP_HERE/32
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
search: []
optional: true
routes:
- to: 0.0.0.0/0
via: YOUR_HOST_GATEWAY_IP_HERE
on-link: true
The YOUR_FALLBACK_IP_HERE
is the Additional IP that you've bought, and the YOUR_HOST_GATEWAY_IP_HERE
is your host's gateway IP that you can find in your dedicated server's OVHcloud dashboard, it always ends with .254
. It will look something like this:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
eth0:
addresses:
- 123.123.123.123/32
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
search: []
optional: true
routes:
- to: 0.0.0.0/0
via: 200.200.200.254
on-link: true
After you are done, save the file by pressing CTRL+X, and now let's apply it! Apply the netplan config with netplan apply
.
root@fallbackiptest:~# netplan apply
I've noticed that sometimes netplan apply
complains saying that it needs to do a hard restart, but don't worry, it will work.
And then let's test it!
root@fallbackiptest:~# curl https://api.ipify.org/
HOPEFULLY_YOUR_FALLBACK_IP_WILL_BE_HERE
If your fallback IP is shown, then yay, you did it!
Now we need to tell cloud-init to not replace our custom settings, to do this, open /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
root@fallbackiptest:~# nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
And write the following into the file:
network: {config: disabled}
And that's it, have fun!