Policyrouting Script

Bitte loggen sie sich ein oder registrieren sie sich.

Einloggen mit Benutzername, Passwort und Sitzungslänge
Erweiterte Suche  

Autor Thema: Policyrouting Script  (Gelesen 2171 mal)

0 Mitglieder und 1 Gast betrachten dieses Thema.

Ralf

  • Grünschnabel
  • *
  • Offline Offline
  • Beiträge: 25
Policyrouting Script
« am: 21.August 2009, 01:31:35 »

Hallo,

da Rescue System usw. ohne Probleme funktioniert, hat Euserv empfohlen ein Policyrouting Skript zu starten um die zusätzlichen IP Adresse mit anderem Broadcast einzuschalten. (Dual Broadcast).

Nun in der /etc/network/interfaces

# auto-generated system-config
# part of KDCTRL-NOC and FADC
auto lo eth0
iface lo inet loopback
iface eth0 inet static
address 91.143.81.xxx
netmask 255.255.255.0
broadcast 91.143.81.255
gateway 91.143.81.1
dns-nameservers 85.31.184.6 85.31.185.126 85.31.184.7

steht die orginal IP des Servers die auch im Kundenmenü steht...

Nun habe ich ein /etc/init.d/policyrouting Skript um die eine andere IP einzuschalten..

#!/bin/sh
#
#/etc/init.d/policyrouting
###BEGIN INIT INFO
# Provides: policyRouting
# Required-Start: $network
# Required-Stop:
# Default-Start: 3 5
# Default-Stop:
# Description: Set up policy based routing
### END INIT INFO

#Secondary Gateway and IP address
GATEWAY2="81.89.96.xxx"
MYIP2="81.89.96.xxx"
NETMASK="255.255.255.xxx"
BROADCAST="81.89.96.xxx"
INTERFACE="eth0"

case "$1" in
        start)
               ifconfig eth0:5 $MYIP2 netmask $NETMASK broadcast $BROADCAST
                echo -n "Starting policy-based routing"
                ip route list | grep -v default | while read a; do ip route add table 1 $a; done
                ip route add table 1 default via $GATEWAY2 dev $INTERFACE
                ip rule add from $MYIP2 table 1 priority 10000
                echo
                ;;
        stop)
                ip rule delete from $MYIP2 table 1 priority 10000
                ip route flush table 1
                ifconfig eth0:5 down
                echo
                ;;
        restart|reload|force-reload)
                $0 stop
                $0 start
                ;;
        *)
                echo "Usage: $0 {start|stop|restart}"
                exit 1
                ;;
esac

Das funtioniert auch wunderbar!! Wenn ich nur 2 IP habe also die originale und eine weitere..

Nun zu meiner Frage wie passe ich das /etc/init.d/policyrouting Skript an wenn ich 2 weitere IP hinzufügen will.

Also ingesamt dann 4 scharf geschaltet habe??

Wie gesagt EuServ empfiehlt nicht eine andere Broadcast Adresse in der /etc/network/interfaces zu schreiben. Dafür soll dieses Script sein was ich auch von Euserv habe..

Hat einer eine Idee we das Start Skript angepasst werden muss damit weitere IP zugeschaltet werden können

/etc/network/interfaces   Standart IP mit Broadcast Adresse A

/etc/init.d/policyrouting   3 weitere IP Adressen mit der gleichen Broadcast Adresse B (andere als /etc/network/interfaces )

Gruß

Ralf
Gespeichert


timo

  • Gast
Re: Policyrouting Script
« Antwort #1 am: 21.August 2009, 10:40:17 »

Hallo,

ich hoffe es passt so, siehe Code Abschnitt. Ich habe auch die normalen Parameter etwas angepaßt (NETMASK ist nun NETMASK2 und BROADCAST ist BROADCAST2).

Es werden dann neben der default Routing Tabelle 0 , die Routing Tabellen 1 ,2, 3 angelegt.

#!/bin/sh
#
#/etc/init.d/policyrouting
###BEGIN INIT INFO
# Provides: policyRouting
# Required-Start: $network
# Required-Stop:
# Default-Start: 3 5
# Default-Stop:
# Description: Set up policy based routing
### END INIT INFO

#Secondary Gateway and IP address
INTERFACE="eth0"
GATEWAY2="81.89.96.xxx"
MYIP2="81.89.96.xxx"
NETMASK2="255.255.255.xxx"
BROADCAST2="81.89.96.xxx"

GATEWAY3="81.89.96.xxx"
MYIP3="81.89.96.xxx"
NETMASK3="255.255.255.xxx"
BROADCAST3="81.89.96.xxx"

GATEWAY4="81.89.96.xxx"
MYIP4="81.89.96.xxx"
NETMASK4="255.255.255.xxx"
BROADCAST4="81.89.96.xxx"


case "$1" in
        start)
# 1. ZusatzIP (table 1)
               ifconfig eth0:5 $MYIP2 netmask $NETMASK2 broadcast $BROADCAST2
                echo -n "Starting policy-based routing #1"
                ip route list | grep -v default | while read a; do ip route add table 1 $a; done
                ip route add table 1 default via $GATEWAY2 dev $INTERFACE
                ip rule add from $MYIP2 table 1 priority 10000
# 2. ZusatzIP (table 2)
               ifconfig eth0:6 $MYIP3 netmask $NETMASK3 broadcast $BROADCAST3
                echo -n "Starting policy-based routing #2"
                ip route list | grep -v default | while read a; do ip route add table 2 $a; done
                ip route add table 2 default via $GATEWAY3 dev $INTERFACE
                ip rule add from $MYIP3 table 2 priority 10000
# 3. ZusatzIP (table 3)
               ifconfig eth0:7 $MYIP4 netmask $NETMASK4 broadcast $BROADCAST4
                echo -n "Starting policy-based routing #3"
                ip route list | grep -v default | while read a; do ip route add table 3 $a; done
                ip route add table 3 default via $GATEWAY4 dev $INTERFACE
                ip rule add from $MYIP3 table 3 priority 10000
                ;;
        stop)
                ip rule delete from $MYIP2 table 1 priority 10000
                ip route flush table 1
                ifconfig eth0:5 down
                ip rule delete from $MYIP3 table 2 priority 10000
                ip route flush table 2
                ifconfig eth0:6 down
                ip rule delete from $MYIP4 table 3 priority 10000
                ip route flush table 3
                ifconfig eth0:7 down

                ;;
        restart|reload|force-reload)
                $0 stop
                $0 start
                ;;
        *)
                echo "Usage: $0 {start|stop|restart}"
                exit 1
                ;;
esac

Gruß Timo,
Gespeichert
 

Seite erstellt in 0.094 Sekunden mit 21 Abfragen.