How to Install NetBox on Ubuntu 18.04 LTS is the heading of our article today. NetBox is an open source IPAM / DCIM web application used for managing and documenting computer networks and managing IP addresses. It was Initially conceived by the network engineering team at DigitalOcean.
Netbox encompasses the following aspects of network management:
- IP address management (IPAM) – IP networks and addresses, VRFs, and VLANs
- Equipment racks – Organized by group and site
- Devices – Types of devices and where they are installed
- Connections – Network, console, and power connections among devices
- Virtualization – Virtual machines and clusters
- Data circuits – Long-haul communications circuits and providers
- Secrets – Encrypted storage of sensitive credentials
If you’re interested in deploying Netbox on CentOS 7, check:
Install NetBox on Ubuntu 18.04 LTS
This section will discuss the actual steps you need to follow to have NetBox installed on your Ubuntu 18.04 LTS server. Follow them in order of the appearance, though you can skip a part if you have the software being installed already configiured.
Step 1: Install required dependencies
Start by installing all dependency applications required to run NetBox on Ubuntu 18.04 LTS.
sudo apt update
sudo apt install -y git gcc nginx redis supervisor build-essential libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev libssl-dev zlib1g-dev
Install Python3.9 packages.
sudo apt install wget build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
wget https://www.python.org/ftp/python/3.9.17/Python-3.9.17.tgz
tar xzf Python-3.9.*.tgz
cd Python-3.9*/
sudo ./configure --enable-optimizations
sudo make altinstall
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.9
Confirm the version of Python installed.
$ python3.9 -V
Python 3.9.16
$ pip3.9 -V
pip 23.2.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
Step 2: Install PostgreSQL database server
NetBox uses PostgreSQL database server to store its data. So install and configure it on Ubuntu 18.04 using our previous guide below:
Then Create a database and user for NetBox.
$ sudo -u postgres psql
CREATE DATABASE netbox;
CREATE USER netbox WITH PASSWORD 'StrongPassword';
GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;
\q
Confirm that you can login to database as netbox
user.
# psql -U netbox -h localhost -W
Password:
psql (12.15 (Ubuntu 12.15-1.pgdg18.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
netbox-> \q
Step 3: Install and configure Netbox
Change to /opt/
directory
cd /opt/
sudo git clone -b master https://github.com/digitalocean/netbox.git
Create a configuration file
cd netbox/netbox/netbox/
sudo cp configuration_example.py configuration.py
Edit the configuration file and set allowed host and database login details
$ sudo vim configuration.py
# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
ALLOWED_HOSTS = ['*']
# PostgreSQL database configuration.
DATABASE = {
'NAME': 'netbox', # Database name
'USER': 'netbox', # PostgreSQL username
'PASSWORD': 'StrongPassword', # PostgreSQL password
'HOST': 'localhost', # Database server
'PORT': '', # Database port (leave blank for default)
}
Generate Django SECRET Key:
cd /opt/netbox/netbox
sudo ./generate_secret_key.py
Then set the key on the file /opt/netbox/netbox/netbox/configuration.py
Example:
$ sudo vim /opt/netbox/netbox/netbox/configuration.py
SECRET_KEY = '30m&hqd@09h2i5hro=^l8wqtjw2$!3j%=f2!zh_sey+13jg%3$'
Install Netbox dependencies
sudo pip3.9 install -r /opt/netbox/requirements.txt
Migrate database data:
cd /opt/netbox/netbox/
sudo python3.9 manage.py migrate
Sample output for database migration.
....
Applying dcim.0171_cabletermination_change_logging... OK
Applying dcim.0172_larger_power_draw_values... OK
Applying django_rq.0001_initial... OK
Applying extras.0087_dashboard... OK
Applying extras.0088_jobresult_webhooks... OK
Applying extras.0089_customfield_is_cloneable... OK
Applying extras.0090_objectchange_index_request_id... OK
Applying extras.0091_create_managedfiles... OK
Applying extras.0092_delete_jobresult... OK
Applying ipam.0064_clear_search_cache... OK
Applying ipam.0065_asnrange... OK
Applying ipam.0066_iprange_mark_utilized... OK
Applying sessions.0001_initial... OK
Applying social_django.0001_initial... OK
Applying social_django.0002_add_related_name... OK
Applying social_django.0003_alter_email_max_length... OK
Applying social_django.0004_auto_20160423_0400... OK
Applying social_django.0005_auto_20160727_2333... OK
Applying social_django.0006_partial... OK
Applying social_django.0007_code_timestamp... OK
Applying social_django.0008_partial_timestamp... OK
Applying social_django.0009_auto_20191118_0520... OK
Applying social_django.0010_uid_db_index... OK
Applying social_django.0011_alter_id_fields... OK
Applying taggit.0001_initial... OK
Applying taggit.0002_auto_20150616_2121... OK
Applying taggit.0003_taggeditem_add_unique_index... OK
Applying taggit.0004_alter_taggeditem_content_type_alter_taggeditem_tag... OK
Applying taggit.0005_auto_20220424_2025... OK
Applying tenancy.0010_tenant_relax_uniqueness... OK
Applying users.0001_squashed_0011... OK
Applying users.0002_standardize_id_fields... OK
Applying users.0003_token_allowed_ips_last_used... OK
Create admin user:
$ sudo python3.9 manage.py createsuperuser
Username (leave blank to use 'root'): admin
Email address: [email protected]
Password: <Enter Password>
Password (again): <Re-enter Password>
Superuser created successfully.
Move static files
$ cd /opt/netbox/netbox
$ sudo python3.9 manage.py collectstatic
229 static files copied to '/opt/netbox/netbox/static'.
Step 4: Install and Configure gunicorn
Install gunicorn using pip3:
$ sudo pip3.9 install gunicorn
Collecting gunicorn
Downloading https://files.pythonhosted.org/packages/8c/da/b8dd8deb741bff556db53902d4706774c8e1e67265f69528c14c003644e6/gunicorn-19.9.0-py2.py3-none-any.whl (112kB) 100% |████████████████████████████████| 122kB 737kB/s
Installing collected packages: gunicorn
Successfully installed gunicorn-19.9.0
Configure gunicorn for Netbox:
cat <<EOF | sudo tee /opt/netbox/gunicorn_config.py
command = '/usr/local/bin/gunicorn'
pythonpath = '/opt/netbox/netbox'
bind = 'localhost:8085'
workers = 3
user = 'www-data'
EOF
Step 5: Configure supervisord
Create a supervisord configuration file:
cat <<EOF | sudo tee /etc/supervisor/conf.d/netbox.conf
[program:netbox]
command = gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
directory = /opt/netbox/netbox/
user = www-data
EOF
Restart and enable supervisord service to start on boot.
sudo systemctl restart supervisor.service
sudo systemctl enable supervisor.service
Status should show running with netbox output.
$ systemctl status supervisor
● supervisor.service - Supervisor process control system for UNIX
Loaded: loaded (/lib/systemd/system/supervisor.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-08-16 20:56:46 UTC; 7s ago
Docs: http://supervisord.org
Main PID: 25571 (supervisord)
Tasks: 5 (limit: 4584)
CGroup: /system.slice/supervisor.service
├─25571 /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
├─25679 /usr/local/bin/python3.9 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
├─25680 /usr/local/bin/python3.9 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
├─25681 /usr/local/bin/python3.9 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
└─25682 /usr/local/bin/python3.9 /usr/local/bin/gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
Aug 16 20:56:46 bionic systemd[1]: Started Supervisor process control system for UNIX.
Aug 16 20:56:47 bionic supervisord[25571]: 2023-08-16 20:56:47,049 CRIT Supervisor running as root (no user in config file)
Aug 16 20:56:47 bionic supervisord[25571]: 2023-08-16 20:56:47,050 INFO Included extra file "/etc/supervisor/conf.d/netbox.conf" during parsing
Aug 16 20:56:47 bionic supervisord[25571]: 2023-08-16 20:56:47,060 INFO RPC interface 'supervisor' initialized
Aug 16 20:56:47 bionic supervisord[25571]: 2023-08-16 20:56:47,060 CRIT Server 'unix_http_server' running without any HTTP authentication checking
Aug 16 20:56:47 bionic supervisord[25571]: 2023-08-16 20:56:47,060 INFO supervisord started with pid 25571
Aug 16 20:56:48 bionic supervisord[25571]: 2023-08-16 20:56:48,064 INFO spawned: 'netbox' with pid 25679
Aug 16 20:56:49 bionic supervisord[25571]: 2023-08-16 20:56:49,254 INFO success: netbox entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
Step 6: Configure Nginx Web Server
Let’s configure Nginx web server to help us access Netbox via Domain name rather than specifying an IP address and a port.
Create new Nginx configuration file for Netbox.
sudo vim /etc/nginx/conf.d/netbox.conf
With below data.
server {
listen 80;
server_name netbox.example.com;
client_max_body_size 25m;
location /static/ {
alias /opt/netbox/netbox/static/;
}
location / {
proxy_pass http://localhost:8085;
}
}
Check Nginx configuration syntax and restart its service
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If OK, restart Nginx service
sudo systemctl restart nginx
Step 7: Access Netbox Web UI
If you don’t have DNS server add an entry in the /etc/hosts
.
$ sudo vim /etc/hosts
5.75.227.153 netbox.example.com
Open your default web browser and open Netbox server hostname. To make changes, login with admin user created earlier.
Enjoy using Netbox to document your network infrastructure. Refer to official Netbox documentation for more details.