3 # set IP MASQUERADE for listed devices
4 # this script must be set on the LAN gateway device
10 # IFACE physical name of the interface being processed
11 # METHOD method of the interface (e.g., static)
12 # MODE start if run from ifup, stop if run from ifdown
13 # PHASE as per MODE, but with finer granularity, distinguishing the pre-
14 # up, post-up, pre-down and post-down phases.
16 # optional argument to set default gateway devices connected to WAN manually
17 # (try each of them in order)
20 if [ "${PHASE}" = "post-down" ]; then
21 # flush POSTROUTING chain and exit
22 /sbin/iptables -t nat -F POSTROUTING
29 # wait for initialization of WAN device with DHCPd
32 if [ -z "${GATEWAYS}" ]; then
33 GATEWAYS=`/sbin/ip route show table main | grep -w default | tr -s ' ' | cut -d ' ' -f 5`
36 for GW in ${GATEWAYS}; do
37 if [ ${GW} = ${IFACE} ]; then
38 # skip if device is the LAN gateway
42 IPADDR=`/sbin/ip addr show dev ${GW} | grep -w inet | tr -s ' ' | cut -d ' ' -f 3 | cut -d / -f 1`
43 if [ -z "${IPADDR}" ]; then
44 # device doesn't seem to have an IP address
48 ## set masquerade rule to all devices
49 # because there is no way to know which one is default gateway
50 # without manual specification
51 /sbin/iptables -t nat -A POSTROUTING -o ${GW} -j MASQUERADE