|
3 | 3 | set -euo pipefail
|
4 | 4 | c=$'\n\t'
|
5 | 5 |
|
| 6 | +# since alpine version 3.19.0 iptables-nft is used by default (https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.19.0), |
| 7 | +# however this causes compatibility issues for hosts with older kernels (e.g. Windows > https://github.com/microsoft/WSL/issues/6044), |
| 8 | +# therefore we still use iptables-legacy |
| 9 | +alias iptables=iptables-legacy |
| 10 | + |
6 | 11 | # --- Ensure container network capabilities ----------------------------------
|
7 | 12 |
|
8 | 13 | if ! capsh --has-p='cap_net_admin' --has-p='cap_net_raw' &>/dev/null
|
|
82 | 87 | # nft add rule nat prerouting tcp \
|
83 | 88 | # dport "${docker_container_port}" \
|
84 | 89 | # dnat to "$docker_host_ip:$docker_host_port"
|
85 |
| - iptables-legacy --table nat --insert PREROUTING \ |
| 90 | + iptables --table nat --insert PREROUTING \ |
86 | 91 | --protocol tcp --destination-port "${docker_container_port/-/:}" \
|
87 | 92 | --jump DNAT --to-destination "$docker_host_ip:$docker_host_port"
|
88 | 93 |
|
89 | 94 | # nft add rule nat prerouting udp \
|
90 | 95 | # dport "${docker_container_port}" \
|
91 | 96 | # dnat to "$docker_host_ip:$docker_host_port"
|
92 |
| - iptables-legacy --table nat --insert PREROUTING \ |
| 97 | + iptables --table nat --insert PREROUTING \ |
93 | 98 | --protocol udp --destination-port "${docker_container_port/-/:}" \
|
94 | 99 | --jump DNAT --to-destination "$docker_host_ip:$docker_host_port"
|
95 | 100 | done
|
96 | 101 |
|
97 | 102 | # nft add rule nat postrouting masquerade
|
98 |
| -iptables-legacy --table nat --insert POSTROUTING --jump MASQUERADE |
| 103 | +iptables --table nat --insert POSTROUTING --jump MASQUERADE |
99 | 104 |
|
100 | 105 |
|
101 | 106 | # --- Drop root access and "Ah, ha, ha, ha, stayin' alive" ---------------------
|
|
0 commit comments