Overview

One application I usually introduce at customers without an existing network management solution is Netdisco, which is an open source application that scans the network and collects information about the network equipment and all connected devices. This has proven particularly useful for on-site support, who can use it to find where equipment is located and connected, but having visibility is rarely a bad thing for network, client or other teams either.

I usually find myself starting with the official documentation for installation, then trying to remember how I setup the reverse proxy for HTTPS and how the systemd files were formatted. For this reason I wanted to collect all steps to install Netdisco the way I usually do, on one page only.

This guide is written for Ubuntu, and has been tested on the following versions:

  • 20.04
  • 22.04
  • 24.04

In this case we are also running web, backend and database on the same server. I found this to be the most common implementation, but it is possible to run separate or even multiple backends if you need to restrict traffic flows to specific network segments for example.

The guide assumes you have a fresh Ubuntu installation, but I have installed Netdisco alongside other applications like Netbox in some cases without issues.

Prerequisites

You will need the following software installed to run Netdisco:

  • PostgreSQL (9.6+)
  • Perl (5.10+)
  • Nginx or Apache for reverse proxy (Nginx covered in this guide)

Start by installing the pre-requisites:

sudo apt update

sudo apt install -y \
  libdbd-pg-perl \
  libsnmp-perl \
  libssl-dev \
  libio-socket-ssl-perl \
  python3 \
  python3-venv \
  curl \
  postgresql \
  build-essential

Create the service user which will run Netdisco:

sudo useradd \
  --system \
  --create-home \
  --user-group \
  --home-dir /home/netdisco \
  --shell /bin/bash \
  netdisco

Create the database:

sudo -u postgres createuser \
  --no-createdb \
  --no-createrole \
  --no-superuser \
  --pwprompt \
  netdisco

sudo -u postgres createdb \
  --owner=netdisco \
  netdisco

Install Netdisco

Switch to the service user and run the install script to download and install Netdisco into the service accounts home area:

sudo -iu netdisco
curl -fsSL https://cpanmin.us/ | \
  perl - --notest --local-lib ~/perl5 App::Netdisco

Create symlinks:

mkdir -p ~/bin
ln -s ~/perl5/bin/{localenv,netdisco-*} ~/bin/

Make a directory for your local configuration and copy the default configuration template:

mkdir -p ~/environments

cp ~/perl5/lib/perl5/auto/share/dist/App-Netdisco/environments/deployment.yml \
  ~/environments/deployment.yml

chmod 600 ~/environments/deployment.yml

You can verify the installation by checking if this command produces a status message:

~/bin/netdisco-backend status

Configure Netdisco

The configuration is kept in the file you copied earlier, edit ~/environments/deployment.yml with your favourite editor.

Database settings

Start by setting the essential settings, which means your database credentials:

# ------------------
# ESSENTIAL SETTINGS
# ------------------

database:
  name: 'netdisco'
  user: 'netdisco'
  pass: 'CHANGEMEPLEASE'
  #host: 'localhost'

Device authentication

Configure some SNMP and/or SSH credentials:

# Device authentication settings
# define snmp communities and ssh credentials here
# ````````````````````````````````````````````````
device_auth:
  - tag: 'default_v2_readonly'
    community: 'public'
    read: true
    write: false
  - tag: 'customer_community'
    community: 'SUPERSECURE'
    read: true
    write: false
  - tag: 'customer_v3'
    user: netdisco
    auth:
      pass: PASSWORD1
      proto: SHA
    priv:
      pass: PASSWORD2
      proto: AES    

I would recommend leaving the default_v2_readonly one as a means of discovering default devices with the public community.

You can add more than one credential here, and they can also be restricted to IP-addresses or actions:

  - tag: 'fortigate_ssh'
    driver: cli
    platform: FortiOS
    only:
      - 10.20.30.40
    username: 'netdisco'
    password: 'EVENMORESECURE'

There are SSH connectors available for certain vendors to collect MAC and ARP information. Please see https://github.com/netdisco/netdisco/wiki/SSH-Platforms for the current list and how to use them.

Schedule

There is a default schedule in place which is the following:

#schedule:
#  discoverall:
#    when: '5 7 * * *'
#  macwalk:
#    when:
#      min: 20
#  arpwalk:
#    when:
#      min: 50
#  nbtwalk:
#    when: '0 8,13,21 * * *'
#  expire:
#    when: '30 23 * * *'

Uncomment and edit this if you want/need, otherwise just leave it as default.

Other settings

You can set the domain-suffix which will then strip this from the web GUI to reduce clutter:

domain_suffix:
  - '.test'
  - '.example'

Uncomment session_secure if running this over HTTPS behind a reverse proxy (which you should):

session_secure: true

By default Netdisco will discover wireless access points, but not IP-phones, based on information provided over LLDP/CDP. I usually disable the discovering of access points, especially when they are controller managed:

discover_waps: false

I often add TACACS+ for authentication to Netdisco:

tacacs:
  - { server: 'tacacs-1.example', key: 'SHAREDSECRET' }
  - { server: 'tacacs-2.example', key: 'SHAREDSECRET' }

RADIUS and LDAP are also available if needed. LDAP requires a bit more configuration related to certificate trust etc.

Initial startup

When Netdisco is installed and your configuration file is ready, initialise Netdisco by running the deploy script:

~/bin/netdisco-deploy

Follow the wizard and create an administrator account for the Web GUI:

This is the Netdisco 2 deployment script.

Before we continue, the following prerequisites must be in place:
 * Database added to PostgreSQL for Netdisco
 * User added to PostgreSQL with rights to the Netdisco Database
 * "~/environments/deployment.yml" file configured with Database dsn/user/pass
 * A full backup of any existing Netdisco database data
 * Internet access (for OUIs and MIBs)

If you are upgrading Netdisco 2 read the release notes:
https://github.com/netdisco/netdisco/wiki/Release-Notes
There you will find required and incompatible changes
which are not covered by this script.

You will be asked to confirm all changes to your system.

So, is all of the above in place? [y/N]: y

Would you like to deploy the database schema? [y/N]: y

DB schema update complete.
Updating statistics... done.

We need to create a user for initial login. This user will be a full Administrator.
Afterwards, you can go to Admin -> User Management to manage users.

Username:  : admin
Password:  : ADMINPASSWORD
New user created.

Download and update vendor MAC prefixes (OUI data)? [y/N]: y
Updating OUI, Manufacturers, Enterprises, and Products... done.

Download and update MIB files? [y/N]: y
MIBs update complete.

Once the deploy finished, you can start the web interface and backend poller by running:

~/bin/netdisco-web start
~/bin/netdisco-backend start

The web interface can now be reached at http://server-ip:5000/ or http://localhost:5000/ when accessing it directly from the server.

During initial testing, Netdisco listens on port 5000 and can be accessed directly from the network. This is temporary; once configured as a systemd service, Netdisco will listen only on localhost and be accessible through the Nginx reverse proxy.

Note: If you enabled “session_secure” earlier, you won’t be able to log in at this stage since the site is not running HTTPS. Entering the correct username and password will just send you back to the login page without showing an error. You can disable the flag for testing if you want to check out the web interface before proceeding.

After you are done testing, stop the services again as them being started might give an error when trying to start the systemd services later:

~/bin/netdisco-web stop
~/bin/netdisco-backend stop

Also make sure you exit the netdisco service user session and go back to your normal user before proceeding.

Install and configure Nginx

In this guide we will use Nginx as a reverse proxy, since Netdisco itself does not support HTTPS.

Nginx expects a PEM-encoded certificate and private keys. If you have a PFX and want to convert it, see further down.

Start by installing Nginx:

sudo apt update
sudo apt install -y nginx

Enable and start the service:

sudo systemctl enable --now nginx

Verify that it’s started:

sudo systemctl status nginx

Create a configuration file

sudoedit /etc/nginx/sites-available/netdisco

Add the configuration needed. I usually go with this as a template:

server {
    listen 443 ssl;
    server_name netdisco.example;

    ssl_certificate /etc/ssl/certs/netdisco-fullchain.pem;
    ssl_certificate_key /etc/ssl/private/netdisco.key;

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_set_header Host $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;

        proxy_connect_timeout 60s;
        proxy_read_timeout 60s;
        proxy_send_timeout 60s;
    }
}

Enable the site using a symbolic link:

sudo ln -s \
  /etc/nginx/sites-available/netdisco \
  /etc/nginx/sites-enabled/netdisco

And remove the default site unless you want it for some reason:

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

Make sure your TLS certificate and private key are installed at the paths specified in the configuration before proceeding, then verify the Nginx configuration:

sudo nginx -t

The expected output is something like:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Then reload Nginx:

sudo systemctl reload nginx

Once the Netdisco services are running, the web interface should be available at https://netdisco.example

Converting PFX to PEM

If you have a TLS certificate in the PFX format, which is quite common, you can convert it as follows:

Extract server certificate:

openssl pkcs12 -in certificate.pfx \
  -clcerts -nokeys -out netdisco.crt

Extract intermediate CA certificates:

openssl pkcs12 -in certificate.pfx \
  -cacerts -nokeys -out chain.crt

Extract private key (unencrypted):

openssl pkcs12 -in certificate.pfx \
  -nocerts -noenc -out netdisco.key

You can then merge the certificate and the chain:

cat netdisco.crt chain.crt > netdisco-fullchain.pem

Move the created pem and key files to the applicable folders as specified in the Nginx configuration file.

Create systemd services

To make sure Netdisco is running after your dear Ubuntu server was rebooted, make sure you create services for the web and backend.

Start by creating the web service:

sudoedit /etc/systemd/system/netdisco-web.service

Add the content to the file:

[Unit]
Description=Netdisco Web Service
AssertFileIsExecutable=/home/netdisco/bin/netdisco-web
After=syslog.target network-online.target netdisco-backend.service

[Service]
Type=forking
User=netdisco
Group=netdisco
ExecStart=/home/netdisco/bin/netdisco-web start --host=127.0.0.1
ExecStop=/home/netdisco/bin/netdisco-web stop
Restart=on-failure
RestartSec=60

[Install]
WantedBy=multi-user.target

Then create the backend service:

sudoedit /etc/systemd/system/netdisco-backend.service

And add the content to the file:

[Unit]
Description=Netdisco Backend Service
AssertFileIsExecutable=/home/netdisco/bin/netdisco-backend
After=syslog.target network-online.target

[Service]
Type=forking
User=netdisco
Group=netdisco
ExecStart=/home/netdisco/bin/netdisco-backend start
ExecStop=/home/netdisco/bin/netdisco-backend stop
Restart=on-failure
RestartSec=60

[Install]
WantedBy=multi-user.target

Get systemd to find the new files:

sudo systemctl daemon-reload

Enable and start the services:

sudo systemctl enable --now netdisco-web.service
sudo systemctl enable --now netdisco-backend.service

You can check the status of the services:

sudo systemctl status netdisco-web
sudo systemctl status netdisco-backend

Congratulations, you now have a (hopefully) functioning Netdisco installation!

Login

Navigate to the web interface https://netdisco.example and login using the local administrator user created during the deploy. You should now be presented with a welcome page:

Netdisco web interface after installation

Discover your first device

To start discovering your network, write the IP-address or hostname of any switch in your network and click discover. You can now check the jobs page to verify the status of the discover:

Netdisco job queue

What you will notice is that after discovering the first switch, Netdisco will start discovering neighbouring switches found with LLDP/CDP, assuming the first switch has one.

Discovery (and other commands) can also be executed from the shell of the service user using netdisco-do:

~/bin/netdisco-do discover -d 192.168.100.50

Adding users

To add new users to Netdisco, navigate to the Admin –> User Management page and fill out the needed information:

  • Full name
  • Username
  • Password (if local user, otherwise leave blank)
  • Auth method (only configured ones are shown)

Then click on Add to create the user.

Netdisco user management

Maintenance

To upgrade Netdisco to the latest version, start by running installation script from the Netdisco service user:

sudo -iu netdisco

~/bin/localenv cpanm --notest App::Netdisco
ln -sf ~/perl5/bin/{localenv,netdisco-*} ~/bin/

Once the upgrade finishes, run the deploy:

~/bin/netdisco-deploy

Unless you have a reason for skipping MIB/OUI updates, answer yes to all:

This is the Netdisco 2 deployment script.

Before we continue, the following prerequisites must be in place:
 * Database added to PostgreSQL for Netdisco
 * User added to PostgreSQL with rights to the Netdisco Database
 * "~/environments/deployment.yml" file configured with Database dsn/user/pass
 * A full backup of any existing Netdisco database data
 * Internet access (for OUIs and MIBs)

If you are upgrading Netdisco 2 read the release notes:
https://github.com/netdisco/netdisco/wiki/Release-Notes
There you will find required and incompatible changes
which are not covered by this script.

You will be asked to confirm all changes to your system.

So, is all of the above in place? [y/N]: y

Would you like to deploy the database schema? [y/N]: y
DB schema update complete.
Updating statistics... done.

Download and update vendor MAC prefixes (OUI data)? [y/N]: y
Updating OUI, Manufacturers, Enterprises, and Products... done.

Download and update MIB files? [y/N]: y
MIBs update complete.

Once the deploy is finished, exit from the service user and restart the services:

exit

sudo systemctl restart netdisco-web netdisco-backend

Then login to the web interface to verify. I would suggest running a discovery/macsuck/arpnip against a known device just to verify polling works as well.

References