Skip to content
Follow
Ubuntu Linux

Install NetBox IPAM on Ubuntu: Step-by-Step Guide

Richard
Written by
Richard
Jan 26, 2024 Updated Sep 15, 2026 7 min read
How to Enable or Disable Microsoft Defender Cloud Protection
How to Enable or Disable Microsoft Defender Cloud Protection

NetBox IPAM is a free open-source tool that helps you track IP addresses, network cables, and data center hardware in one central web interface. Installing NetBox on Ubuntu 22.04 LTS gives you a reliable way to manage your entire network layout through a local web server.

Advertisement

This setup works on version 3.7.x of the software using standard terminal commands. You need root access to your Ubuntu machine and a working internet connection to download the required packages.

⚡ Quick Answer

Install NetBox IPAM by updating your system, installing dependencies like PostgreSQL and Redis, creating a NetBox database and user, cloning the NetBox repository, and configuring the `configuration.py` file. Then, install required Python packages.

Advertisement

Prerequisites

Before you proceed with the installation, ensure that you have:

  • A server running Ubuntu Linux.
  • Sudo privileges on the server.
  • Basic knowledge of command-line operations and Linux environment.

Update and Upgrade the System

Begin by updating your package list and upgrading your system to ensure all existing packages are up to date.

sudo apt update
sudo apt upgrade

Restart your server if required.

Install Required Dependencies

NetBox has some dependencies you must install, including PostgreSQL, Redis, and other necessary software.

Advertisement
sudo apt install python3 python3-pip python3-venv python3-dev build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev git postgresql postgresql-contrib redis-server

Create PostgreSQL Database and User

To prepare your NetBox IPAM Ubuntu installation, you must create a dedicated PostgreSQL database and user. Run the sudo -u postgres psql command in your terminal to open the database prompt, then execute the SQL commands to create the netbox database and grant full access to your new user account.

sudo -u postgres psql

From the PostgreSQL prompt, execute:

CREATE DATABASE netbox;
CREATE USER netbox WITH PASSWORD 'netbox_user_password';
GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;
ALTER DATABASE netbox OWNER TO netbox;
q
⚠️WarningRemember to replace netbox_user_password with a secure password.

Remember to replace netbox_user_password with a secure password.

Clone NetBox Repository

Clone the NetBox repository into the directory of your choice.

Advertisement
sudo mkdir -p /opt/netbox/
cd /opt/netbox/
sudo git clone -b master --depth 1 https://github.com/netbox-community/netbox.git .

Create a NetBox non-login account

First, execute the command below to create a new netbox user to run the NetBox installation.

sudo adduser --system --group netbox
sudo chown --recursive netbox /opt/netbox/netbox/media/

Configure NetBox

To configure NetBox, copy the default template file named configuration_example.py into a new file called configuration.py inside your /opt/netbox/netbox/netbox/ directory. Open this new file in a text editor to set up your database credentials and allowed host settings before running the application.

cd /opt/netbox/netbox/netbox/
sudo cp configuration_example.py configuration.py

Next, open configuration.py with your preferred editor to begin configuring NetBox.

sudo nano /opt/netbox/netbox/netbox/configuration.py
⚠️WarningSet the ALLOWED_HOSTS, DATABASE, and SECRET_KEY settings to match your environment.

Set the ALLOWED_HOSTS, DATABASE, and SECRET_KEY settings to match your environment.

Advertisement
# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
ALLOWED_HOSTS = []

# PostgreSQL database configuration. See the Django documentation for a complete list of available>
#   https://docs.djangoproject.com/en/stable/ref/settings/#databases
DATABASE = {
    'ENGINE': 'django.db.backends.postgresql',  # Database engine
    'NAME': 'netbox',         # Database name
    'USER': 'netbox',               # PostgreSQL username
    'PASSWORD': 'netbox_user_password',           # PostgreSQL password
    'HOST': 'localhost',      # Database server
    'PORT': '',               # Database port (leave blank for default)
    'CONN_MAX_AGE': 300,      # Max database connection age
}

A simple Python script  generate_secret_key.py is provided in the parent directory to assist in generating a suitable key:

python3 ../generate_secret_key.py

Also, add the new secret to the SECRET_KEY section of the config file above.

SECRET_KEY = 'mnY(fx7RFfpV3yD#yEJ^Z8FOg&(hab7#KbYW+!u=J2HnL8ujk1'

Install Required Python Packages

To install required Python packages for your NetBox IPAM Ubuntu installation, add any extra dependencies like napalm to your local_requirements.txt file. NetBox automatically reads this file during setup to install all necessary modules for network automation features and smooth operation.

sudo sh -c "echo 'napalm' >> /opt/netbox/local_requirements.txt"

By default, NetBox will use the local filesystem to store uploaded files. To use a remote filesystem, install the django-storages library and configure your desired storage backend in configuration.py.

Advertisement
sudo sh -c "echo 'django-storages' >> /opt/netbox/local_requirements.txt"

Run the Upgrade Script

Once NetBox has been configured, run the packaged upgrade script (upgrade.sh) to perform the following actions:

  • Create a Python virtual environment
  • Installs all required Python packages
  • Run database schema migrations
  • Builds the documentation locally (for offline use)
  • Aggregate static resource files on disk
sudo /opt/netbox/upgrade.sh

Create Super User

To create a super user account for NetBox, activate the Python virtual environment by running the source /opt/netbox/venv/bin/activate command. Once the virtual environment is active, run the management script to set up your administrator username, email address, and password.

First, enter the Python virtual environment created by the upgrade script:

source /opt/netbox/venv/bin/activate

Once the virtual environment has been activated, you should notice the string (venv) prepended to your console prompt.

Advertisement

Next, create a superuser account using the createsuperuser Django management command (via manage.py).

Specifying an email address for the user is not required, but be sure to use a strong password.

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

Follow the prompts to set up your superuser login.

Once done, run the command below to test your configuration.

Advertisement
python3 manage.py runserver 0.0.0.0:8000 --insecure

Open your browser and browse to the server hostname or IP address followed by port number 8000.

http://localhost:8000
Install NetBox on Ubuntu Linux
Install NetBox on Ubuntu Linux

The server is up and running. Howerver, when you type Ctrl+c , you will stop the server.

You will want to set up a reverse proxy to run NetBox IPAM in a production environment. A reverse proxy, such as Nginx, helps manage incoming requests and can improve your NetBox IPAM performance and security by directing traffic efficiently.

Continue with the steps below to do that.

Collect Static Files

Collect the static files required for the web interface to function correctly.

python3 manage.py collectstatic --no-input

Configuration of Gunicorn

To set up Gunicorn as the application server for NetBox, install the package using pip3 and create a systemd service file at /etc/systemd/system/netbox.service. This service file tells Ubuntu how to start, stop, and manage the Gunicorn process automatically in the background.

pip3 install gunicorn

Then, create a Gunicorn systemd service file:

sudo nano /etc/systemd/system/netbox.service

Add the following configuration to the netbox.service file:

[Unit]
Description=NetBox WSGI Service
After=network.target

[Service]
Type=simple
User=netbox
Group=netbox
Environment="PATH=/opt/netbox/venv/bin"
ExecStart=/opt/netbox/venv/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi

[Install]
WantedBy=multi-user.target

Make sure to adjust paths if you installed NetBox in a different directory.

Configure Gunicorn

Next, you'll need to create a Gunicorn configuration file at /opt/netbox/gunicorn_config.py.

sudo nano /opt/netbox/gunicorn_config.py

Add your Gunicorn config, which may look something like this:

command = '/opt/netbox/venv/bin/gunicorn'
pythonpath = '/opt/netbox/netbox'
bind = '0.0.0.0:8000'
workers = 3

Configure Nginx

To configure Nginx as a reverse proxy for NetBox, install the web server using sudo apt install nginx and create a site configuration file at /etc/nginx/sites-available/netbox. This file routes incoming web traffic from your domain name to the Gunicorn socket running your application.

sudo apt install nginx
sudo nano /etc/nginx/sites-available/netbox

Set up the server block:

server {
    listen 80;

    server_name netbox.example.com;

    client_max_body_size 25m;

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

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Remember to replace netbox.example.com with your domain name or server IP address.

Enable the NetBox site by linking the configuration file to the sites-enabled directory and restarting Nginx.

sudo ln -s /etc/nginx/sites-available/netbox /etc/nginx/sites-enabled/netbox
sudo systemctl restart nginx

Start NetBox and Gunicorn

Enable and start the NetBox service.

sudo systemctl daemon-reload
sudo systemctl enable netbox
sudo systemctl start netbox

Access NetBox

To access NetBox, open your web browser and navigate to your server address or domain name, such as http://netbox.example.com. Log in using the administrator username and password you created during the super user setup steps to start managing your IP addresses.

http://netbox.example.com
NetBox IPAM dashboard interface running on an Ubuntu Linux server
NetBox IPAM dashboard interface running on an Ubuntu Linux server

That should do it!

Conclusion:

  • Successfully installing and setting up NetBox IPAM on Ubuntu Linux provides a secure and reliable platform for centrally managing IP addresses, devices, and racks within a data center infrastructure.
  • Utilizing the strong community support and flexibility of the widely used Ubuntu Linux operating system ensures a smooth installation and configuration process.
  • Embracing the open-source nature of NetBox IPAM offers cost reduction and greater flexibility than proprietary IPAM solutions.
  • The comprehensive guide has detailed the necessary prerequisites, installation of required dependencies, database and user creation, repository cloning, configuration, Python package installation, upgrade script execution, super user creation, static file collection, Gunicorn and Nginx configuration, and starting NetBox and Gunicorn services.
  • Upon completion, accessing NetBox via a web browser allows the management of the instance with the created superuser account.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

Advertisement

📚 Related Tutorials

Change Power Button Behavior in Ubuntu Linux
Ubuntu Linux Change Power Button Behavior in Ubuntu Linux
How to list Services on Ubuntu Linux
Ubuntu Linux How to list Services on Ubuntu Linux
Working with Sudo and Su Commands in Ubuntu Linux
Ubuntu Linux Working with Sudo and Su Commands in Ubuntu Linux
How to Install Apache on Ubuntu Linux
Ubuntu Linux How to Install Apache on Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *