0

I have a host A on which I have 2 lxc container (X and Y).

I originally had port 22 on my host (A) forwarded to X. Using this configuration, I wasn't able to ssh out of the container X and when ssh-ing out of contianer Y, it caused the ssh connection to be some how forwarded to X (even though I was ssh-in to an external computer).

When changing the port 22 fowarding from the host to forwarding port 2222 to X:22 then everything went back to normal...

Is there a way to forward port 22 to an lxc container?

Iptables command I used to forward port 22 on host A to container X:

iptables -t nat -A POSTROUTING -s 10.0.0.4 -o eth0 -j MASQUERADE

iptables -t nat -A PREROUTING -p tcp --dport 22 -j DNAT --to-destination 10.0.0.4:22

Thanks.

1 Answer 1

3

Fixed by adding the -i eth0 to my iptable rules (to specify only outside traffic should be redirected to container X:22.

iptables -t nat -A PREROUTING -p tcp --dport 22 -i eth0 -j DNAT --to-destination 10.0.0.4:22

1
  • In my case, I had to add -i ens3. Just prepare to use the correct interface. May 27, 2018 at 18:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .