Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
default external_ip to spec.address [thx @dpb587-pivotal]
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Mar 21, 2017
1 parent d349a25 commit 80ddd05
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions jobs/port_forwarding/templates/bin/forward_ports.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 80ddd05

Please sign in to comment.