File "iproute.sh"

Full path: /www/wwwroot/fabriciovc.eti.br/downloads/windows/ORGANIZAR/iproute.sh
File size: 2.2 KiB (2254 bytes)
MIME-type: text/x-shellscript
Charset: 8 bit

Download   Open   Back

#!/bin/sh

IP=`which ip`

if [ ! -x $IP ]; then
	exit 0
fi

NAME_LINK0="copel"
DEV_ETH_LINK0="eth0"
IP_LOCAL_LINK0="192.168.0.1"
GATEWAY_LINK0="192.168.0.254"
REDE_LOCAL_LINK0="192.168.0.0/24"

DEV_ETH_LINK1="eth0:1"
IP_LOCAL_LINK1="192.168.1.1"
GATEWAY_LINK1="192.168.1.254"
REDE_LOCAL_LINK1="192.168.1.0/24"

DEV_ETH_LINK2="eth0:2"
IP_LOCAL_LINK2="192.168.2.1"
GATEWAY_LINK2="192.168.2.254"
REDE_LOCAL_LINK2="192.168.2.0/24"

DEV_ETH_LINK3="eth0:3"
IP_LOCAL_LINK3="192.168.3.1"
GATEWAY_LINK3="192.168.3.254"
REDE_LOCAL_LINK3="192.168.3.0/24"

start() {

# Configuração de roteamento para o link 0
  $IP rule add from $IP_LOCAL_LINK0 table $NAME_LINK0
  $IP route add $REDE_LOCAL_LINK0 dev $DEV_ETH_LINK0 table $NAME_LINK0
  $IP route add 0.0.0.0/0 via $GATEWAY_LINK0 dev $DEV_ETH_LINK0 table $NAME_LINK0

# Configuração de roteamento para o link 1
  $IP rule add from $IP_LOCAL_LINK1 table $NAME_LINK1
  $IP route add $REDE_LOCAL_LINK1 dev $DEV_ETH_LINK1 table $NAME_LINK1
  $IP route add 0.0.0.0/0 via $GATEWAY_LINK1 dev $DEV_ETH_LINK1 table $NAME_LINK1

# Configuração de roteamento para o link 2
  $IP rule add from $IP_LOCAL_LINK2 table $NAME_LINK2
  $IP route add $REDE_LOCAL_LINK2 dev $DEV_ETH_LINK2 table $NAME_LINK2
  $IP route add 0.0.0.0/0 via $GATEWAY_LINK2 dev $DEV_ETH_LINK2 table $NAME_LINK2

# Configuração de roteamento para o link 3 (Default)
  $IP rule add from $IP_LOCAL_LINK3 table $NAME_LINK3
  $IP route add $REDE_LOCAL_LINK3 dev $DEV_ETH_LINK3 table $NAME_LINK3
  $IP route add 0.0.0.0/0 via $GATEWAY_LINK3 dev $DEV_ETH_LINK3 table $NAME_LINK3

  echo Feito!
}

stop() {
  /sbin/ip rule del from $IP_LOCAL_LINK0
  /sbin/ip rule del from $IP_LOCAL_LINK1
  /sbin/ip rule del from $IP_LOCAL_LINK2
  /sbin/ip rule del from $IP_LOCAL_LINK3
  /sbin/ip route flush table $NAME_LINK0
  /sbin/ip route flush table $NAME_LINK1
  /sbin/ip route flush table $NAME_LINK2
  /sbin/ip route flush table $NAME_LINK3
}

case "$1" in
  start)
    start ;;

  stop)
    stop ;;

  restart|reload)
    stop ; start ;;

  status)
    echo "Regras";
    $IP rule ls;
    echo .;
    echo "Tabela $NAME_LINK3";
    $IP route ls table $NAME_LINK3;
    echo .;
    ;;
  *)
    echo "Usage: %s {start|stop|restart|status}\n"
    exit 1
    ;;
esac

exit 0

PHP File Manager