Hands-on task
Port forwarding from the inside: DNAT in iptables
The payment gateway pay (izzylab/minihttp:1) is published on the server's port 9443 (docker port pay). The container is alive and answers inside, but curl http://127.0.0.1:9443/ and a request to the server's external address (eth0) hang until timeout.
After the move from the old server, hand-written rules were left in the nat table. Use iptables -t nat to work out where packets to 9443 really go, and fix it:
- remove the extra rules; don't touch Docker's rules, don't recreate or restart
pay; payanswers both on127.0.0.1:9443and on the server's external address;- write to
/root/dnat.txt, asIP:port, where Docker actually forwards port 9443.
The lab has its own Docker with no internet access; the images are already loaded: izzylab/minihttp:1, alpine:3.21, busybox:1.36, nginx:1.27-alpine. izzylab/minihttp is a tiny HTTP service on port 8080: GET / answers <NAME> ok, GET /call itself goes to http://<UPSTREAM>/ and answers <NAME> -> <the neighbor's reply> (or 502), GET /env shows its settings. It is configured with the environment variables NAME, PORT, BIND (the address it listens on) and UPSTREAM.
- iptables nat
- DNAT
- docker port publishing