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

Commit

Permalink
always allow loopback access to forwared ports
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Dec 22, 2017
1 parent 80ddd05 commit ac65b4a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions jobs/port_forwarding/templates/bin/forward_ports.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ fi

iptables -F ${CHAIN} || true

# Reset in case when there is no localhost routing
sysctl net.ipv4.conf.all.route_localnet=0
sysctl net.ipv4.conf.all.route_localnet=1

<% p("networking.port_forwarding").each do |rule| %>
<%
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")
-%>
%>
# external clients
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
<% end %>
# loopback
sudo iptables -t nat -A portforwarding-release -p tcp -d 127.0.0.1 --dport <%= external_port %> -j DNAT --to <%= internal_ip %>:<%= internal_port %> -o lo

<% end %>

0 comments on commit ac65b4a

Please sign in to comment.