Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a host machine(A) with lxc-container(B). A's local ip address is 10.0.3.1 and public ip, let's say 1.2.3.4. B's local ip address is 10.0.3.21.

I need 1.2.3.4:7999 to be forwarded to 10.0.3.1:7999 and I created the following rules for that:

iptables -t nat -I PREROUTING -p tcp -d 1.2.3.4 --dport 7999 -j DNAT --to 10.0.3.21:7999
iptables -A FORWARD -p tcp -d 10.0.3.21 --dport 7999 -j ACCEPT

When I connect to the A (1.2.3.4:7999) from the outside world I am connecting successfully. But I am falling when I try to connect to B from A (connection timed out).

What rules should I create to be able to connect to 1.2.3.4:7999 from 10.0.3.1?

share|improve this question
When you say public ip of A is hypothetically 1.2.3.4, is that actually the ip address of you router? – Jack Feb 4 at 14:32
Yes. It is its IP on eth0 (external IP). – Andrey Kouznetsov Feb 4 at 14:35
2  
Do not crosspost (serverfault.com/q/475065/51929). – Lekensteyn Feb 4 at 17:24

closed as off topic by Lekensteyn, Chris Wilson, Eliah Kagan, gertvdijk, Amith KK Feb 5 at 11:02

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

If I understand (I am not familiar with lxc-container), I don't think what you are trying to do is possible on most routers.

See http://forum1.netgear.com/showthread.php?t=76215, for example.

Port forwarding is part of NAT (Network Address Translation) and in most cases can only be done when accessing the network from the outside. I tried to do the exact same thing a few months ago and this was the conclusion I reached. You an I are trying to leave the network and come back into it so the translation will be done.

If we try to access another computer on the same network, we should use the "local" IP - in your case 10.0.3.1.

If you do find a way to do it, post it. I'd like to know.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.