Installing Netbox on Ubuntu

IPAM Ubuntu

Netbox Installation (bobcares.com)

Netbox installation will will allow us to automate most networking operations. Its an open-source, web-based Infrastructure Resource Modeling (IRM) application.

At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Service.

Check out how our Support team assisted a customer with installing and configuring NetBox on Ubuntu 20.04.

Netbox Installation

NetBox is a web-based, open-source Infrastructure Resource Modeling (IRM) application. Its main tool is IP Address Management (IPAM), which manages IP addresses. Another tool is Datacenter Infrastructure Management (DCIM), which manages and documents computer networks.

Prerequisites

  • Firstly, install Ubuntu 20.04 LTS, with at least 2GB of RAM and 1 vCPU core, on Vultr.
  • In addition, create a sudo-enabled non-root user.

Install and configure PostgreSQL

  1. Firstly, PostgreSQL should be installed.
    sudo apt install postgresql libpq-dev -y
  2. Secondly, we need to start the database server.
  3. Meanwhile, allow the database server to start automatically when the server is restarted.
    sudo systemctl enable postgresql
  4. Change PostgreSQL’s default password.
    sudo passwd postgres
  5. In addition, change user to postgres.
    su - postgres
  6. Then, log in to the PostgreSQL database.
    psql
  7. Create a database called netbox.
    CREATE DATABASE netbox;
  8. Similarly, create a user netbox with password STRONGPASSWORD . Use a strong password in place of STRONGPASSWORD .
    CREATE USER netbox WITH ENCRYPTED password 'STRONGPASSWORD';
  9. Most importantly, ll privileges on the netbox database should be granted to the netbox user.
    GRANT ALL PRIVILEGES ON DATABASE netbox to netbox;
  10. Finally, PostgreSQL should now be exited.
    \q
  11. Meanwhile ,return to sudo user account as a non-root user.
    exit

Install Redis

Redis is a key-value store that runs in memory. So, it’s used by NetBox for caching and queuing.

We can install Redis using the following command.
sudo apt install -y redis-server

Install and configure NetBox

It’s best to install NetBox from the official git repository. So that we can upgrade without having to re-pull the master branch.

  1. Firstly, all of the required packages should be installed.
    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 -y
  2. In addition, PIP should be updated to the latest version.
    sudo pip3 install --upgrade pip
  3. The installation directory will be /opt/netbox/. So, create the /opt/netbox/ directory and change to the/opt/netbox/ directory.
    sudo mkdir -p /opt/netbox/ && cd /opt/netbox/
  4. Then, in the current directory, clone NetBox from the official git repository.
    sudo git clone -b master https://github.com/netbox-community/netbox.git
  5. After that, make a system user called netbox.
    sudo adduser --system --group netbox
  6. Most importantly, give the user netbox ownership of the directory /opt/netbox/netbox/media/.
    sudo chown --recursive netbox /opt/netbox/netbox/media/
  7. After that, browse to the directory /opt/netbox/netbox/netbox/.
    cd /opt/netbox/netbox/netbox/
  8. In addition, copy the configuration.example.py example configuration file to the configuration.py file we’ll use to configure the project.
    sudo cp configuration.example.py configuration.py
  9. After that, create a Python binary symbolic link.
    sudo ln -s /usr/bin/python3 /usr/bin/python
  10. Then, create a SECRET_KEY with at least 50 alphanumeric characters at random.
    sudo /opt/netbox/netbox/generate_secret_key.py;We will be given a random secret_key, similar to the one shown below. Create a copy of it and keep it somewhere safe. It’ll be required in the configuration file.
    XLM7Wd$9M8hajGqqJC^DS&*-fed=jF&k-k9jjxQ-n5#8s$LLvg
  11. Open the configuration.py file and make changes.
    sudo nano /opt/netbox/netbox/netbox/configuration.pyMost importantly, following settings should be included in the final file.
    ALLOWED_HOSTS = ['*']
    DATABASE = {
    ‘NAME’: ‘netbox’, # Database name we created
    ‘USER’: ‘netbox’, # PostgreSQL username we created
    ‘PASSWORD’: ‘my_strong_password’, # PostgreSQL password we set
    ‘HOST’: ‘localhost’, # Database server
    ‘PORT’: ”, # Database port (leave blank for default)
    }SECRET_KEY = ‘-^%YEl*Q2etCR6$kNG70H=&sM(45XvJaBWdf3O)inZ@L9j8_w1’
  12. Then, run the script to upgrade the server.
    sudo /opt/netbox/upgrade.sh
  13. Now, we will enter the Python virtual environment.
    source /opt/netbox/venv/bin/activate
  14. Meanwhile, navigate to the /opt/netbox/netbox directory.
    cd /opt/netbox/netbox
  15. Then, set up a superuser account.
    python3 manage.py createsuperuser
  16. Finally, To apply the changes, reboot.
    sudo reboot

Configure Gunicorn

/opt/netbox/contrib/gunicorn.py should be copied to /opt/netbox/gunicorn.py
sudo cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py

Configure Systemd

  1. Firstly, in the /etc/systemd/system/ directory, copy contrib/netbox.service and contrib/netbox-rq.service.
    sudo cp /opt/netbox/contrib/*.service /etc/systemd/system/
  2. Secondly , to enable the Systemd changes, reload the daemon.
    sudo systemctl daemon-reload
  3. Then, start the services netbox and netbox-rq.
    sudo systemctl start netbox netbox-rq
  4. Finally, allow services to start automatically when the server boots up.
    sudo systemctl enable netbox netbox-rq

Configure Nginx Web Server

  1. Firstly , set up the Nginx web server.
    sudo apt install -y nginx
  2. Secondly, copy the nginx.conf file from NetBox Nginx to /etc/nginx/sites-available/netbox.
    sudo cp /opt/netbox/contrib/nginx.conf /etc/nginx/sites-available/netbox
  3. Edit the netbox file.
    sudo nano /etc/nginx/sites-available/netboxReplace the content of the files with the code below. Most importantly, replace the server name value with the IP address of our server: server { listen 80; # CHANGE THIS TO OUR SERVER'S NAME server_name 192.0.2.10; client_max_body_size 25m; location /static/ { alias /opt/netbox/netbox/static/; } location / { proxy_pass http://127.0.0.1:8001; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; } }
  4. Then, delete the file /etc/nginx/sites-enabled/default.
    sudo rm /etc/nginx/sites-enabled/default
  5. After that, create a symlink to the netbox configuration file in the sites-enabled directory.
    sudo ln -s /etc/nginx/sites-available/netbox /etc/nginx/sites-enabled/netbox
  6. Finally, to enable the new configurations, restart the nginx service.
    sudo systemctl restart nginx

[Looking for a solution to another query? We are just a click away.]

Conclusion

To sum up, NetBox has been successfully installed. We can now log in using the username and password we assigned to the superuser account when we created it.

Leave a Reply

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