I try to test a python hole punching packet based on this article: https://bford.info/pub/net/p2pnat/

The hole punching process worked in several network setups, only the final use case (3.5 Peers Behind Multiple Levels of NAT) gives me difficulties.

Let's assume the following network:

                /    \
               /      \ /        \
        __[eth0]__   __[eth0]__
         **NATA**     **NATB**
        __[eth1]__   __[eth1]__|            |
            |            ||            |
        __[eth0]__   __[eth0]__
        **NodeA**    **NodeB**

I want to implement a hairpin on NAT0 as I think this causes the issue. However I do not understand how to configure the PREROUTING and POSTROUTING as I do not know the public port from the PAT(=NAT). Thus I am not able to know which packet belongs to machine NATA or NATB only by checking the destination ip-d if I would now which public port belongs to NATA and NATB I would able to send the package to the right local machine.

The interesting thing is that I was able to get it working with only a single NAT layer (while not having configured a Hairpin at all).

Possibly Related Question

How does NAT reflection (NAT loopback) work?

However in this case all the (local) traffic with the destination of the public ip gets routed to a single machine. In my case I want to route the package to different machine depending on their public port.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.