sharing my PoC with Hetzner private networking
Hetzner Cloud VM private (internal) networking case. Task - assign private IP for container which is accessible from other VMs or servers via vSwitch.
Assumes you already have setup for vSwitch and internal networking, your VM private IP is 192.168.2.2 . Cloud subnet - 192.168.2.0/23, global private subnet with dedicated servers: 192.168.0.0/20
Add another internal ip via control panel - itās buried in Networking ā subnets, list of VMs ā triple . (ā¦) - add alias ip, something like that.
In my case Iāve chosen internal IP to be 192.168.2.101
<pretty standard lxc init, for bridge itās fine to answer yes)>
ensure that you have forwarding on - net.ipv4.ip_forward = 1
(lxd with default bridge/nat will do it for you)
configuring container of interest:
run on host:
lxc launch ubuntu:focal c1
lxc stop c1
lxc config edit c1
change devices section to have network part (by default devices section is empty - devices {} )
devices:
eth0:
ipv4.address: 192.168.2.101
name: eth0
nictype: routed
type: nic
on host:
iptables -t nat -A POSTROUTING -s 192.168.2.0/23 ! -d 192.168.0.0/20 -m comment --comment "NAT for internal network" -j MASQUERADE
letās make changes in container - lxc shell c1
to get inside and configure you network, netplan /etc/netplan/50-cloud-init.yaml
sample:
root@c1:~# cat /etc/netplan/50-cloud-init.yaml
# 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: no
dhcp6: no
addresses:
- 192.168.2.101/32
routes:
- on-link: true
to: 0.0.0.0/0
via: 169.254.0.1
nameservers:
addresses:
- 213.133.100.100
- 213.133.99.99
- 213.133.98.98
save and apply -netplan apply
.
Now you should be able to
- ping 192.168.2.101 (container itself)
- ping 192.168.2.2 (you host private IP)
- ping any other existing host in your private netrange, like 192.168.0.12
- ping 8.8.8.8 or any other public ip
If any of the above not working, means you have some issues with setup/nat/other parts of the system. If all good, congrats - use networking as usual for LXD containers.