reach lxd container from local network
There's several different ways to accomplish what you want.
- Forward required ports from host to guest
- Route networks
- Bridge devices
Options 1 and 2 require ip-forwarding to be enabled on the host:
# run time:
sudo sysctl -w net.ipv4.ip_forward=1
# permanent:
echo 'net.ipv4.ip_forward = 1' | sudo tee /etc/sysctl.d/30-virt-network
Easiest is 1 if you want to access specific service like http (port 80) on guest (you access guest port 80 with host ip-address+port), but you cannot run host services on that same port.
# on lxd host: (-i HOSTDEVICE to lan, usually enp3s0 or eth0)
sudo iptables -t nat -A PREROUTING -i enp3s0 -p tcp -m tcp --dport 80 -j DNAT --to 10.0.3.181:80
# making this permanent is left to the reader (because that depends on your choice of fw setup)
Option 2 is more tricky and depends on how much you can modify your network.
Check that (sudo iptables -L -n
) says that chain FORWARD (policy ACCEPT) or sudo iptables -I FORWARD -s 192.168.2.118 -j ACCEPT
allow it specifically.
Now either on the network firewall route 10.0.3.0/24 to your 192.168.1.112 host or test with route on the 192.168.2.118.
sudo ip route add 10.0.3.181 via 192.168.1.112 dev wlp3s0
Third option would bring your lxd guests to your lan as part of the lan. See Instruction converting eth0 (enp3s0 in your case) to bridge how to do it. In short:
- Create bridge device on host
- Add
eth0
orenp3s0
to that bridge - Set host address to bridge (not
enp3s0
) -
Bind lxd guest devices to that bridge
stop network-manager brctl addbr br0 brctl addif br0 enp3s0 ifconfig enp3s0 up ifconfig br0 up dhclient br0 lxc profile edit default - change lxcbr0 to br0