How to configure SNMP on Linux (Ubuntu, Debian, RHEL): snmpd v2c and v3
Install and configure the Net-SNMP agent (snmpd) on Ubuntu, Debian, RHEL, Rocky or Alma Linux: listen on the network, allow a v2c community only from your monitoring server, create an encrypted SNMPv3 user, open the firewall and test with snmpwalk.
Updated November 2026: rewritten for current Ubuntu, Debian and RHEL 9: drop-in config files, a v2c community locked to one IP, SNMPv3 with SHA-512 and AES instead of MD5, firewall rules, and the errors you actually hit.
SNMP is old, a bit ugly and still everywhere. Zabbix, LibreNMS, PRTG, Cacti and Observium all speak it, and so does every switch and UPS in your rack. If you want a Linux server on the same graphs as the rest of the network, you run the Net-SNMP agent, snmpd.
Short answer:
- Install
snmpd(Ubuntu/Debian) ornet-snmp(RHEL, Rocky, Alma). - Make it listen on the network address, not only
127.0.0.1. - Use SNMPv3 with auth and encryption, or at least a v2c community limited to your monitoring server's IP.
- Open UDP 161 only for that server and test with
snmpwalk.
Everything below was tested with NET-SNMP 5.9.4 on Ubuntu 24.04. The config syntax is the same on RHEL. The differences are the package names, the firewall and one file path.
Install snmpd
On Ubuntu and Debian:
sudo apt update
sudo apt install snmpd snmp
snmpd is the agent, snmp gives you the client tools (snmpwalk, snmpget) for testing. If you want readable names like IF-MIB::ifName instead of raw OIDs in the client output, also install the MIB files:
sudo apt install snmp-mibs-downloader
On RHEL, Rocky Linux, AlmaLinux and Fedora:
sudo dnf install net-snmp net-snmp-utils
sudo systemctl enable --now snmpd
On RHEL the MIBs come with the packages, so there's nothing extra to install. Red Hat's own Net-SNMP guide is old but the directives haven't changed.
The default config and why it shows almost nothing
The stock Ubuntu /etc/snmp/snmpd.conf boils down to this:
agentaddress 127.0.0.1,[::1]
view systemonly included .1.3.6.1.2.1.1
view systemonly included .1.3.6.1.2.1.25.1
rocommunity public default -V systemonly
rocommunity6 public default -V systemonly
includeDir /etc/snmp/snmpd.conf.d
Two things in there explain most "SNMP doesn't work" questions:
agentaddress 127.0.0.1,[::1]means the agent only answers on localhost. Your monitoring server gets a timeout.- The
systemonlyview exposes only thesystemgroup and host uptime. No interfaces, no disks, no CPU. Walk it and you get about 45 lines, thenNo more variables left in this MIB View.
RHEL's default is similar: a public community mapped to a small systemview. So on both, the job is the same: open the listening address, define a proper view and replace public.
Back up the original first:
sudo cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig
A clean snmpd.conf for monitoring
This is the config I'd start with on a server that a single monitoring box polls. Replace 192.168.1.10 with your Zabbix, LibreNMS or PRTG server, and pick your own community string.
sysLocation Rack 2, office server room
sysContact admin@example.com
# Listen on all IPv4 addresses, plus IPv6 localhost
agentaddress udp:161,udp6:[::1]:161
# A view that covers the whole MIB tree
view all included .1
# SNMPv2c: read-only, only from the monitoring server
rocommunity MyS3cretComm 192.168.1.10 -V all
# SNMPv3 user (created below): read-only, must use auth + encryption
rouser monitor authpriv -V all
includeDir /etc/snmp/snmpd.conf.d
A few notes on the lines that matter (the full directive list is in the snmpd.conf man page):
agentaddress udp:161binds to every IPv4 address. To listen on one interface only, useudp:192.168.1.20:161. If the host has no IPv6 at all, drop theudp6part or snmpd refuses to start withError opening specified endpoint.rocommunity <string> <source>is the v2c rule. The source can be one IP or a subnet like192.168.1.0/24. Requests from anywhere else are silently dropped, so a wrong IP looks exactly like a firewall problem.-V allpoints the community or user at the view. If you only need interfaces and system info, make a tighter view instead of.1.- Never use
rwcommunityunless something really needs to write via SNMP. For monitoring, nothing does.
Ubuntu also reads every file in /etc/snmp/snmpd.conf.d/, so you can put your settings in a drop-in like /etc/snmp/snmpd.conf.d/monitoring.conf and leave the main file alone. Just remember to comment out the default agentaddress and rocommunity public lines in the main file, because both files are applied.
Restart and check that it's listening:
sudo systemctl restart snmpd
sudo ss -ulpn | grep 161
SNMPv3: the version you should actually use
SNMPv2c sends the community string in clear text in every packet. Anyone who can sniff the path sees it. SNMPv3 adds a username, authentication and encryption. Every modern monitoring tool supports it, so for anything beyond a home lab, I'd go v3 only and delete the rocommunity line.
The easy way to create a user is net-snmp-create-v3-user. It only works while snmpd is stopped:
sudo systemctl stop snmpd
sudo net-snmp-create-v3-user -ro -a SHA-512 -A 'AuthPassw0rd!42' -x AES -X 'PrivPassw0rd!42' monitor
sudo systemctl start snmpd
What the options mean:
-roread-only user-a SHA-512authentication hash. PlainSHA(SHA-1) also works, and some older pollers only support that. AvoidMD5-Aauth passphrase, at least 8 characters-x AESencryption (AES-128)-Xprivacy passphrase, use a different one from-A
Don't run the tool without options: the interactive mode falls back to MD5 and DES.
The tool writes a createUser line to /var/lib/snmp/snmpd.conf (/var/lib/net-snmp/snmpd.conf on RHEL). On the next start, snmpd turns it into a hashed usmUser entry and removes the plain-text passwords. It also appends rouser monitor to /etc/snmp/snmpd.conf. Since my config above already has rouser monitor authpriv -V all, delete that extra line so the user is restricted to authpriv.
Open the firewall
On Ubuntu with UFW, allow only the monitoring server:
sudo ufw allow from 192.168.1.10 to any port 161 proto udp
On RHEL with firewalld, the simple version opens SNMP to the whole zone:
sudo firewall-cmd --permanent --add-service=snmp
sudo firewall-cmd --reload
A tighter rule that only accepts the monitoring server:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.10" service name="snmp" accept'
sudo firewall-cmd --reload
You only need UDP 161 for polling. UDP 162 is for traps, which go the other way, from the agent to your monitoring server.
Test with snmpwalk and snmpget
Start on the server itself, then repeat from the monitoring box using the server's IP.
SNMPv2c:
snmpget -v2c -c MyS3cretComm 192.168.1.20 sysName.0 sysUpTime.0
SNMPv2-MIB::sysName.0 = STRING: web01
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (155) 0:00:01.55
SNMPv3:
snmpget -v3 -l authPriv -u monitor -a SHA-512 -A 'AuthPassw0rd!42' -x AES -X 'PrivPassw0rd!42' \
192.168.1.20 sysName.0 UCD-SNMP-MIB::memTotalReal.0 UCD-SNMP-MIB::laLoad.1
SNMPv2-MIB::sysName.0 = STRING: web01
UCD-SNMP-MIB::memTotalReal.0 = INTEGER: 8216208 kB
UCD-SNMP-MIB::laLoad.1 = STRING: 0.03
A few walks worth knowing:
# Interfaces
snmpwalk -v2c -c MyS3cretComm 192.168.1.20 IF-MIB::ifName
# Disks and memory
snmpwalk -v2c -c MyS3cretComm 192.168.1.20 HOST-RESOURCES-MIB::hrStorageDescr
# Everything (long)
snmpwalk -v2c -c MyS3cretComm 192.168.1.20 .1
Before you go hunting in snmpd.conf, check the port is reachable at all. A quick UDP probe with netcat is covered in my netcat examples.
Common errors and what they mean
| Error | Usual cause |
|---|---|
Timeout: No Response from 192.168.1.20 |
snmpd only listens on 127.0.0.1, firewall blocks UDP 161, wrong community, or the request comes from an IP not allowed in rocommunity. v2c gives no hint which one |
No more variables left in this MIB View after a few lines |
The community or user is tied to the default systemonly view. Use a wider view with -V |
Unknown user name |
The v3 user doesn't exist: snmpd was running when you ran net-snmp-create-v3-user, or you started snmpd with -C, which skips the persistent file |
Authentication failure (incorrect password, community or key) |
Wrong -A passphrase or wrong -a algorithm (SHA vs SHA-512) |
| v3 timeout but auth looks right | Wrong -X privacy passphrase or -x algorithm. Bad encryption keys produce a timeout, not an error |
authorizationError (access denied to that object) |
The user exists but you asked with a lower security level than rouser requires, for example -l noAuthNoPriv against an authpriv user |
passphrase chosen is below the length requirements of the USM (min=8) |
-A or -X shorter than 8 characters |
Error opening specified endpoint "udp:161" |
Another snmpd is already running, or the same agentaddress is loaded twice (for example the main file plus a drop-in, or -c pointing at the default file) |
Cannot find module (SNMPv2-MIB) |
Client-side only, MIB files missing. Install snmp-mibs-downloader and comment out mibs : in /etc/snmp/snmp.conf |
For the logs, run journalctl -u snmpd -f while you test. On a Cacti box, a host stuck in "unknown" is usually one of the first three rows. See Cacti host status unknown.
SNMP or an agent?
If you run Zabbix, its own agent gives you more (per-process stats, log monitoring, custom checks) with less fuss, see how to install the Zabbix agent on Linux. I still set up SNMP when a tool only speaks SNMP (LibreNMS, PRTG, a lot of NOC dashboards) or when I want the server next to the switches using the same templates. For quick ad-hoc checks on one box, plain command-line tools are faster. I've listed mine in how to monitor network traffic on Linux.
My take
Configure SNMP once, carefully, and it runs for years without anyone touching it. My rules: v3 with authPriv wherever the monitoring tool supports it, v2c only from one IP and never with public, read-only always, and UDP 161 closed to everyone except the poller. Most broken setups I see are the default config with only agentaddress changed, which leaves public open to the whole network.
FAQ
Where is the SNMP config file on Linux?
The agent config is /etc/snmp/snmpd.conf on Ubuntu, Debian, RHEL, Rocky and Alma. Ubuntu also reads drop-in files from /etc/snmp/snmpd.conf.d/. SNMPv3 users are stored in a separate persistent file: /var/lib/snmp/snmpd.conf on Debian and Ubuntu, /var/lib/net-snmp/snmpd.conf on RHEL.
What port does SNMP use?
The agent listens on UDP 161 for polling requests. Traps and informs are sent to UDP 162 on the monitoring server. Allow UDP 161 only from the systems that poll the host.
How do I enable SNMP on Ubuntu?
Install it with sudo apt install snmpd snmp, change agentaddress in /etc/snmp/snmpd.conf from 127.0.0.1 to udp:161, replace the public community with your own string limited to your monitoring server's IP (or create an SNMPv3 user), then run sudo systemctl restart snmpd.
Should I use SNMP v2c or v3?
Use SNMPv3 with authPriv when your monitoring tool supports it, because v2c sends the community string in clear text. If you must use v2c, make it read-only, use a long random community string and restrict it to the poller's IP in both snmpd.conf and the firewall.
How do I test SNMP from the command line?
Use snmpwalk or snmpget from the snmp package (net-snmp-utils on RHEL). For v2c: snmpwalk -v2c -c <community> <host> system. For v3: snmpwalk -v3 -l authPriv -u <user> -a SHA-512 -A <authpass> -x AES -X <privpass> <host> system.