NetBox is a powerful open-source tool for IP address management that can help you manage your network more efficiently. Self-hosting NetBox on a VPS allows you to have complete control over your data and customizations. This guide will walk you through the installation of NetBox on a VPS, using Docker for simplicity and efficiency.
We ended up running NetBox on a VPS rather than on a box at home for a fairly boring reason: it is the tool you most need to look at when the network at home is the thing that broke. Keeping the source of truth off the network it documents has saved us twice.
Prerequisites
Before getting started, ensure you have the following:
- VPS Server: Choose a VPS provider that suits your budget and needs. Hereโs a quick comparison of several top providers:
| Provider | Monthly Price (EUR) | Monthly Price (USD) | Key Features |
|---|---|---|---|
| Contabo VPS | 5.99 | ~6.00 | Affordable pricing, good performance |
| Hetzner Cloud | 5.49 | ~4.50 | High performance, flexible scaling |
| DigitalOcean | ~5.55 | 6.00 | User-friendly UI, great community support |
| Vultr | ~5.55 | 6.00 | Global data centers, reliable infrastructure |
| Linode | ~4.75 | 5.00 | Excellent customer service and performance |
You can choose any of the above VPS providers by following their respective links for ease of setup: Contabo, Hetzner Cloud, DigitalOcean, Vultr, and Linode.
-
A Domain Name: While optional, having a domain name makes it easier to access your NetBox instance.
-
Basic Knowledge of Docker: Familiarity with Docker commands will help you through the installation.
Setting Up Your VPS
-
Choose Your Operating System: Most users prefer Ubuntu for its stability and support. Install the latest LTS version (e.g., Ubuntu 22.04).
-
Update Your System: Before installing Docker, ensure your system is up to date using:
sudo apt update && sudo apt upgrade -y -
Install Docker: Use the following commands to install Docker:
sudo apt install -y docker.io sudo systemctl start docker sudo systemctl enable docker -
Install Docker Compose: Download the latest version of Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
Deploying NetBox
With Docker installed, you are now ready to deploy NetBox. Follow these steps:
-
Create a Project Directory:
mkdir /opt/netbox cd /opt/netbox -
Create Docker Compose File: Create a
docker-compose.ymlfile with the following configuration:version: '3.9' services: netbox: image: netbox-community/netbox:latest environment: - SECRET_KEY=your_secret_key - ALLOWED_HOSTS=yourdomain.com ports: - "8000:8080" volumes: - netbox-data:/opt/netbox/netbox/media postgres: image: postgres:latest environment: - POSTGRES_DB=netbox - POSTGRES_USER=netbox - POSTGRES_PASSWORD=your_password volumes: - postgres-data:/var/lib/postgresql/data volumes: netbox-data: postgres-data:Replace
your_secret_key,yourdomain.com, andyour_passwordwith your desired values. -
Run Docker Compose: Start the services with:
sudo docker-compose up -d -
Initialize the Database: Connect to the NetBox container:
sudo docker exec -it netbox-netbox-1 bashThen run the database migrations:
python3 manage.py migrate -
Create a Superuser: While inside the container, create an admin user:
python3 manage.py createsuperuser
Follow the prompts to set up your admin credentials.
Two things bit us on the first run. NetBox and Postgres start at the same time under this compose file, and NetBox will fail its first migration if Postgres is not ready yet, which is exactly why the migrate step above is run separately instead of being left to sort itself out. The second is SECRET_KEY. Set it to something real before the first start rather than after, or you will be invalidating every session later for no good reason.
Accessing NetBox
With everything in place, access your NetBox instance at http://yourdomain.com:8000. Log in using the superuser credentials you created.
Leave port 8000 reachable from the open internet for that first login and nothing more. We put NetBox behind a reverse proxy with TLS the same evening we deployed it, and it is worth doing before you type anything into it that you care about.
FAQs
1. What is NetBox, and why should I self-host it?
NetBox is an open-source tool designed for IP address management and data center infrastructure management. Self-hosting gives you control over your installation, allowing customizations to fit specific network requirements. Moreover, hosting NetBox on a VPS ensures you maintain your dataโs privacy and security, reducing reliance on external providers.
2. Can I use NetBox without Docker?
While it is possible to install NetBox without Docker, using Docker simplifies the deployment process, making it easier to manage dependencies and configurations. Docker provides isolation and simplifies updates. If youโre familiar with traditional software installation methods and wish to explore them, refer to the official documentation on the NetBox GitHub page.
3. Which VPS provider is best for self-hosting NetBox?
The best VPS provider depends on your budget and requirements. Contabo and Hetzner Cloud offer some of the most affordable options, while DigitalOcean and Linode provide excellent user experiences. For a comprehensive comparison of VPS providers, check out our full VPS comparison.
By following this guide, you should now have a fully functional NetBox instance running on your VPS. Enjoy managing your IP addresses efficiently!