Thank you for the reply.
The LXD host has WAN connection on ens3 and private network 192.168.1.0/24 on ens13
For accessing internet i need routed nic to ens3 and for accessing private net - a routed nic to ens13.
I created container with the settings from your tutorial:
lxc profile create garb_intranet
lxc profile edit garb_intranet << EOF
- to: 0.0.0.0/0
description: Galera Arbitrator Intranet (Production)
lxc launch ubuntu:22.04 garb-intranet -p garb_intranet
Now i have container with eth0 192.168.100.200/32 and gateway 169.254.0.1
Host has additional vethb5c9d2ad attached with IP 169.254.0.1/32
Still no internet, i added iptables rule:
iptables -t nat -A POSTROUTING -s 192.168.100.200/32 -o ens3 -j SNAT --to-source 18.104.22.168
Using SNAT instead of MASQUERADE because ens3 has multiple public IPs attached and not all of them may be attached on this host instance (it’s main purpose is load balancing). Internet started working.
How can i set the iptables rule permanent on reboot?
Is it possible to configure iptables in lxc profile? Or should i include it in Ubuntu netplan config for ens3?
How to configure second nic in lxc? If i add eth1 in profile devices
then launching lxc shows error:
Error: Failed instance creation: Failed creating instance record: Failed initialising instance: Invalid devices: Device validation failed for "eth0": Existing NIC "eth1" already uses "ipv4.gateway" in auto mode