Skip to content

Instantly share code, notes, and snippets.

@buddyp1952
Last active February 25, 2020 19:55
Show Gist options
  • Save buddyp1952/86a7cbade55a7cea6e3bc01742f153f9 to your computer and use it in GitHub Desktop.
Save buddyp1952/86a7cbade55a7cea6e3bc01742f153f9 to your computer and use it in GitHub Desktop.
Install snmpd on ubuntu 18.04
#!/bin/bash -x
# install packages
sudo apt install snmp snmpd snmp-mibs-downloader -y -qq
# create config file
cat > /tmp/snmpd.conf << EOF
# Listen for connections on all interfaces (IPv4 only)
agentAddress udp:161
# We do not want annoying "Connection from UDP: " messages in syslog.
# If the following option is commented out, snmpd will print each incoming
# connection, which can be useful for debugging.
dontLogTCPWrappersConnects yes
rocommunity communitystr 192.168.0.0/16
syslocation home
sysContact Joel
sysServices 72
#
# AgentX is only needed on routers
#
#master agentx
EOF
sudo mv -f /tmp/snmpd.conf /etc/snmp/snmpd.conf
sudo chmod 600 /etc/snmp/snmpd.conf
sudo chown root.root /etc/snmp/snmpd.conf
# Only log warnings and more severe
sudo sed -i "s|-Lsd|-LSwd|" /lib/systemd/system/snmpd.service
sudo sed -i 's|^Environment="MIBS="|#Environment="MIBS="|' /lib/systemd/system/snmpd.service
sudo systemctl daemon-reload
sudo service snmpd restart
# verify it works
snmpwalk -c communitystr -v2c -O e $(echo $(host $(hostname)) | cut -d ' ' -f 4) | tail
sudo grep snmp /var/log/syslog | tail
# get rid of statfs errors in log
cat > /tmp/040-snmp-statfs.conf << EOF
if $programname == 'snmpd' and $msg contains 'statfs' then {
stop
}
EOF
sudo mv -f /tmp/040-snmp-statfs.conf /etc/rsyslog.d/040-snmp-statfs.conf
sudo chown root.root /etc/rsyslog.d/040-snmp-statfs.conf
sudo systemctl restart rsyslog
sudo tail /var/log/syslog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment