lxc iptables network forwarding

Опубликовано: 23 Июль 2026
на канале: Dan Sheffner
5,967
67

how to access lxc/lxd/kvm or any remote hosts behind a server running these services.

packages
sudo apt-get install bridge-utils

static IP bind to br0
vi /etc/network/interfaces
auto lo
iface lo inet loopback

iface eth0 inet manual

auto br0
iface br0 inet static
bridge_ports eth0
address 192.168.1.10
broadcast 192.168.1.255
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4


allow internet access and ipv4 forwarding:
iptables -t nat -A POSTROUTING -s 10.0.3.0/24 -o br0 -j MASQUERADE
echo 1 LEFT ARROW /proc/sys/net/ipv4/ip_forward

persistent ipv4 forwarding
vi /etc/sysctl.conf
net.ipv4.ip_forward = 1

check forwarding:
cat /proc/sys/net/ipv4/ip_forward

forwarding web server (apache2)
iptables -t nat -A PREROUTING -p tcp -i br0 -d 192.168.1.10 --dport 8080 -j DNAT --to 10.0.3.76:80

forwarding SSH
iptables -t nat -A PREROUTING -p tcp -i br0 -d 192.168.1.10 --dport 8081 -j DNAT --to 10.0.3.76:22