Francis Francis - 1 year ago 240
Linux Question

LXC Container as VPS

I've been looking into LXC containers and I was wondering as to whether or not it is possible to use an LXC container like an ordinary VPS?

What I mean is;

  1. How do I assign an external IP address to an LXC container?

  2. How do I ssh into an LXC container directly?

I'm quite new to LXC containers so please let me know if there are any other differences I should be aware of.

Answer Source
lxc-create -t download -n cn_name
lxc-start -n cn_name -d
lxc-attach -n cn_name

then in container cn_name install openssh server so you can use ssh then reboot it or restart ssh service.

To make any container "services" available to the world configure port forwarding from the host to the container.

For instance if you had a web server in a container, to forward port 80 from the host ip to a container with ip you can use the iptables rule below.

iptables -t nat -I PREROUTING -i eth0 -p TCP -d --dport 80 -j DNAT --to-destination

now the web server on port 80 of the container will be available via port 80 of the host OS.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download