Install NetBox from scratch

From a fresh Linux server to a NetBox instance behind HTTPS, ready for users. PostgreSQL, Redis, NetBox itself, gunicorn, then the web server you choose.

intermediate~45 min hands-on
#netbox#postgresql#redis#gunicorn#nginx#apache

Not validated end to end yet — be the first.Report a problem

Draft — not yet run end to end. This page was written but its author has not yet run it on a real machine. Commands may be wrong: read before you run, and tell us what breaks.

The gistOne server, four pieces
Your server
HTTPS
Your teamhttps://
nginx443 → 8001
NetBox (gunicorn)
PostgreSQLnetbox / netbox
Redisdb 0 tasks · db 1 cache

The web server takes HTTPS from users and hands requests to gunicorn, which runs NetBox. NetBox keeps everything in PostgreSQL and uses Redis for its queue and cache. With LDAP, logins are checked against your directory.

NetBox is four moving parts: a PostgreSQL database, a Redis cache, the Django application served by gunicorn, and a web server in front of it for HTTPS. We install them in that order, checking each one before moving on.

Before you start

$sudo apt update && sudo apt upgrade -y

PostgreSQL

$sudo apt install -y postgresql
Check
$psql --version
Expected output
psql (PostgreSQL) 16.x

Create the database and its owner:

$sudo -u postgres psql -c "CREATE DATABASE netbox;"
$sudo -u postgres psql -c "CREATE USER netbox WITH PASSWORD '';"
$sudo -u postgres psql -c "ALTER DATABASE netbox OWNER TO netbox;"
$sudo -u postgres psql -d netbox -c "GRANT CREATE ON SCHEMA public TO netbox;"
Check
$psql --username netbox --password --host localhost netbox -c '\conninfo'
Expected output
You are connected to database "netbox" as user "netbox" on host "localhost"

Redis

$sudo apt install -y redis-server
Check
$redis-cli ping
Expected output
PONG

Install NetBox

$sudo apt install -y git python3 python3-pip python3-venv python3-dev build-essential \
$ libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev
Check
$python3 -V
Expected output
Python 3.12.x
$sudo mkdir -p
$sudo git clone -b --depth 1 https://github.com/netbox-community/netbox.git
$sudo adduser --system --group netbox
$sudo chown --recursive netbox /netbox/media/ /netbox/reports/ /netbox/scripts/

Configuration

$sudo cp /netbox/netbox/configuration_example.py /netbox/netbox/configuration.py
$python3 /netbox/generate_secret_key.py

Edit configuration.py and set these values (paste the key printed above into SECRET_KEY):

python
ALLOWED_HOSTS = ['']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'netbox',
'USER': 'netbox',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '',
'CONN_MAX_AGE': 300,
}
}
REDIS = {
'tasks': {'HOST': 'localhost', 'PORT': 6379, 'PASSWORD': '', 'DATABASE': 0, 'SSL': False},
'caching': {'HOST': 'localhost', 'PORT': 6379, 'PASSWORD': '', 'DATABASE': 1, 'SSL': False},
}
SECRET_KEY = 'paste-the-generated-key-here'

Run the upgrade script

$sudo /upgrade.sh
Check
$sudo /venv/bin/python /netbox/manage.py check
Expected output
System check identified no issues

Create the first administrator:

$sudo /venv/bin/python /netbox/manage.py createsuperuser
$sudo ln -s /contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping

gunicorn and systemd

$sudo cp /contrib/gunicorn.py /gunicorn.py
$sudo cp -v /contrib/*.service /etc/systemd/system/
$sudo systemctl daemon-reload
$sudo systemctl enable --now netbox netbox-rq
Check
$systemctl is-active netbox netbox-rq
Expected output
active
active
Check
$curl -sI http://127.0.0.1:8001/ | head -1
Expected output
HTTP/1.1 200 OK

Web server and HTTPS

$sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
$ -keyout /etc/ssl/private/netbox.key -out /etc/ssl/certs/netbox.crt \
$ -subj "/CN="
Sensitive command — recursive or forced deletion (rm). Review before running.
$sudo apt install -y nginx
$sudo cp /contrib/nginx.conf /etc/nginx/sites-available/netbox
$sudo sed -i 's/netbox.example.com//' /etc/nginx/sites-available/netbox
$sudo rm -f /etc/nginx/sites-enabled/default
$sudo ln -sf /etc/nginx/sites-available/netbox /etc/nginx/sites-enabled/netbox
$sudo nginx -t && sudo systemctl restart nginx
Check
$curl -skI https:/// | head -1
Expected output
HTTP/2 200

Done

Open https:/// and log in with the administrator you created. The next page of this series adds users and permissions, plugins and the settings you will want before opening NetBox to your team.

Did everything work?

If you followed this page to the end on a real machine, say so. Your validation is dated and records your stack, so the next reader on the same path knows it still works.

This copy is read-only. To report that it works, or that it does not, open an issue

Only your stack choices are recorded, never your values. The pseudonym stays on this browser.