From 80ddd0558368970a7c60b42e3e8b8a9ce1f3a964 Mon Sep 17 00:00:00 2001 From: Dr Nic Williams Date: Wed, 22 Mar 2017 07:24:08 +1000 Subject: [PATCH] default external_ip to spec.address [thx @dpb587-pivotal] --- .../templates/bin/forward_ports.sh.erb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/jobs/port_forwarding/templates/bin/forward_ports.sh.erb b/jobs/port_forwarding/templates/bin/forward_ports.sh.erb index 56612d0..8863f71 100644 --- a/jobs/port_forwarding/templates/bin/forward_ports.sh.erb +++ b/jobs/port_forwarding/templates/bin/forward_ports.sh.erb @@ -26,11 +26,13 @@ iptables -F ${CHAIN} || true sysctl net.ipv4.conf.all.route_localnet=0 <% p("networking.port_forwarding").each do |rule| %> - <% external_port = rule['external_port'] || raise("Expected non-empty 'external_port' on '#{rule.inspect}' rule") %> - <% internal_ip = rule['internal_ip'] || "127.0.0.1" %> - <% internal_port = rule['internal_port'] || raise("Expected non-empty 'internal_port' on '#{rule.inspect}' rule") %> - - sudo iptables -t nat -A portforwarding-release -p tcp -d <%= spec.networks.send(spec.networks.methods(false).first).ip %> --dport <%= external_port %> -j DNAT --to <%= internal_ip %>:<%= internal_port %> + <% + external_ip = rule['external_ip'] || spec.address + external_port = rule['external_port'] || raise("Expected non-empty 'external_port' on '#{rule.inspect}' rule") + internal_ip = rule['internal_ip'] || "127.0.0.1" + internal_port = rule['internal_port'] || raise("Expected non-empty 'internal_port' on '#{rule.inspect}' rule") + -%> + sudo iptables -t nat -A portforwarding-release -p tcp -d <%= external_ip %> --dport <%= external_port %> -j DNAT --to <%= internal_ip %>:<%= internal_port %> <% if internal_ip == "127.0.0.1" %> sysctl net.ipv4.conf.all.route_localnet=1