Changeset 16 in lab


Ignore:
Timestamp:
Jul 7, 2009 7:33:04 PM (15 years ago)
Author:
mitty
Message:
  • setlan2wan.sh
  • setmasq.sh
    • replacement for setnapt.sh
Location:
trunk/iptables
Files:
1 added
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/iptables/setmasq.sh

    r15 r16  
    11#!/bin/sh 
    22 
    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) 
    54 
    65 
     
    1615# optional argument to set default gateway devices connected to WAN manually 
    1716# (try each of them in order) 
    18 GATEWAYS="$@" 
    1917 
    2018if [ "${PHASE}" = "post-down" ]; then 
    21     # flush POSTROUTING chain and exit 
    22     /sbin/iptables -t nat -F POSTROUTING 
     19    # remove MASQUERADE rule and exit 
     20    /sbin/iptables -t nat -D POSTROUTING -o ${IFACE} -j MASQUERADE 
    2321    exit 
    2422fi 
    2523 
    2624 
    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.