IAT
******
Niveau : M2 SR Module : Solution de sauvegarde des Systèmes
Exercice 1
Szwitch 1 Szwitch 2
.2 .3
Szwitch 3
4
Szwitch 5
Szwitch 4
6
5
Reseau:
172.16.16.0/20
Machine [Python]
.1
Etape 1 : Adressage IP de VLAN 1 de chaque Switch et configuration d
conf t
int vlan 1
no shutdown
ip address 172.16.16.x 255.255.240.0
exit
username epn password epn
service password-encryption
enable password enp
secret password epn24
line vty 0 4
password epn
login local
transport input ssh
exit
ip domain-name EPN
crypto key generat rsa general modul 1024
do write
Etape 2 : Ecrire le script Python de configuration des switch, exécutable depuis la machine cliente. Ce script utilise le
module netmiko
Objectif : Vérifier la configuration SSH de chaque switch
from netmiko import ConnectHandler as H
r='172.16.16.'
for h in range(2,7):
cn={
'type_device':'cisco_ios',
'host':r+str(h),
'username':'epn',
'password':'epn',
'secret':'epn24',
'verbose':True,
}
cnS=H(**cn)
result=cnS.send_command('show run | section ssh')
print(result)
cnS.disconnect()
Exercice 2-
from netmiko import ConnectHandler as H
r='172.16.16.'
for h in range(2,7):
cn={
'type_device':'cisco_ios',
'host':r+str(h),
'username':'epn',
'password':'epn',
'secret':'epn24',
'verbose':True,
}
cnS=H(**cn)
cnS.enable()
f=open('bk.txt', 'a')
for i in range(2,11):
result=cnS.send_config_set('vlan %d' %i)
print(result)
cnS.disconnect()
f.close()
Exercice 3: configuration des consoles
from netmiko import ConnectHandler as H
r='172.16.16.'
for h in range(2,7):
cn={
'type_device':'cisco_ios',
'host':r+str(h),
'username':'epn',
'password':'epn',
'secret':'epn24',
'verbose':True,
}
cnS=H(**cn)
cnS.enable()
print(cnS.send_config_set(['line cons 0','login local','password epn','line aux
0','login local','password epn','do wr']))
cnS.disconnect()
exercice 4: config à partir du fichier
from netmiko import ConnectHandler as H
r='172.16.16.'
for h in range(2,7):
cn={
'type_device':'cisco_ios',
'host':r+str(h),
'username':'epn',
'password':'epn',
'secret':'epn24',
'verbose':True,
}
cnS=H(**cn)
cnS.enable()
cnS.send_config_from_file('fichier.txt')
cnS.disconnect()
TD 2
.2
.3
Reseau: 192.168.1.0/24
.4 .5
.1
.6 .7 .8
Distribution.txt :
int range e0/0 - 1
no sh
channel-group 1 mode on
int range e0/2 - 3
no sh
channel-group 2 mode on
int range e1/0 - 1
no sh
channel-group 3 mode on
int range po1 , po2 , po3 , e1/2 - 3 , e2/0
switchport encapsul dot1q
switchport mode trunk
switchport tr allowed vlan add 2-7
do write
access.txt
int range e0/0 - 1
no shut
switchport encapsul dot1q
switchport mode trunk
switchport tr allowed vlan add 2-7
do write
Travail demandé
1. Ecrire un script Python qui permet de.
a. Configurer la sécurité des consoles
b. Configurer le protocole VTP sur les switch 2 et 3
c. Configurer le trunc
d. Configurer le protocole LACP
from netmiko import ConnectHandler as H
r='192.168.1.'
for h in range(2,9):
cn={
'type_device':'cisco_ios',
'host':r+str(h),
'username':'epn',
'password':'epn',
'secret':'epn24',
'verbose':True,
}
cnS=H(**cn)
cnS.enable()
for i in range(2,7):
cnS.send_config_set('vlan %d' % i)
if h in [2,3,4,5]:
cnS.send_config_from_file('distribution.txt')
else:
cnS.send_config_from_file('access.txt')
cnS.disconnect()
Autre façon : Programmation fonctionnelle
from netmiko import ConnectHandler as H
def programmer(a,f):
cn={
'type_device':'cisco_ios',
'host':a,
'username':'epn',
'password':'epn',
'secret':'epn24',
'verbose':True,
}
cnS=H(**cn)
cnS.enable()
for i in range(2,7):
cnS.send_config_set('vlan %d' % i)
cnS.send_config_from_file(f)
cnS.disconnect()
r=’172.16.16.’
for i in(2,12):
programmer(r+str(i),’configSw.txt’)
Autre façon : utilisation de paramètres
from netmiko import ConnectHandler as H
def programmer(a,u,p,s,f):
cn={
'type_device':'cisco_ios',
'host':a,
'username':u,
'password':p,
'secret':s,
'verbose':True,
}
cnS=H(**cn)
cnS.enable()
for i in range(2,7):
cnS.send_config_set('vlan %d' % i)
cnS.send_config_from_file(f)
cnS.disconnect()
Exercice 6
Reseau: 192.168.1.0/24
.2
.3
e0/0 -1 .9
.10
e0/0 -1
e0/2 -3 e1/0 -1 e0/2 -3
e1/0 -1
e0/2 -3 e0/2 -3
.11
.4 e0/0 -1 .5
e2/0 e2/0 e1/2 e0/0 -1 .12
e1/2 e1/3 e1/3 .1
e1/2 e2/0 e2/0 e1/2
e1/3 e1/3
e0/0 e0/1
e0/0 e0/1 e0/2 e0/1
e0/1
e0/0 e0/0 e0/1 .14
e0/3 e0/0
e0/2
.6 .7 .8
.13
.2 .3
e0/0 -1 .6 .7
e0/0 -1
e1/0 -1
Roseau:
e0/2-3 e0/2-3 10.16.0.0/12 e1/0 -1
e0/2-3 e0/2-3
e2/0
e0/0 -1
e1/2 e0/0 -1
.4 .5 e1/3 e1/3 .9
.8 e1/2
.10 .11 e1/2
e0/0 -1 e1/3
.15
e0/0 -1
e2/0
.3
e1/0 -1 e1/0 -1
e0/2-3 e0/2-3 e0/2-3 e0/2-3
e0/0 -1
e0/0 -1
.12 .13
.16 . .17