Dynamic IP GRE Tunnel
Inviato: lun 25 giu , 2007 1:07 pm
Sperando di fare cosa gradita a qualcuno propongo una mia soluzione che consente di superare il problema degli ip dinamici con i tunnel GRE.
Si tratta di uno script TCL da copiare in flash:
#File tunnel.tcl
# Nome del file temporaneo
set _file_name "flash:old_ip.txt"
#Indirizzo dell'endpoint
set _endpoint ""
#Password Line Vty
set _password ""
#Password di Enable
set _enable ""
#Numero dell'interfaccia Tunnel sull'endpoint
set _t_num "20"
set _ints [ exec "show interfaces dialer 0 | include Internet" ]
set _ints_l [ split $_ints " " ]
set _ip_net [ lindex $_ints_l 5 ]
set _ip_l [ split $_ip_net "/" ]
set _ip [ lindex $_ip_l 0 ]
set _last_ip "0.0.0.0"
if { [ file exists $_file_name ] } {
set _file_r_handle [open $_file_name r]
gets $_file_r_handle _last_ip
close $_file_r_handle
}
if { $_ip != $_last_ip } {
if [catch {socket $_endpoint 23} _socket] {
file delete $_file_name
} else {
# set _socket [socket $_endpoint 23]
after 1000
puts $_socket "$_password"
flush $_socket
after 500
puts $_socket "enable"
flush $_socket
after 500
puts $_socket "$_enable"
flush $_socket
after 500
puts $_socket "configure terminal"
flush $_socket
after 500
puts $_socket "interface tunnel $_t_num"
flush $_socket
after 500
puts $_socket "tunnel destination $_ip"
flush $_socket
after 500
puts $_socket "exit"
flush $_socket
after 500
puts $_socket "exit"
flush $_socket
after 500
puts $_socket "exit"
flush $_socket
after 500
close $_socket
file delete $_file_name
set _file_w_handle [open $_file_name w]
puts $_file_w_handle $_ip
flush $_file_w_handle
close $_file_w_handle
}
}
#END
L'esecuzione di questo script viene effettuata automaticamente ogni 10 minuti pianificando lo scheduling con kron:
kron occurrence tunnel in 10 recurring
policy-list tunnel
!
kron policy-list tunnel
cli tclsh flash:tunnel.tcl
!
L'ip TUNNEL DESTINATIONdell'endpoint viene aggiornato automaticamente quando l'IP cambia.
E' graditissimo qualsiasi tipo di commento.
Si tratta di uno script TCL da copiare in flash:
#File tunnel.tcl
# Nome del file temporaneo
set _file_name "flash:old_ip.txt"
#Indirizzo dell'endpoint
set _endpoint ""
#Password Line Vty
set _password ""
#Password di Enable
set _enable ""
#Numero dell'interfaccia Tunnel sull'endpoint
set _t_num "20"
set _ints [ exec "show interfaces dialer 0 | include Internet" ]
set _ints_l [ split $_ints " " ]
set _ip_net [ lindex $_ints_l 5 ]
set _ip_l [ split $_ip_net "/" ]
set _ip [ lindex $_ip_l 0 ]
set _last_ip "0.0.0.0"
if { [ file exists $_file_name ] } {
set _file_r_handle [open $_file_name r]
gets $_file_r_handle _last_ip
close $_file_r_handle
}
if { $_ip != $_last_ip } {
if [catch {socket $_endpoint 23} _socket] {
file delete $_file_name
} else {
# set _socket [socket $_endpoint 23]
after 1000
puts $_socket "$_password"
flush $_socket
after 500
puts $_socket "enable"
flush $_socket
after 500
puts $_socket "$_enable"
flush $_socket
after 500
puts $_socket "configure terminal"
flush $_socket
after 500
puts $_socket "interface tunnel $_t_num"
flush $_socket
after 500
puts $_socket "tunnel destination $_ip"
flush $_socket
after 500
puts $_socket "exit"
flush $_socket
after 500
puts $_socket "exit"
flush $_socket
after 500
puts $_socket "exit"
flush $_socket
after 500
close $_socket
file delete $_file_name
set _file_w_handle [open $_file_name w]
puts $_file_w_handle $_ip
flush $_file_w_handle
close $_file_w_handle
}
}
#END
L'esecuzione di questo script viene effettuata automaticamente ogni 10 minuti pianificando lo scheduling con kron:
kron occurrence tunnel in 10 recurring
policy-list tunnel
!
kron policy-list tunnel
cli tclsh flash:tunnel.tcl
!
L'ip TUNNEL DESTINATIONdell'endpoint viene aggiornato automaticamente quando l'IP cambia.
E' graditissimo qualsiasi tipo di commento.