Installazione software · 6 min read · Nov 19, 2025

Come installare NetBox Strumento di Documentazione e Gestione della Rete su Ubuntu 20.04 LTS

Netbox è uno strumento gratuito e potente per la gestione degli indirizzi IP (IPAM) e dell’infrastruttura del datacenter (DCIM). Viene utilizzato per memorizzare informazioni sulle tue reti, VM, inventari e molto altro. È stato originariamente sviluppato dal team di ingegneria di rete di DigitalOcean. Questo strumento è scritto nel framework Django Python e si basa sul database PostgreSQL. Il suo obiettivo è funzionare come una fonte di verità specifica per le operazioni di rete.

In questo tutorial, spiegheremo come installare Netbox con Nginx come proxy inverso su Ubuntu 20.04.

Prerequisiti

  • Un server che esegue Ubuntu 20.04.
  • Una password di root configurata sul tuo server.

Iniziare

Prima di iniziare, dovrai installare alcune dipendenze richieste da Netbox. Puoi installarle tutte eseguendo il seguente comando:

apt-get install nginx git gcc supervisor python3 python3-dev python3-pip python3-setuptools build-essential libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev libssl-dev zlib1g-dev -y

Una volta installati tutti i pacchetti, puoi procedere al passaggio successivo.

Installare e Configurare il Database PostgreSQL

Netbox si basa sul database PostgreSQL per la memorizzazione dei dati. Puoi installarlo con il seguente comando:

apt-get install postgresql postgresql-contrib -y

Una volta installato PostgreSQL, accedi a PostgreSQL con il seguente comando:

su - postgres  
postgres@ubuntu2004:~$ psql

Dovresti ottenere il seguente output:

psql (12.2 (Ubuntu 12.2-4))
Type "help" for help.

Successivamente, crea un database e un utente per Netbox con il seguente comando:

postgres=# CREATE DATABASE netbox;  
postgres=# CREATE USER netbox WITH PASSWORD 'password';

Successivamente, concedi tutti i privilegi al database Netbox con il seguente comando:

postgres=# GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;

Successivamente, esci dalla shell di PostgreSQL con il seguente comando:

postgres=# exit  
postgres@ubuntu2004:~$ exit

Installare e Configurare NetBox

Per prima cosa, cambia la directory in /opt e scarica l’ultima versione di Netbox dal repository Git Hub utilizzando il seguente comando:

cd /opt/  
git clone -b master https://github.com/digitalocean/netbox.git

Successivamente, crea un collegamento simbolico del binario Python con il seguente comando:

ln -s /usr/bin/python3 /usr/bin/python

Successivamente, cambia la directory in /opt/netbox/netbox/ e genera la chiave segreta di Django eseguendo il seguente comando:

cd /opt/netbox/netbox/  
./generate_secret_key.py

Dovresti ottenere il seguente output:

wcq@L2)eTDpo(k^f4Sm9bariUnK0syCPMGEIjW6XV_8l5xhB7z

Successivamente, cambia la directory in netbox e rinomina il file di configurazione di esempio:

cd netbox  
mv configuration.example.py configuration.py

Successivamente, modifica il file di configurazione di Netbox e definisci il tuo database, la chiave segreta e gli host consentiti:

nano configuration.py

Apporta le seguenti modifiche:

ALLOWED_HOSTS = ['your-server-ip']

# Configurazione del database PostgreSQL. Vedi la documentazione di Django per un elenco completo dei parametri disponibili:
#   https://docs.djangoproject.com/en/stable/ref/settings/#databases
DATABASE = {
    'NAME': 'netbox',         # Nome del database
    'USER': 'netbox',               # Nome utente PostgreSQL
    'PASSWORD': 'password',           # Password PostgreSQL
    'HOST': 'localhost',      # Server del database
    'PORT': '',               # Porta del database (lascia vuoto per predefinito)
    'CONN_MAX_AGE': 300,      # Età massima della connessione al database
}

SECRET_KEY = 'wcq@L2)eTDpo(k^f4Sm9bariUnK0syCPMGEIjW6XV_8l5xhB7z'

Salva e chiudi il file, quindi installa tutte le dipendenze Python con il seguente comando:

pip3 install -r /opt/netbox/requirements.txt

Successivamente, migra il database con il seguente comando:

cd /opt/netbox/netbox/  
python3 manage.py migrate

Successivamente, crea un utente amministrativo di Netbox con il seguente comando:

python3 manage.py createsuperuser

Ti verrà chiesto di fornire nome utente e password come mostrato di seguito:

Username (leave blank to use 'root'): netboxadmin
Email address: [email protected]
Password: 
Password (again): 
Superuser created successfully.

Successivamente, raccogli i file statici con il seguente comando:

python3 manage.py collectstatic

Dovresti vedere il seguente output:

976 static files copied to '/opt/netbox/netbox/static'.

Installare e Configurare Gunicorn

Netbox è un’applicazione basata su Django. Quindi dovrai installare Gunicorn nel tuo sistema. Puoi installarlo eseguendo il seguente comando:

pip3 install gunicorn

Dopo aver installato Gunicorn, crea un nuovo file di configurazione di Gunicorn per Netbox con il seguente comando:

nano /opt/netbox/gunicorn_config.py

Aggiungi le seguenti righe:

command = '/usr/local/bin/gunicorn'
pythonpath = '/opt/netbox/netbox'
bind = 'your-server-ip:8001'
workers = 3
user = 'www-data'

Salva e chiudi il file quando hai finito.

Installare e Configurare Supervisor

Supervisor è un sistema client/server che ti consente di monitorare e controllare il servizio NetBox. Puoi creare un nuovo file di configurazione di Supervisor per Netbox con il seguente comando:

nano /etc/supervisor/conf.d/netbox.conf

Aggiungi le seguenti righe:

[program:netbox]
command = gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
directory = /opt/netbox/netbox/
user = www-data

Salva e chiudi il file quando hai finito. Quindi, riavvia il servizio Supervisor con il seguente comando:

systemctl restart supervisor

Puoi anche verificare lo stato del servizio Supervisor utilizzando il seguente comando:

systemctl status supervisor

Dovresti ottenere il seguente output:

? supervisor.service - Sistema di controllo dei processi Supervisor per UNIX
     Loaded: loaded (/lib/systemd/system/supervisor.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-05-30 05:49:08 UTC; 14s ago
       Docs: http://supervisord.org
   Main PID: 550606 (supervisord)
      Tasks: 5 (limit: 4691)
     Memory: 184.3M
     CGroup: /system.slice/supervisor.service
             ??550606 /usr/bin/python3 /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
             ??550626 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
             ??550628 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
             ??550629 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
             ??550630 /usr/bin/python3 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi

May 30 05:49:08 ubuntu2004 systemd[1]: Started Supervisor process control system for UNIX.
May 30 05:49:08 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:08,664 CRIT Supervisor is running as root.  Privileges were not dropped becau>
May 30 05:49:08 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:08,664 INFO Included extra file "/etc/supervisor/conf.d/netbox.conf" during p>
May 30 05:49:08 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:08,671 INFO RPC interface 'supervisor' initialized
May 30 05:49:08 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:08,671 CRIT Server 'unix_http_server' running without any HTTP authentication>
May 30 05:49:08 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:08,672 INFO supervisord started with pid 550606
May 30 05:49:09 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:09,676 INFO spawned: 'netbox' with pid 550626
May 30 05:49:11 ubuntu2004 supervisord[550606]: 2020-05-30 05:49:11,060 INFO success: netbox entered RUNNING state, process has stayed up for

Configurare Nginx per NetBox

È una buona idea configurare Nginx come proxy inverso per accedere a Netbox sulla porta 80. Puoi creare una nuova configurazione di host virtuale Nginx utilizzando il seguente comando:

nano /etc/nginx/sites-available/netbox.conf

Aggiungi le seguenti righe:

server {
    listen 80;
    server_name your-server-ip;
    client_max_body_size 25m;

    location /static/ {
        alias /opt/netbox/netbox/static/;
    }

    location / {
        proxy_pass http://your-server-ip:8001;
    }
}

Salva e chiudi il file. Quindi, crea un collegamento simbolico alla directory /etc/nginx/sites-enabled/:

ln -s /etc/nginx/sites-available/netbox.conf /etc/nginx/sites-enabled/

Successivamente, verifica Nginx per eventuali errori di sintassi con il seguente comando:

ginx -t

Se tutto è a posto, dovresti ottenere il seguente output:

ginx: the configuration file /etc/nginx/nginx.conf syntax is ok
ginx: configuration file /etc/nginx/nginx.conf test is successful

Infine, riavvia il servizio Nginx per implementare le modifiche.

systemctl restart nginx

Puoi anche verificare lo stato di Nginx con il seguente comando:

systemctl status nginx

Dovresti ottenere il seguente output:

? nginx.service - Il server HTTP e proxy inverso nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-05-30 22:28:13 EST; 4min 14s ago
  Process: 984 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 982 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 980 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 985 (nginx)
    Tasks: 3 (limit: 25028)
   Memory: 5.5M
   CGroup: /system.slice/nginx.service
           ??985 nginx: master process /usr/sbin/nginx
           ??986 nginx: worker process
           ??987 nginx: worker process

May 30 21:28:12 ubuntu2004 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Mar 30 21:28:12 ubuntu2004 nginx[982]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar 30 21:28:12 ubuntu2004 nginx[982]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar 30 21:28:13 ubuntu2004 systemd[1]: Started The nginx HTTP and reverse proxy server.

A questo punto, il server web Nginx è configurato per servire Netbox sulla porta 80. Puoi ora procedere ad accedere all’interfaccia web di Netbox.

Accedere all’Interfaccia Web di Netbox

Apri il tuo browser web e visita l’URL http://your-server-ip. Sarai reindirizzato alla seguente pagina:

Interfaccia Netbox

Clicca sul pulsante Accedi. Dovresti vedere la pagina di accesso di Netbox nel seguente schermo:

Login Netbox

Fornisci il tuo nome utente e password di amministratore di Netbox e clicca sul pulsante login. Dovresti vedere il dashboard predefinito di Netbox nella seguente pagina:

Dashboard amministrativa di Netbox

Conclusione

In questa guida, hai imparato come installare Netbox su Ubuntu 20.04 con Nginx. Puoi ora iniziare a documentare la tua infrastruttura di rete. Per ulteriori informazioni, visita la documentazione ufficiale di Netbox. Sentiti libero di chiedermi se hai domande.

Share: X/Twitter LinkedIn

Ricevi i nuovi post nella tua casella di posta.

Nessuno spam. Disiscriviti in qualsiasi momento.