From 1bc493d5de2bf969e13ee155e235df943dd5886d Mon Sep 17 00:00:00 2001 From: lub Date: Wed, 14 Aug 2019 21:56:09 +0200 Subject: [PATCH] add legacy bash code/notes --- expose_forwards.ps1 | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/expose_forwards.ps1 b/expose_forwards.ps1 index 72a38ec..abe56f7 100644 --- a/expose_forwards.ps1 +++ b/expose_forwards.ps1 @@ -85,4 +85,36 @@ foreach($yaml in (Get-ChildItem -Filter '*.yml')) { $nat.internal_port } } -} \ No newline at end of file +} + + + +#TODO: port from bash + +chain_rule='-m addrtype --dst-type LOCAL -j SWARM-NAT' +if ! iptables -t nat -C PREROUTING $chain_rule; then + Write-Output 'Add jump rule for SWARM-NAT' + iptables -t nat -A PREROUTING $chain_rule +fi + + +bridge=$( + docker network inspect docker_gwbridge \ + --format '{{(index .Containers "ingress-sbox").IPv4Address}}' \ + | cut -d'/' -f1 +) + +internal_port=30000 +public_port=30001 +destination='145.239.119.128' + + +rule="-p tcp -m tcp --destination ""${destination}"" --dport ""${public_port}"" + -j DNAT --to-destination ""${bridge}:${internal_port}""" + +if ! iptables -t nat -C SWARM-NAT $rule > /dev/null; then + Write-Output "Add rule for NAT from ${destination}:${public_port} to ${bridge}:${internal_port}" + iptables -t nat -A SWARM-NAT $rule +else + Write-Output "Rule for NAT from ${destination}:${public_port} to ${bridge}:${internal_port} already exists" +fi \ No newline at end of file