Changeset 16 in lab
- Timestamp:
- Jul 7, 2009 7:33:04 PM (16 years ago)
- Location:
- trunk/iptables
- Files:
-
- 1 added
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/iptables/setmasq.sh
r15 r16 1 1 #!/bin/sh 2 2 3 # set IP MASQUERADE for listed devices 4 # this script must be set on the LAN gateway device 3 # set IP MASQUERADE with post-up command in INTERFACES(5) 5 4 6 5 … … 16 15 # optional argument to set default gateway devices connected to WAN manually 17 16 # (try each of them in order) 18 GATEWAYS="$@"19 17 20 18 if [ "${PHASE}" = "post-down" ]; then 21 # flush POSTROUTING chainand exit22 /sbin/iptables -t nat - F POSTROUTING19 # remove MASQUERADE rule and exit 20 /sbin/iptables -t nat -D POSTROUTING -o ${IFACE} -j MASQUERADE 23 21 exit 24 22 fi 25 23 26 24 27 ( 28 29 # wait for initialization of WAN device with DHCPd 30 sleep 60 31 32 if [ -z "${GATEWAYS}" ]; then 33 GATEWAYS=`/sbin/ip route show table main | grep -w default | tr -s ' ' | cut -d ' ' -f 5` 34 fi 35 36 for GW in ${GATEWAYS}; do 37 if [ ${GW} = ${IFACE} ]; then 38 # skip if device is the LAN gateway 39 continue 40 fi 41 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 45 continue 46 fi 47 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 52 done 53 54 ) & 25 # set MASQUERADE rule 26 /sbin/iptables -t nat -A POSTROUTING -o ${IFACE} -j MASQUERADE
Note: See TracChangeset
for help on using the changeset viewer.