@@ -69,22 +69,24 @@ echo "Docker Host: $docker_host_ip ($docker_host_source)"
6969PORTS=" ${PORTS:- " 1-65535" } "
7070PORTS=" $( echo ${PORTS// ,/ } ) "
7171
72+ nft add table nat
73+ nft add chain nat prerouting { type nat hook prerouting priority -100 \; }
74+ nft add chain nat postrouting { type nat hook postrouting priority 100 \; }
75+
7276echo " Forwarding ports: ${PORTS// / , } "
7377for forwarding_port in $PORTS
7478do
7579 docker_container_port=" ${forwarding_port%%:* } "
7680 docker_host_port=" ${forwarding_port#*: } "
81+
82+ nft add rule nat prerouting tcp \
83+ dport " ${docker_container_port} " dnat to " $docker_host_ip :$docker_host_port "
84+ nft add rule nat prerouting udp \
85+ dport " ${docker_container_port} " dnat to " $docker_host_ip :$docker_host_port "
7786
78- iptables --table nat --insert PREROUTING \
79- --protocol tcp --destination-port " ${docker_container_port/ -/: } " \
80- --jump DNAT --to-destination " $docker_host_ip :$docker_host_port "
81-
82- iptables --table nat --insert PREROUTING \
83- --protocol udp --destination-port " ${docker_container_port/ -/: } " \
84- --jump DNAT --to-destination " $docker_host_ip :$docker_host_port "
8587done
8688
87- iptables --table nat --insert POSTROUTING --jump MASQUERADE
89+ nft add rule nat postrouting masquerade
8890
8991# --- Drop root access and "Ah, ha, ha, ha, stayin' alive" ---------------------
9092
0 commit comments