add NAT-PMP for automatic port mapping and external address discovery

This commit is contained in:
2026-02-09 17:05:24 -03:00
parent 7b47ef155c
commit cf5eb0d5fd
11 changed files with 970 additions and 1 deletions

View File

@@ -0,0 +1,95 @@
# NAT-PMP Test Environment
#
# Architecture:
# ┌─────────────────────────────────────────────────────┐
# │ Internal (10.100.0.0/24) │
# │ │
# │ ┌─────────┐ ┌─────────┐ ┌───────┐ │
# │ │ peer-a │ │ peer-b │ │router │ │
# │ │ .10 │ │ .11 │ │ .1 │ │
# │ └─────────┘ └─────────┘ └───┬───┘ │
# └─────────────────────────────────────────────┼──────┘
# │
# ┌─────────────────────────────────────────────┼──────┐
# │ External (10.200.0.0/24) │ │
# │ ┌─────┴────┐ │
# │ │ router │ │
# │ │ .1 │ │
# │ └──────────┘ │
# └────────────────────────────────────────────────────┘
#
# The router runs miniupnpd and does NAT for internal clients.
# Peers can use NAT-PMP to discover their external address and map ports.
services:
# NAT Router with miniupnpd
router:
build:
context: .
dockerfile: Dockerfile.router
cap_add:
- NET_ADMIN
sysctls:
- net.ipv4.ip_forward=1
networks:
internal:
ipv4_address: 10.100.0.1
external:
ipv4_address: 10.200.0.1
healthcheck:
test: ["CMD", "pgrep", "miniupnpd"]
interval: 2s
timeout: 2s
retries: 5
# Peer A (behind NAT)
peer-a:
build:
context: ../..
dockerfile: docker-tests/nat-pmp/Dockerfile.peer
depends_on:
router:
condition: service_healthy
cap_add:
- NET_ADMIN
networks:
internal:
ipv4_address: 10.100.0.10
environment:
- PEER_NAME=alice
- PEER_PORT=18100
- GATEWAY_IP=10.100.0.1
command: ["sleep", "infinity"]
# Peer B (behind NAT)
peer-b:
build:
context: ../..
dockerfile: docker-tests/nat-pmp/Dockerfile.peer
depends_on:
router:
condition: service_healthy
cap_add:
- NET_ADMIN
networks:
internal:
ipv4_address: 10.100.0.11
environment:
- PEER_NAME=bob
- PEER_PORT=18200
- GATEWAY_IP=10.100.0.1
command: ["sleep", "infinity"]
networks:
internal:
driver: bridge
ipam:
config:
- subnet: 10.100.0.0/24
gateway: 10.100.0.254
external:
driver: bridge
ipam:
config:
- subnet: 10.200.0.0/24
gateway: 10.200.0.254