mirror of
https://github.com/wickedyoda/public-setupfiles.git
synced 2026-11-16 13:31:56 -06:00
Reorganize repository structure and refresh READMEs
This commit is contained in:
1 parent
2270530d9e
commit
a8b7ccbf2a
170 files changed
+616
-1391
No files matched your search
@@ -0,0 +1,18 @@
|
||||
# snmp
|
||||
|
||||
## Overview
|
||||
SNMP setup scripts for Linux, macOS, and OpenWrt along with default configuration references.
|
||||
|
||||
## Contents
|
||||
- `Setup_snmp_macos.sh`
|
||||
- `openwrt_snmp_defaults.txt`
|
||||
- `setup_snmp.sh`
|
||||
- `setup_snmp_openwrt.sh`
|
||||
- `setup_snmp_openwrt_publicv2.sh`
|
||||
- `setup_snmp_openwrt_v2.sh`
|
||||
|
||||
## Usage
|
||||
Use the script that matches the target platform and validate the SNMP version and community or credential model first.
|
||||
|
||||
## Notes
|
||||
SNMP settings expose monitoring data, so align them with the security posture of the network.
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if the script is running on macOS
|
||||
if [[ "$(uname)" != "Darwin" ]]; then
|
||||
echo "This script is designed to run on macOS."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if Homebrew is installed
|
||||
if ! command -v brew &> /dev/null; then
|
||||
echo "Homebrew is not installed. Installing Homebrew..."
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
fi
|
||||
|
||||
# Install SNMP tools
|
||||
echo "Installing SNMP tools via Homebrew..."
|
||||
brew install net-snmp
|
||||
|
||||
# Prompt for user input
|
||||
echo "Enter the SNMPv3 username (e.g., admin):"
|
||||
read SNMP_USER
|
||||
echo "Enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD
|
||||
echo "Re-enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD_CONFIRM
|
||||
|
||||
# Verify password confirmation
|
||||
if [ "$SNMP_PASSWORD" != "$SNMP_PASSWORD_CONFIRM" ]; then
|
||||
echo "Passwords do not match. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Enter the system location (e.g., Office):"
|
||||
read SYS_LOCATION
|
||||
echo "Enter the system contact (e.g., admin@example.com):"
|
||||
read SYS_CONTACT
|
||||
|
||||
# Configure SNMPv3
|
||||
echo "Configuring SNMPv3..."
|
||||
SNMP_CONF="/usr/local/etc/snmp/snmpd.conf"
|
||||
sudo mkdir -p /usr/local/etc/snmp
|
||||
|
||||
cat <<EOT | sudo tee $SNMP_CONF
|
||||
# SNMPv3 Configuration
|
||||
createUser $SNMP_USER MD5 $SNMP_PASSWORD AES $SNMP_PASSWORD
|
||||
rouser $SNMP_USER priv
|
||||
agentAddress udp:161,udp6:[::1]:161
|
||||
view all included .1 80
|
||||
access notConfigGroup "" any noauth exact all none none
|
||||
sysLocation "$SYS_LOCATION"
|
||||
sysContact "$SYS_CONTACT"
|
||||
EOT
|
||||
|
||||
# Restrict permissions on the configuration file
|
||||
echo "Setting proper permissions for SNMP configuration..."
|
||||
sudo chmod 600 $SNMP_CONF
|
||||
|
||||
# Start SNMP service
|
||||
echo "Starting SNMP service..."
|
||||
sudo launchctl load -w /Library/LaunchDaemons/org.net-snmp.snmpd.plist
|
||||
|
||||
# Verify SNMP configuration
|
||||
echo "Verifying SNMP service..."
|
||||
snmpwalk -v3 -u $SNMP_USER -a MD5 -A $SNMP_PASSWORD -x AES -X $SNMP_PASSWORD -l authPriv localhost
|
||||
|
||||
echo "SNMPv3 installation and configuration complete on macOS."
|
||||
@@ -0,0 +1,130 @@
|
||||
config agent
|
||||
option agentaddress UDP:161,UDP6:161
|
||||
|
||||
config agentx
|
||||
option agentxsocket /var/run/agentx.sock
|
||||
|
||||
config com2sec public
|
||||
option secname ro
|
||||
option source default
|
||||
option community public
|
||||
|
||||
config com2sec private
|
||||
option secname rw
|
||||
option source localhost
|
||||
option community private
|
||||
|
||||
config com2sec6 public6
|
||||
option secname ro
|
||||
option source default
|
||||
option community public
|
||||
|
||||
config com2sec6 private6
|
||||
option secname rw
|
||||
option source localhost
|
||||
option community private
|
||||
|
||||
config group public_v1
|
||||
option group public
|
||||
option version v1
|
||||
option secname ro
|
||||
|
||||
config group public_v2c
|
||||
option group public
|
||||
option version v2c
|
||||
option secname ro
|
||||
|
||||
config group public_usm
|
||||
option group public
|
||||
option version usm
|
||||
option secname ro
|
||||
|
||||
config group private_v1
|
||||
option group private
|
||||
option version v1
|
||||
option secname rw
|
||||
|
||||
config group private_v2c
|
||||
option group private
|
||||
option version v2c
|
||||
option secname rw
|
||||
|
||||
config group private_usm
|
||||
option group private
|
||||
option version usm
|
||||
option secname rw
|
||||
|
||||
config view all
|
||||
option viewname all
|
||||
option type included
|
||||
option oid .1
|
||||
|
||||
config access public_access
|
||||
option group public
|
||||
option context none
|
||||
option version any
|
||||
option level noauth
|
||||
option prefix exact
|
||||
option read all
|
||||
option write none
|
||||
option notify none
|
||||
|
||||
config access private_access
|
||||
option group private
|
||||
option context none
|
||||
option version any
|
||||
option level noauth
|
||||
option prefix exact
|
||||
option read all
|
||||
option write all
|
||||
option notify all
|
||||
|
||||
config system
|
||||
option sysLocation 'Mothers'
|
||||
option sysContact 'alerts@tyates.one'
|
||||
option sysName 'Mothers Router'
|
||||
# option sysServices 72
|
||||
# option sysDescr 'adult playground'
|
||||
# option sysObjectID '1.2.3.4'
|
||||
|
||||
config exec
|
||||
option name filedescriptors
|
||||
option prog /bin/cat
|
||||
option args /proc/sys/fs/file-nr
|
||||
# option miboid 1.2.3.4
|
||||
|
||||
config engineid
|
||||
# option engineid 'LEDE'
|
||||
option engineidtype '3'
|
||||
option engineidnic 'eth0'
|
||||
|
||||
#config trapcommunity 'trapcommunity'
|
||||
# option community 'public'
|
||||
|
||||
#config trapsink
|
||||
# option host 'nms.system.com'
|
||||
# option community 'public'
|
||||
# option port '162'
|
||||
|
||||
#config trap2sink
|
||||
# option host 'nms.system.com'
|
||||
# option community 'secret'
|
||||
# option port '162'
|
||||
|
||||
#config informsink
|
||||
# option host 'nms.sytem.com'
|
||||
# option community 'public'
|
||||
# option port '162'
|
||||
|
||||
#config authtrapenable 'authtrapenable'
|
||||
# option enable '1'
|
||||
|
||||
#config v1trapaddress 'v1trapaddress'
|
||||
# option host '1.2.3.4'
|
||||
|
||||
#config trapsess 'trapsess'
|
||||
# option trapsess '-v 3 -e 0x80001f88808c18d3f7b0000 -u trapuser -a MD5 -A administrator -l authPriv -x DES -X rootpasswd udp:127.0.0.1:162'
|
||||
|
||||
config snmpd general
|
||||
option enabled '1'
|
||||
# list network 'wan'
|
||||
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Prompt for user input
|
||||
echo "Enter the SNMPv3 username (e.g., admin):"
|
||||
read SNMP_USER
|
||||
echo "Enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD
|
||||
echo "Re-enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD_CONFIRM
|
||||
|
||||
# Verify password confirmation
|
||||
if [ "$SNMP_PASSWORD" != "$SNMP_PASSWORD_CONFIRM" ]; then
|
||||
echo "Passwords do not match. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Enter the system location (e.g., Data Center):"
|
||||
read SYS_LOCATION
|
||||
echo "Enter the system contact (e.g., admin@example.com):"
|
||||
read SYS_CONTACT
|
||||
|
||||
# Update the system
|
||||
echo "Updating system packages..."
|
||||
apt update -y && apt upgrade -y
|
||||
|
||||
# Install SNMP and related packages
|
||||
echo "Installing SNMP and dependencies..."
|
||||
apt install -y snmpd snmp libsnmp-dev
|
||||
|
||||
# Stop SNMP service to configure it
|
||||
echo "Stopping SNMP service..."
|
||||
systemctl stop snmpd
|
||||
|
||||
# Backup the original SNMP configuration file
|
||||
echo "Backing up the original configuration file..."
|
||||
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak
|
||||
|
||||
# Configure SNMPv3
|
||||
echo "Configuring SNMPv3..."
|
||||
cat <<EOT > /etc/snmp/snmpd.conf
|
||||
# SNMPv3 Configuration
|
||||
createUser $SNMP_USER MD5 $SNMP_PASSWORD AES $SNMP_PASSWORD
|
||||
rouser $SNMP_USER priv
|
||||
agentAddress udp:161,udp6:[::1]:161
|
||||
view all included .1 80
|
||||
access notConfigGroup "" any noauth exact all none none
|
||||
sysLocation "$SYS_LOCATION"
|
||||
sysContact "$SYS_CONTACT"
|
||||
EOT
|
||||
|
||||
# Restrict access to the configuration file
|
||||
echo "Restricting access to the configuration file..."
|
||||
chmod 600 /etc/snmp/snmpd.conf
|
||||
|
||||
# Start and enable SNMP service
|
||||
echo "Starting and enabling SNMP service..."
|
||||
systemctl enable snmpd
|
||||
systemctl start snmpd
|
||||
|
||||
# Verify SNMP configuration
|
||||
echo "Verifying SNMP service..."
|
||||
snmpstatus -v3 -u $SNMP_USER -a MD5 -A $SNMP_PASSWORD -x AES -X $SNMP_PASSWORD -l authPriv localhost
|
||||
|
||||
echo "SNMPv3 installation and configuration complete."
|
||||
@@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if the script is running on OpenWrt
|
||||
if ! grep -q "OpenWrt" /etc/os-release; then
|
||||
echo "This script is designed to run on OpenWrt."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prompt for user input
|
||||
echo "Enter the SNMPv3 username (e.g., admin):"
|
||||
read SNMP_USER
|
||||
echo "Enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD
|
||||
echo "Re-enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD_CONFIRM
|
||||
|
||||
# Verify password confirmation
|
||||
if [ "$SNMP_PASSWORD" != "$SNMP_PASSWORD_CONFIRM" ]; then
|
||||
echo "Passwords do not match. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Enter the system location (e.g., Router Closet):"
|
||||
read SYS_LOCATION
|
||||
echo "Enter the system contact (e.g., admin@example.com):"
|
||||
read SYS_CONTACT
|
||||
|
||||
# Update opkg and install SNMP
|
||||
echo "Updating package list..."
|
||||
opkg update
|
||||
|
||||
echo "Installing SNMP daemon..."
|
||||
opkg install snmpd snmp-utils
|
||||
|
||||
# Stop SNMP service to configure it
|
||||
echo "Stopping SNMP service..."
|
||||
/etc/init.d/snmpd stop
|
||||
|
||||
# Backup the original SNMP configuration file
|
||||
echo "Backing up the original configuration file..."
|
||||
cp /etc/config/snmpd /etc/config/snmpd.bak
|
||||
|
||||
# Configure SNMPv3
|
||||
echo "Configuring SNMPv3..."
|
||||
cat <<EOT > /etc/config/snmpd
|
||||
config agent
|
||||
option agentaddress 161
|
||||
option agentxsocket /var/agentx/master
|
||||
|
||||
config view
|
||||
option name all
|
||||
option type included
|
||||
option subtree .1
|
||||
|
||||
config access
|
||||
option groupname notConfigGroup
|
||||
option context ""
|
||||
option version v3
|
||||
option level authPriv
|
||||
option readview all
|
||||
option writeviewe
|
||||
option notifyview none
|
||||
|
||||
config user
|
||||
option name $SNMP_USER
|
||||
option authproto MD5
|
||||
option authpass $SNMP_PASSWORD
|
||||
option privproto AES
|
||||
option privpass $SNMP_PASSWORD
|
||||
|
||||
config system
|
||||
option location "$SYS_LOCATION"
|
||||
option contact "$SYS_CONTACT"
|
||||
EOT
|
||||
|
||||
# Restart and enable SNMP service
|
||||
echo "Starting and enabling SNMP service..."
|
||||
/etc/init.d/snmpd enable
|
||||
/etc/init.d/snmpd start
|
||||
|
||||
# Verify SNMP configuration
|
||||
echo "Verifying SNMP service..."
|
||||
snmpwalk -v3 -u $SNMP_USER -a MD5 -A $SNMP_PASSWORD -x AES -X $SNMP_PASSWORD -l authPriv localhost
|
||||
|
||||
echo "SNMPv3 installation and configuration complete on OpenWrt."
|
||||
@@ -0,0 +1,76 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Ensure the script is run as root
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "This script must be run as root. Use sudo or run as root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Starting SNMPv2 configuration on OpenWRT..."
|
||||
|
||||
# Install SNMP if not installed
|
||||
opkg update
|
||||
opkg install snmpd
|
||||
|
||||
# Define SNMP configuration file location
|
||||
SNMP_CONFIG="/etc/config/snmpd"
|
||||
|
||||
# Backup existing SNMP configuration
|
||||
if [ -f "$SNMP_CONFIG" ]; then
|
||||
echo "Backing up existing SNMP configuration..."
|
||||
cp "$SNMP_CONFIG" "$SNMP_CONFIG.bak"
|
||||
fi
|
||||
|
||||
# Create SNMPv2 configuration with public community
|
||||
echo "Configuring SNMPv2 with public community..."
|
||||
|
||||
cat <<EOL > "$SNMP_CONFIG"
|
||||
config system
|
||||
option enable '1'
|
||||
|
||||
config agent
|
||||
option agentaddress 'udp:161'
|
||||
|
||||
config com2sec
|
||||
option secname 'public'
|
||||
option source 'default'
|
||||
option community 'public'
|
||||
|
||||
config group
|
||||
option groupname 'publicGroup'
|
||||
option securitymodel 'v2c'
|
||||
option secname 'public'
|
||||
|
||||
config view
|
||||
option viewname 'all'
|
||||
option type 'included'
|
||||
option oid '.1'
|
||||
|
||||
config access
|
||||
option groupname 'publicGroup'
|
||||
option securitymodel 'v2c'
|
||||
option context 'none'
|
||||
option level 'noAuthNoPriv'
|
||||
option prefix 'exact'
|
||||
option read 'all'
|
||||
option write 'none'
|
||||
option notify 'none'
|
||||
EOL
|
||||
|
||||
# Restart the SNMP service to apply changes
|
||||
echo "Restarting SNMP service..."
|
||||
/etc/init.d/snmpd restart
|
||||
|
||||
# Verify if SNMP is running
|
||||
if pgrep snmpd > /dev/null; then
|
||||
echo "SNMP service is running."
|
||||
else
|
||||
echo "Failed to start SNMP service."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test SNMPv2 configuration
|
||||
echo "Testing SNMPv2 configuration with snmpwalk..."
|
||||
snmpwalk -v2c -c public localhost system
|
||||
|
||||
echo "SNMPv2 configuration on OpenWRT completed successfully!"
|
||||
@@ -0,0 +1,93 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
# Confirm OpenWrt OS
|
||||
if ! grep -q "OpenWrt" /etc/os-release; then
|
||||
echo "❌ This script must be run on an OpenWrt device."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✔ OpenWrt detected: $(. /etc/os-release && echo $PRETTY_NAME)"
|
||||
|
||||
# Get SNMPv3 user info
|
||||
read -p "Enter SNMPv3 username (e.g., admin): " SNMP_USER
|
||||
read -s -p "Enter SNMPv3 password: " SNMP_PASSWORD
|
||||
echo
|
||||
read -s -p "Re-enter SNMPv3 password: " SNMP_PASSWORD_CONFIRM
|
||||
echo
|
||||
|
||||
if [ "$SNMP_PASSWORD" != "$SNMP_PASSWORD_CONFIRM" ]; then
|
||||
echo "❌ Passwords do not match. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -p "Enter SNMP system location (e.g., Router Closet): " SYS_LOCATION
|
||||
read -p "Enter SNMP system contact (e.g., admin@example.com): " SYS_CONTACT
|
||||
|
||||
# Install SNMP
|
||||
echo "📦 Installing snmpd and snmp-utils..."
|
||||
opkg update
|
||||
opkg install snmpd snmp-utils
|
||||
|
||||
# Stop service before config
|
||||
echo "🛑 Stopping SNMP service..."
|
||||
/etc/init.d/snmpd stop
|
||||
|
||||
# Backup config
|
||||
cp /etc/config/snmpd /etc/config/snmpd.bak.$(date +%s)
|
||||
|
||||
# Write SNMP config
|
||||
cat <<EOF > /etc/config/snmpd
|
||||
config agent
|
||||
option agentaddress '161'
|
||||
option agentxsocket '/var/agentx/master'
|
||||
|
||||
config system
|
||||
option location '$SYS_LOCATION'
|
||||
option contact '$SYS_CONTACT'
|
||||
|
||||
config view
|
||||
option name 'all'
|
||||
option type 'included'
|
||||
option subtree '.1'
|
||||
|
||||
config access
|
||||
option groupname 'notConfigGroup'
|
||||
option context ''
|
||||
option version 'v3'
|
||||
option level 'authPriv'
|
||||
option readview 'all'
|
||||
option writeview 'all'
|
||||
option notifyview 'all'
|
||||
|
||||
config user
|
||||
option name '$SNMP_USER'
|
||||
option authproto 'MD5'
|
||||
option authpass '$SNMP_PASSWORD'
|
||||
option privproto 'AES'
|
||||
option privpass '$SNMP_PASSWORD'
|
||||
EOF
|
||||
|
||||
# Enable and start SNMP
|
||||
echo "🚀 Starting SNMP service..."
|
||||
/etc/init.d/snmpd enable
|
||||
/etc/init.d/snmpd start
|
||||
|
||||
# Configure firewall
|
||||
echo "🔐 Adding firewall rule to allow SNMP on LAN (UDP/161)..."
|
||||
uci add firewall rule
|
||||
uci set firewall.@rule[-1].name='Allow-SNMP'
|
||||
uci set firewall.@rule[-1].src='lan'
|
||||
uci set firewall.@rule[-1].proto='udp'
|
||||
uci set firewall.@rule[-1].dest_port='161'
|
||||
uci set firewall.@rule[-1].target='ACCEPT'
|
||||
uci commit firewall
|
||||
/etc/init.d/firewall restart
|
||||
|
||||
# Test SNMP locally
|
||||
echo "🧪 Running SNMPv3 test on localhost..."
|
||||
snmpwalk -v3 -u "$SNMP_USER" -l authPriv -a MD5 -A "$SNMP_PASSWORD" -x AES -X "$SNMP_PASSWORD" localhost
|
||||
|
||||
echo "✅ SNMPv3 successfully configured on OpenWrt ${PRETTY_NAME}"
|
||||
Reference in new issue
Block a user