net/templates/run.sh: tweak masquerade

Replace the old check with an exact check for the given rule. The old
check doesn't work on my system if docker is running and sets up other
masquerading rules.

Change -A to -I, so it is less likely to be affected by whatever other
rules may already be above in the chain.

Change-Id: I30c22fe4e7683611e8dada329dbf7d51f78b6016
This commit is contained in:
Oliver Smith 2021-07-07 16:40:36 +02:00 committed by osmith
parent 1276bf2c1a
commit 4186b95259
1 changed files with 3 additions and 2 deletions

View File

@ -13,8 +13,9 @@ apn="${APN_DEV}"
sudo true || exit 1
if [ -z "$(sudo iptables -L -t nat | grep MASQUERADE)" ]; then
sudo iptables -t nat -A POSTROUTING -s ${GGSN_NET} -o $dev -j MASQUERADE
if ! sudo iptables -t nat -C POSTROUTING -s ${GGSN_NET} -o $dev -j MASQUERADE 2>/dev/null; then
echo "Adding iptables rule for masquerade"
sudo iptables -t nat -I POSTROUTING -s ${GGSN_NET} -o $dev -j MASQUERADE
fi
if [ "$(sudo cat /proc/sys/net/ipv4/ip_forward)" = "0" ]; then