How to Install NetBox on Ubuntu 20.04

In this article, we’ll explain how to install NetBox on Ubuntu 20.04. This will guide you with the installation and configuration process.

NetBox is an infrastructure resource modeling (IRM) application designed to empower network automation. NetBox was developed specifically to address the needs of network and infrastructure engineers. It is intended to function as a domain-specific source of truth for network operations.

NetBox runs as a web application atop the Django Python framework with a PostgreSQL database.


  • A Ubuntu 20.04 installed KVM VPS.
  • A root user access or normal user with administrative privileges

1. Keep the server up to date

# apt update -y && apt upgrade -y

2. Install and Configure PostgreSQL Database

We’ll install and configure a local PostgreSQL database.

Note: NetBox requires PostgreSQL 9.6 or higher. Please note that MySQL and other relational databases are not currently supported.

Install PostgreSQL database using following command:

# apt install -y postgresql libpq-dev

Start and enable PostgreSQL service:

# systemctl start postgresql

# systemctl enable postgresql

Next, we need to create a database for NetBox and assign it a username and password for authentication.

# sudo -u postgres psql psql

postgres=# CREATE DATABASE netbox;


postgres=# CREATE USER netbox WITH PASSWORD ‘r5t6^7$%gyuuyt4’;


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


postgres=# q

3. Install Redis

Redis is an in-memory key-value store which NetBox employs for caching and queuing. Use following command to install Redis:

# apt install redis-server -y

Start and enable redis-server service:

# systemctl start redis-server

# systemctl enable redis-server

Use the redis-cli utility to ensure the Redis service is functional:

See also  InoNet and Canonical partner for seamless Edge AI deployment

# redis-cli ping


4. Install and Configure NetBox

There are two ways to install NetBox.

  1. Download a Release Archive
  2. Clone the Git Repository

We’ll install NetBox by cloning the Git repository.

First, install required packages and its dependencies:

# apt install -y python3 python3-pip python3-venv python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev

Update pip (Python’s package management tool) to its latest release:

# pip3 install –upgrade pip

Create the base directory /opt/netbox for the NetBox installation.

# mkdir -p /opt/netbox/ && cd /opt/netbox/

Next, clone the master branch of the NetBox GitHub repository into the current directory.

# git clone -b master .

Create a system user account named netbox. We’ll configure the WSGI and HTTP services to run under this account. We’ll also assign this user ownership of the media directory.

# adduser –system –group netbox

# chown –recursive netbox /opt/netbox/netbox/media/

Move into the NetBox configuration directory and make a copy of named

# cd /opt/netbox/netbox/netbox/

# cp

Create a symbolic link of Python binary.

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

Generate a random SECRET_KEY of at least 50 alphanumeric characters.

# /opt/netbox/netbox/

Above command will create a secret key, store it so that we can use it in the

Open and edit the configuration file

# nano /opt/netbox/netbox/netbox/

The final file should have the following configurations.


‘NAME’: ‘netbox’, # Database name you created
‘USER’: ‘netbox’, # PostgreSQL username you created
‘PASSWORD’: ‘r5t6^7$%gyuuyt4’, # PostgreSQL password you set
‘HOST’: ‘localhost’, # Database server
‘PORT’: ”, # Database port (leave blank for default)


Once NetBox has been configured, we’re ready to proceed with the actual installation.

We’ll run the packaged upgrade script ( to perform the following actions:

  • Create a Python virtual environment
  • Install all required Python packages
  • Run database schema migrations
  • Aggregate static resource files on disk

# /opt/netbox/

Enter the Python virtual environment created by the upgrade script:

# source /opt/netbox/venv/bin/activate

Create a superuser account using the createsuperuser

# cd /opt/netbox/netbox

# python3 createsuperuser


Email address:


Password (again):

Superuser created successfully.

5. Configure Gunicorn

NetBox ships with a default configuration file for gunicorn. To use it, copy /opt/netbox/contrib/ to /opt/netbox/

# cp /opt/netbox/contrib/ /opt/netbox/

Copy contrib/netbox.service and contrib/netbox-rq.service to the /etc/systemd/system/ directory and reload the systemd dameon:

# cp -v /opt/netbox/contrib/*.service /etc/systemd/system/

# systemctl daemon-reload

Start and enable the netbox and netbox-rq services:

# systemctl start netbox netbox-rq

# systemctl enable netbox netbox-rq

6. Configure Nginx Web Server

Install Nginx web server using following command:

# apt install -y nginx

Copy the nginx configuration file provided by NetBox to /etc/nginx/sites-available/netbox.

# cp /opt/netbox/contrib/nginx.conf /etc/nginx/sites-available/netbox

Edit the netbox configuration file and remove all the content and copy paste below contents:

# nano /etc/nginx/sites-available/netbox

Remember to change server_name.

server {
listen 80;


client_max_body_size 25m;

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

location / {
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;

Then, delete /etc/nginx/sites-enabled/default and create a symlink in the sites-enabled directory to the configuration file you just created.

# rm /etc/nginx/sites-enabled/default

# ln -s /etc/nginx/sites-available/netbox /etc/nginx/sites-enabled/netbox

Now test Nginx configuration and restart the Nginx service:

# nginx -t

# systemctl restart nginx

That’s it we have successfully completed with the installation and configuration process.

Navigate to your browser and access NetBox with using either server IP or domain name.

Install NetBox on Ubuntu

In this article, we’ve seen how to install NetBox on Ubuntu 20.04.

2 thoughts on “How to Install NetBox on Ubuntu 20.04”

Leave a Comment

Only people in my network can comment.