OS: Ubuntu 15.10
LXD: 2.0.0.rc5
I would like to know how to access a container from another computer on the same local network.
Address of my PC (the LXD host): 192.168.1.112 (enp3s0)
Xenial container: 10.0.3.181 (eth0), 10.0.4.1 (lxcbr0)
Other PC (Fedora 23): 192.168.2.118 (wlp3s0)
I can ping from the other PC to the LXD host and the otherwise.
There's several different ways to accomplish what you want.
Options 1 and 2 require ip-forwarding to be enabled on the host:
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.
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) orsudo 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.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:
eth0
orenp3s0
to that bridgeenp3s0
)Bind lxd guest devices to that bridge
You need to tell the other computer how to reach the container because the other computer is on a different subnet than the container. That is, you need to set up a "route". Below is a sample route you can create on the other computer. It says, "to get to the container (.181) first go through the host (.112) using the device that is on the same network as the host (eth0). If the other computer uses a different device then change accordingly. Note that this route is not permanent; it will not survive a reboot. Google to find how to set up a permanent route.
Another way is to install
rinetd
and inside/etc/rinetd.conf
just specify the forwarding:and restart
rinetd
.I think it is more convenient because you can always check which ports are you forwarding and add comments to the file if you want. You can also use it with
docker
in the same way if you bind to127.0.0.1
(for example:docker ... -p 127.0.0.1:80:80 ...
and UFW will work as expected.