From c31f5616413231ad6cfc485f9502569866baf036 Mon Sep 17 00:00:00 2001 From: Pete Birley Date: Wed, 8 Jan 2020 14:19:59 -0600 Subject: [PATCH] Gate: Support AIO deployments when multiple default routes present This PS updates the gateway setup script to support deployments where multiple default routes may be present, eg when connecting to a vpn. Change-Id: I5fe86e9471ecb6a9c80e1e4f942822cac00da669 Signed-off-by: Pete Birley --- tools/deployment/developer/common/170-setup-gateway.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/deployment/developer/common/170-setup-gateway.sh b/tools/deployment/developer/common/170-setup-gateway.sh index f71c890007..c56231ba63 100755 --- a/tools/deployment/developer/common/170-setup-gateway.sh +++ b/tools/deployment/developer/common/170-setup-gateway.sh @@ -28,8 +28,10 @@ sudo ip link set br-ex up # VMs to reach the outside world correctly this needs to be set to ACCEPT. sudo iptables -P FORWARD ACCEPT -# Setup masquerading on default route dev to public subnet -DEFAULT_ROUTE_DEV="$(sudo ip -4 route list 0/0 | awk '{ print $5; exit }')" +# Setup masquerading on default route dev to public subnet by searching for the +# interface with default routing, if multiple default routes exist then select +# the one with the lowest metric. +DEFAULT_ROUTE_DEV=$(route -n | awk '/^0.0.0.0/ { print $5 " " $NF }' | sort | awk '{ print $NF; exit }') sudo iptables -t nat -A POSTROUTING -o ${DEFAULT_ROUTE_DEV} -s ${OSH_EXT_SUBNET} -j MASQUERADE # NOTE(portdirect): Setup DNS for public endpoints