Introduzione
In questo documento viene descritta la configurazione e il provisioning dello ZTP (Zero Touch Provisioning) sugli switch Cisco Catalyst serie 9000.
Prerequisiti
Requisiti
Cisco raccomanda la conoscenza dei seguenti argomenti:
- Configurazione del server DHCP (Dynamic Host Configuration Protocol) sullo switch
- Nozioni di base sul codice Python
- Nozioni fondamentali sul servizio HTTP/TFTP
Requisiti di licenza
- Network Advantage o Network Essentials License devono essere attivi.
Piattaforme supportate
- Switch Catalyst serie 9300 con versione 16.5.1a
- Switch Catalyst serie 9500 con versione 16.5.1a
- Switch Catalyst serie 9400 con versione 16.6.2
Nota: Questa funzionalità non è supportata in C9600.
Componenti usati
Le informazioni fornite in questo documento si basano sulle seguenti versioni software e hardware:
- Cisco Catalyst 9300 switch su Cisco IOS® XE 17.6.4
- Cisco Catalyst 3850 funziona come server DHCP con configurazione opzione 67
- L'host finale installato con il servizio HTTP contiene un file Python.
Le informazioni discusse in questo documento fanno riferimento a dispositivi usati in uno specifico ambiente di emulazione. Su tutti i dispositivi menzionati nel documento la configurazione è stata ripristinata ai valori predefiniti. Se la rete è operativa, valutare attentamente eventuali conseguenze derivanti dall'uso dei comandi.
Premesse
Lo ZTP (Zero Touch Provisioning) viene utilizzato per effettuare il provisioning dei dispositivi di rete accuratamente in pochi minuti e senza alcun intervento manuale.
Esempio di rete
Configurazione e procedure di base di Zero Touch Provisioning
Operazione ZTP (procedure dettagliate)
Quando viene introdotto nella rete esistente, lo ZTP automatizza la configurazione degli switch Catalyst serie 9000 senza alcuna configurazione di avvio. Ciò avviene senza alcun intervento manuale. Di seguito sono illustrate le procedure dettagliate.
Passaggio 1. Collegamento del nuovo switch
Collegare un nuovo switch all'infrastruttura esistente e accendere il dispositivo. Lo switch viene avviato senza alcuna configurazione di avvio.
Passaggio 2. Avvio ZTP
Il processo ZTP viene avviato automaticamente dallo switch.
Passaggio 3. Richiesta DHCP
Lo switch invia un messaggio di individuazione DHCP.
Passaggio 4. Risposta DHCP
Il server DHCP risponde con un'offerta che include l'opzione 67, con IP e URL del server HTTP.
Passaggio 5. URL HTTP
Lo switch riceve l'offerta e riceve un indirizzo IP per le proprie comunicazioni. Riceve inoltre l'indirizzo IP del server HTTP e l'URL completo per scaricare il file ZTP.py.
Passaggio 6. Download
Lo switch raggiunge il server HTTP e scarica il ZTP.py file.
Passaggio 7. Guestshell
Lo switch attiva automaticamente la shell guest.
Passaggio 8. Distribuzione delle configurazioni
Lo switch esegue il file Python e le configurazioni vengono applicate automaticamente.
Passaggio 9. Operazioni riuscite
Lo switch elimina la shell del guest e viene visualizzato il script execution is a success messaggio.
Configurazione
Impostazione del servizio HTTP
Passaggio 1. Installare il servizio HTTP nell'host finale (esempio: Linux)
sudo apt update
sudo apt install apache2
Passaggio 2. Creare il file Python ztp_http.py
Se si verificano problemi di autorizzazione, utilizzare chmod 777 per concedere autorizzazioni complete per il file.
Il file Python contiene il codice costituito dalle seguenti attività:
1. Mostra comandi.
2. Configurazione loopback.
3. Verifica della configurazione.
Codice Python:
#Importing cli module
import cli
print "\n\n Running show version \n\n"
cli.executep('show version')
print "\n\n Configure a Loopback Interface \n\n"
cli.configurep(["interface loop 25", "ip address 192.168.0.25 255.255.255.255", "end"])
print "\n\n Running show ip interface brief \n\n"
cli.executep('show ip int brief | i up')
print "\n\n ZTP is success \n\n"
Percorso del file Python.
vm: /var/www/html$ ls -l ztp_http.py
-rwxrwxrwx 1 root root 346 Apr 04 14:14 ztp_http.py
Questo file deve essere archiviato in /var/www/html nel computer Linux.
Passaggio 3. Verificare il servizio HTTP e la porta di ascolto
Utilizzare il comando service per verificare se il servizio HTTP è stato avviato e se è in esecuzione.
vm: /var/www/html$ sudo service apache2 status
Active: active (running)
Verificare la porta di ascolto del servizio HTTP.
vm: /var/www/html$ sudo netstat -anp | grep apache
tcp6 0 :::80 :::* LISTEN 1998/apache2 <<<< Listens at 80
Passaggio 4. Verifica browser del numero di porta
Verificare se il file può essere scaricato tramite il browser Web.
1. Aprire un browser all'interno dello stesso computer (ad esempio, Linux).
2. Inserisci questo URL nella barra di ricerca: localhost:80/ztp_http.py
3. Il file viene scaricato automaticamente.
Configura servizio DHCP
Passaggio 1. Configurazione dell'interfaccia di provisioning (nuovo dispositivo)
Il nuovo switch deve essere collegato a G1/0/1.
enable
configure terminal
interface g1/0/1
description New_9300_switch
switchport
switchport mode access
switchport access vlan 1
Passaggio 2. Configurare l'interfaccia connessa del server HTTP
Il server HTTP (Linux) è collegato direttamente allo switch 3850 (ad esempio, l'interfaccia G1/0/2).
enable
configure terminal
interface g1/0/2
description Linux_is_connected_here
switchport
switchport mode access
switchport access vlan 1
Passaggio 3. Configurare l'ambito DHCP
Esempio di configurazione del pool DHCP con l'opzione 67.
enable
configure terminal
ip dhcp pool ZTP_Pool
network 10.0.0.0 255.255.255.0
default-router 10.0.0.1
option 67 ascii http://10.0.0.2:80/ztp_http.py
end
Verifica
Attualmente non è disponibile una procedura di verifica per questa configurazione.
Log della console di lavoro
No startup-config, starting autoinstall/pnp/ztp...
Autoinstall will terminate if any input is detected on console
--- System Configuration Dialog ---
Would you like to enter the initial configuration dialog? [yes/no]: <<<< Do not provide any input during this time.
Autoinstall trying DHCPv6 on Vlan1
Autoinstall trying DHCPv4 on Vlan1
Acquired IPv4 address 10.0.0.10 on Interface Vlan1
Received following DHCPv4 options:
bootfile : http://10.0.0.2:80/ztp_http.py
stop Autoip process
OK to enter CLI now...
pnp-discovery can be monitored without entering enable mode
Entering enable mode will stop pnp-discovery
Attempting bootfile http://10.0.0.2:80/ztp_http.py
Loading http://10.0.0.2:80/ztp_http.py
Loading http://10.0.0.2:80/ztp_http.py day0guestshell activated successfully
Current state is: ACTIVATED
day0guestshell started successfully
Current state is: RUNNING
Guestshell enabled successfully
Running show version <<<< show command executed
Cisco IOS XE Software, Version 17.06.04
Cisco IOS Software [Bengaluru], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 17.6.4, RELEASE SOFTWARE (fc1)
<snipped>
Model Number : C9300L-48T-4X
System Serial Number : FOC2531LGM8
CLEI Code Number :
Switch Ports Model SW Version SW Image Mode
------ ----- ----- ---------- ---------- ----
* 1 53 C9300L-48T-4X 17.06.04 CAT9K_IOSXE BUNDLE
Configure a Loopback interface <<<< configuration
Line 1 SUCCESS: interface loop 25
Line 2 SUCCESS: ip address 192.168.0.25 255.255.255.255
Line 3 SUCCESS: end
Running show ip int brief <<<< Config Verification
Vlan1 10.0.0.10 YES DHCP up up
Vlan4094 192.168.2.1 YES manual up down
GigabitEthernet0/0 unassigned YES unset up up
GigabitEthernet1/0/2 unassigned YES unset up up
GigabitEthernet1/0/3 unassigned YES unset up up
Ap1/0/1 unassigned YES unset up up
Loopback25 192.168.0.25 YES other up up
ZTP is success
Guestshell destroyed successfully
Script execution success! <<<< Success
Risoluzione dei problemi
In questa sezione vengono fornite informazioni utili per risolvere i problemi di configurazione.
Problemi comuni
Sulla rete è presente un altro server DHCP
No startup-config, starting autoinstall/pnp/ztp...
Autoinstall will terminate if any input is detected on console
--- System Configuration Dialog ---
Would you like to enter the initial configuration dialog? [yes/no]:
Autoinstall trying DHCPv6 on Vlan1
Autoinstall trying DHCPv4 on Vlan1
Acquired IPv4 address 192.168.45.117 on Interface Vlan1 <<<< Gets Different IP from another DHCP server.
Received following DHCPv4 options:
hostname : Switch
stop Autoip process
OK to enter CLI now...
pnp-discovery can be monitored without entering enable mode
Entering enable mode will stop pnp-discovery
Guestshell destroyed successfully
stop Autoip process
% Please answer 'yes' or 'no'.
Would you like to enter the initial configuration dialog? [yes/no]: no
Errore codice Python
--- System Configuration Dialog ---
Would you like to enter the initial configuration dialog? [yes/no]:
Autoinstall trying DHCPv6 on Vlan1
Autoinstall trying DHCPv4 on Vlan1
Acquired IPv4 address 10.106.37.69 on Interface Vlan1
Received following DHCPv4 options:
bootfile : http://10.106.37.59:80/ztp_http.py
stop Autoip process
OK to enter CLI now...
pnp-discovery can be monitored without entering enable mode
Entering enable mode will stop pnp-discovery
Attempting bootfile http://10.106.37.59:80/ztp_http.py
Loading http://10.106.37.59:80/ztp_http.py
Loading http://10.106.37.59:80/ztp_http.py day0guestshell activated successfully
Current state is: ACTIVATED
day0guestshell started successfully
Current state is: RUNNING
Guestshell enabled successfully
File "/bootflash/guest-share/downloaded_script.py", line 1
print "\n\n Running show version \n\n"
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("\n\n Running show version \n\n")? <<<< Code Error
Guestshell destroyed successfully
Script execution success!
Numero porta servizio HTTP
Il servizio HTTP è in ascolto su diverse porte, ad esempio 8080, ma la configurazione DHCP dell'opzione 67 punta a 80.
enable
configure terminal
ip dhcp excluded-address 10.0.0.2
ip dhcp pool ZTP_Pool
network 10.0.0.0 255.255.255.0
default-router 10.0.0.1
option 67 ascii http://10.0.0.2:80/ztp_http.py <<<< Change to 8080
Indirizzo IP duplicato
Verificare l'ambito DHCP ed escludere l'indirizzo IP assegnato al server HTTP.
enable
configure terminal
ip dhcp excluded-address 10.0.0.2 <<<< Exclude HTTP server address.
ip dhcp pool ZTP_Pool
network 10.0.0.0 255.255.255.0
default-router 10.0.0.1
option 67 ascii http://10.0.0.2:80/ztp_http.py
Verifica servizio HTTP, Arresta e Riavvia
vm: /var/www/html$ sudo service apache2 stop
vm: /var/www/html$ sudo service apache2 start
vm: /var/www/html$ sudo service apache2 status
Esempi di dettagli dei pacchetti
Riepilogo scambio HTTP:
10.0.0.10 10.0.0.2 HTTP 183 GET /http_ztp.py HTTP/1.1 <<<< HTTPGETrequest
10.0.0.2 10.0.0.10 HTTP 245 HTTP/1.1 200 OK (text/x-python) <<<< Response
Risposta HTTP dettagliata:
Hypertext Transfer Protocol
HTTP/1.1 200 OK\r\n
Content-Type: text/x-python\r\n
Content-Length: 20\r\n
Date: Tue, 04 Apr 2023 12:24:02 GMT\r\n
Connection: keep-alive\r\n
Keep-Alive: timeout=5\r\n
\r\n
[HTTP response 1/2]
[Time since request: 0.204568243 seconds]
[Request in frame: 21]
[Next request in frame: 25]
[Next response in frame: 26]
[Request URI: http://10.0.0.2:80/http_ztp.py] >>>> URL