Difference between revisions of "SNMP: UBUNTU 20.04 instalasi SNMP"

From OnnoWiki
Jump to navigation Jump to search
Line 69: Line 69:
 
Kita akan melakukan beberapa perubahan kecil. Ini akan digunakan untuk mem-bootstrap konfigurasi agar bisa memanage server dari server lain.
 
Kita akan melakukan beberapa perubahan kecil. Ini akan digunakan untuk mem-bootstrap konfigurasi agar bisa memanage server dari server lain.
  
First, you need to change the agentAddress directive. Currently, it is set to only allow connections originating from the local computer. You’ll need to comment out the current line, and uncomment the line underneath, which allows all connections.
+
'''SATU'''
/etc/snmp/snmpd.conf
+
Ubah agentAddress agar bisa di akses dari komputer lain
  
# Listen for connections from the local system only
+
  /etc/snmp/snmpd.conf
#agentAddress  udp:127.0.0.1:161
 
#  Listen for connections on all interfaces (both IPv4 *and* IPv6)
 
agentAddress udp:161,udp6:[::1]:161
 
  
Note: Since allowing all connections like this is not a security best practice, it is best to make sure to lock this back down soon, after the bootstraping is complete.
+
#  Listen for connections from the local system only
 +
#agentAddress  udp:127.0.0.1:161
 +
#  Listen for connections on all interfaces (both IPv4 *and* IPv6)
 +
agentAddress udp:161,udp6:[::1]:161
  
Next, you will temporarily insert a createUser line. These directives are not normally kept in this file; you will be removing it again in a moment.
+
Setelah selesai melakukan bootstraping, sebaiknya di set hanya localhost yang bisa akses.
  
The user you are creating will be called bootstrap and will be used as a template in which to create your first actual user. The SNMP packages do this through a process of cloning the user’s properties.
+
'''DUA'''
 +
Mendefinisikan pengguna. Pengguna yang kita buat akan disebut bootstrap dan akan digunakan sebagai template untuk membuat pengguna pertama. Paket SNMP melakukan ini melalui proses kloning properti pengguna.
  
When defining a new user, you must specify the authentication type (MD5 or SHA) as well as supply a passphrase that must be at least eight characters. If you plan on using encryption for the transfer, like you will in this tutorial, you also must specify the privacy protocol (DES or AES) and optionally a privacy protocol passphrase. If no privacy protocol passphrase is supplied, the authentication passphrase will be used for the privacy protocol as well.
+
Saat mendefinisikan pengguna baru, kita harus menentukan jenis otentikasi (MD5 atau SHA) serta memberikan frasa sandi yang paling tidak harus delapan karakter. Jika kita berencana menggunakan enkripsi untuk transfer, kita harus menentukan protokol privasi (DES atau AES) dan secara opsional frasa sandi protokol privasi. Jika tidak ada frasa sandi protokol privasi yang diberikan, frasa sandi otentikasi juga akan digunakan untuk protokol privasi.
  
Add this createUser line to the end of the file:
+
Tambahkan createUser line di akhir file:
/etc/snmp/snmpd.conf
 
  
...
+
/etc/snmp/snmpd.conf
createUser bootstrap MD5 temp_password DES
+
 +
...
 +
createUser bootstrap MD5 temp_password DES
 +
 
 +
Sekarang kita memiliki pengguna baru yang ditentukan, kita dapat mengatur tingkat akses yang akan dimiliki oleh pengguna ini. Dalam tutorial ini kita akan mengatur ini untuk pengguna bootstrap, dan juga untuk pengguna baru yang akan kita buat, yang disebut demo. Kita akan mengijinkan mereka read dan write akses dengan menggunakan petunjuk rwuser (alternatifnya adalah rouser untuk read-only access).
  
Now that you have a new user specified, you can set up the level of access that this user will have. In this tutorial you will set this up for your bootstrap user, and also for the new user you will be creating, called demo. You will allow them read and write access by using the rwuser directive (the alternative is rouser for read-only access).
+
Kita juga akan menegakkan penggunaan enkripsi dengan menentukan priv setelah pengguna. Jika kita ingin membatasi pengguna ke bagian tertentu dari MIB, kita bisa menentukan highest-level object identifier (OID) yang bisa diakses pengguna di akhir baris.
  
You will also enforce the use of encryption by specifying priv after your user. If you wanted to restrict the user to a specific part of the MIB, you could specify the highest-level object identifier (OID) that the user should have access to at the end of the line.
+
Dalam tutorial ini, ke dua baris yang dibutuhkan adalah sebagai berikut,
  
For this tutorial’s purposes, both of your lines will be as follows:
+
/etc/snmp/snmpd.conf
/etc/snmp/snmpd.conf
 
  
 
  ...
 
  ...
Line 102: Line 105:
 
  rwuser demo priv
 
  rwuser demo priv
  
When you are finished making these changes, save and close the file.
+
Setelah sudah konfigurasi snmpd.conf, save & close file.
  
To implement these changes, restart the snmpd service on your agent server:
+
'''Restart'''
  
 
  sudo systemctl restart snmpd
 
  sudo systemctl restart snmpd
  
The SNMP daemon will listen for connections on port :161. Configure UFW to allow connections from the manager server to this port:
+
SNMP daemon akan mendengarkan port 161. Konfigurasi UFW untuk mengijinkan sambungan port 161
  
 
  sudo ufw allow from manager_server_ip_address to any port 161
 
  sudo ufw allow from manager_server_ip_address to any port 161
 
You can learn more about UFW in How To Set Up a Firewall with UFW on Ubuntu 18.04.
 
 
Now that the agent server is configured, you can connect to your agent server from the manager server to verify the connection.
 
  
 
==Step 4 — Verifying Authentication to the Agent Server==
 
==Step 4 — Verifying Authentication to the Agent Server==

Revision as of 10:32, 12 May 2020

Sumber: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-an-snmp-daemon-and-client-on-ubuntu-18-04


Sebagian besar menjadi administrator sistem mengumpulkan informasi yang akurat tentang server dan infrastruktur. Ada sejumlah tool dan opsi untuk mengumpulkan dan memproses informasi jenis ini. Banyak dari mereka dibangun di atas teknologi yang disebut SNMP.

SNMP adalah singkatan dari simple network management protocol. Ini adalah cara server dapat berbagi informasi tentang keadaan server saat ini, dan juga saluran di mana seorang administrator dapat mengubah pre-defined value. Sementara protokol itu sendiri ringan, struktur program yang mengimplementasikan SNMP dapat berkembang menjadi kompleks.

Dalam panduan ini, kita akan mengatur tool untuk berkomunikasi menggunakan SNMP. Kita akan menggunakan dua server Ubuntu 20.04 untuk mendemokan. Satu akan berisi SNMP manager, yang akan berbicara dengan agen untuk mengimplementasikan network device. Komputer tempat SNMP manager akan disebut server manajer. Server yang lain akan memiliki SNMP agent yang akan bertindak atas perintah dari server manajer. Ini akan disebut server agen. Kita dapat memilih untuk menginstal agen pada mesin manajer juga, tetapi memisahkannya membuatnya lebih mudah untuk menunjukkan fungsionalitas apa yang disediakan oleh masing-masing komponen.

Pra-Syarat

Ini tutorial ini kita akan membutuhkan:

  • Dua Ubuntu 20.04 server kosong.
  • Ada non-root user dengan sudo privileges.
  • Firewall yang di konfigurasi dengan ufw.

Step 1 — Installing the SNMP Daemon and Utilities

Masuk ke manager server, dengan perintah,

ssh your_username@manager_server_ip_address

Lakukan,

sudo apt update
sudo apt -y install snmp snmp-mibs-downloader

Paket snmp menyediakan koleksi tool CLI untuk mengirim SNMP request ke agen. Paket snmp-mibs-downloader akan membantu untuk menginstal dan mengelola file Management Information Base (MIB), yang melacak network object.

Masuk ke server agent, dengan perintah

ssh your_username@agent_server_ip_address

Lakukan

sudo apt update
sudo apt -y install snmpd

Perhatikan bahwa kita tidak memerlukan paket snmp-mibs-downloader, karena agent server tidak akan mengelola file MIB.

Step 2 — Konfigurasi SNMP Manager Server

Seperti disebutkan sebelumnya, sebagian besar pekerjaan terjadi di agent server, sehingga konfigurasi kita pada server manajer akan tidak berat. Kita hanya perlu memodifikasi satu file untuk memastikan bahwa SNMP tool dapat menggunakan data MIB tambahan yang kita instal.

Pada manager server, buka /etc/snmp/snmp.conf

sudo viu /etc/snmp/snmp.conf

Pada file ini ada bebera comments dan single un-commented line. Untuk mengijinkan manager untuk import MIB file, comment out mibs :

# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loading them by commenting out the following line.
mibs :

Save dan tutup snmp.conf

Step 3 — Konfigurasi SNMP Agent Server

Sebagai sistem client-server yang sebenarnya, agent server tidak memiliki tool eksternal / tambahan yang diperlukan untuk mengkonfigurasi SNMP setup-nya. Kita dapat memodifikasi beberapa file konfigurasi untuk membuat beberapa perubahan, tetapi sebagian besar perubahan yang perlu kita lakukan adalah untuk menghubungkan ke agent server ke management server.

Dalam tutorial ini, kita akan menggunakan SNMP versi 3. Tidak seperti SNMPv1 dan v2, di SNMPv3 setiap pesan berisi parameter keamanan yang disandikan. Pada langkah ini kita akan mengonfigurasi aturan SNMPv3 otentikasi dan kontrol akses.

Untuk memulainya, pada agent server, bukan konfigurasi snmpd.conf sebagai berikut

sudo vi /etc/snmp/snmpd.conf

Kita akan melakukan beberapa perubahan kecil. Ini akan digunakan untuk mem-bootstrap konfigurasi agar bisa memanage server dari server lain.

SATU Ubah agentAddress agar bisa di akses dari komputer lain

/etc/snmp/snmpd.conf
#  Listen for connections from the local system only
#agentAddress  udp:127.0.0.1:161
#  Listen for connections on all interfaces (both IPv4 *and* IPv6)
agentAddress udp:161,udp6:[::1]:161

Setelah selesai melakukan bootstraping, sebaiknya di set hanya localhost yang bisa akses.

DUA Mendefinisikan pengguna. Pengguna yang kita buat akan disebut bootstrap dan akan digunakan sebagai template untuk membuat pengguna pertama. Paket SNMP melakukan ini melalui proses kloning properti pengguna.

Saat mendefinisikan pengguna baru, kita harus menentukan jenis otentikasi (MD5 atau SHA) serta memberikan frasa sandi yang paling tidak harus delapan karakter. Jika kita berencana menggunakan enkripsi untuk transfer, kita harus menentukan protokol privasi (DES atau AES) dan secara opsional frasa sandi protokol privasi. Jika tidak ada frasa sandi protokol privasi yang diberikan, frasa sandi otentikasi juga akan digunakan untuk protokol privasi.

Tambahkan createUser line di akhir file:

/etc/snmp/snmpd.conf

...
createUser bootstrap MD5 temp_password DES

Sekarang kita memiliki pengguna baru yang ditentukan, kita dapat mengatur tingkat akses yang akan dimiliki oleh pengguna ini. Dalam tutorial ini kita akan mengatur ini untuk pengguna bootstrap, dan juga untuk pengguna baru yang akan kita buat, yang disebut demo. Kita akan mengijinkan mereka read dan write akses dengan menggunakan petunjuk rwuser (alternatifnya adalah rouser untuk read-only access).

Kita juga akan menegakkan penggunaan enkripsi dengan menentukan priv setelah pengguna. Jika kita ingin membatasi pengguna ke bagian tertentu dari MIB, kita bisa menentukan highest-level object identifier (OID) yang bisa diakses pengguna di akhir baris.

Dalam tutorial ini, ke dua baris yang dibutuhkan adalah sebagai berikut,

/etc/snmp/snmpd.conf
...
rwuser bootstrap priv
rwuser demo priv

Setelah sudah konfigurasi snmpd.conf, save & close file.

Restart

sudo systemctl restart snmpd

SNMP daemon akan mendengarkan port 161. Konfigurasi UFW untuk mengijinkan sambungan port 161

sudo ufw allow from manager_server_ip_address to any port 161

Step 4 — Verifying Authentication to the Agent Server

In this step, you will test to make sure you can connect with your bootstrap account to the agent server. Before that, however, this tutorial will talk a bit about the general structure of sending an SNMP command.

When using the suite of tools included in the snmp package (the net-snmp software suite), there are a few patterns in the way you must call the commands. The first thing to do is authenticate with the SNMP daemon that you wish to communicate with. This usually involves supplying a few pieces of information. The common ones are as follows:

-v: This flag is used to specify the version of the SNMP protocol that you would like to use. This tutorial will be using v3.
-c: This flag is used if you are using SNMP v1 or v2-style community strings for authentication. Since you are using v3-style user-based authentication, you don’t need to do this.
-u: This parameter is used to specify the username that you wish to authenticate as. To read or modify anything using SNMP, you must authenticate with a known username.
-l: This is used to specify the security level that you are connecting with. The possible values are noAuthNoPriv for no authentication and no encryption, authNoPriv for authentication but no encryption, and authPriv for authentication and encryption. The username that you are using must be configured to operate at the security level you specify, or else the authentication will not succeed.
-a: This parameter is used to specify the authentication protocol that is used. The possible values are MD5 or SHA. This must match the information that was specified when the user was created.
-x: This parameter is used to specify the encryption protocol that is used. The possible values are DES or AES. This must match the information that was specified when the user was created. This is necessary whenever the user’s privilege specification has priv after it, making encryption mandatory.
-A: This is used to give the authentication passphrase that was specified when the user was created.
-X: This is the encryption passphrase that was specified when the user was created. If none was specified but an encryption algorithm was given, the authentication passphrase will be used. This is required when the -x parameter is given or whenever a user’s privilege specification has a priv after it, requiring encryption.

Using this information, you can construct your commands. Given how you set up your bootstrap user, the commands you will be using with that account will look like this:

snmp_command -u bootstrap -l authPriv -a MD5 -x DES -A temp_password -X temp_password remote_host snmp_sub_command_or_options

From your manager server, test to make sure your bootstrap account is available. Type the following to display the system information for the agent server:

snmpget -u bootstrap -l authPriv -a MD5 -x DES -A temp_password -X temp_password agent_server_ip_address 1.3.6.1.2.1.1.1.0

The 1.3.6.1.2.1.1.1.0 string is the OID that is responsible for displaying system information. It will return the output of uname -a on the remote system.

This will give the following output:

Output SNMPv2-MIB::sysDescr.0 = STRING: Linux agent 4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019 x86_64

Now that you have verified that you can authenticate to the server running the SNMP daemon, you can continue on to create your regular user account.

Step 5 — Setting Up the Regular User Account

Although you have specified the privileges for the demo user account in the snmpd.conf file, you haven’t actually created this user yet. In this step, you are going to use the bootstrap user as a template for your new user. You will do this using the snmpusm tool, which is used for user management.

On the manager server, you can create the user from the template using the snmpusm tool and the following general syntax:

snmpusm authentication_info agent_server_ip_address create new_user existing_user

Using what you know about the authentication flags you need to pass, and leveraging the user account you already have (bootstrap), you can make a user that fits the user privileges you have already defined (demo).

The command will look like this:

snmpusm -u bootstrap -l authPriv -a MD5 -x DES -A temp_password -X temp_password agent_server_ip_address create demo bootstrap

You will receive the following message:

Output
User successfully created.

You now have a fully functioning user called demo on your agent server. However, it is still using the same authentication information as the bootstrap account. To increase security, you can change the password to something else. This time, you will use the demo account to authenticate. Remember, passwords must be at least eight characters long:

snmpusm -u demo -l authPriv -a MD5 -x DES -A temp_password -X temp_password agent_server_ip_address passwd temp_password new_password

You will receive the following message back:

Output
SNMPv3 Key(s) successfully changed.

You can test your new credentials and password by asking the agent server how long the SNMP service has been running. You will use the snmpget command to get a single value from the agent server.

This time, take advantage of the extra MIB definitions you downloaded to ask for the value by name instead of the OID numeric ID.

snmpget -u demo -l authPriv -a MD5 -x DES -A new_password -X new_password agent_server_ip_address sysUpTime.0

You will get back a value that represents the last time that the remote SNMP daemon was restarted:

Output
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (53309) 0:08:53.09

You now have a working user account named demo. In the next step, you will simplify working with SNMP commands by configuring the client.

Step 6 — Creating a Client Configuration File

You have probably noticed by this point that the authentication details for all of your SNMP commands will be fairly static with each request. Rather than typing these in each time, you can create a client-side configuration file that will contain the credentials you are connecting with.

The client configuration file can be placed in two different locations depending on how wide-spread you wish to share it.

If you want to share your login credentials with any valid user on your management machine, you can place your configuration details into the global snmp.conf file on the manager server. You would need to open that file with sudo privileges:

sudo nano /etc/snmp/snmp.conf

If, however, you want to define the authentication credentials for your user alone, you can create a hidden .snmp directory within your user’s home directory on the manager server, and create the file there:

mkdir ~/.snmp
nano ~/.snmp/snmp.conf

Regardless of your decision on where to place your configuration, the contents will be the same.

The commands that you will be using to authenticate are in the following table. In the right-hand column, you can see the directive names used to set those configuration details within the snmp.conf file: Command Flag Description Translated snmp.conf directive

-u username 	The SNMPv3 username to authenticate as. 	defSecurityName username
-l authPriv 	The security level to authenticate with. 	defSecurityLevel authPriv
-a MD5 	The authentication protocol to use. 	defAuthType MD5
-x DES 	The privacy (encryption) protocol to use. 	defPrivType DES
-A passphrase 	The authentication passphrase for the supplied username. 	defAuthPassphrase  passphrase
-X passphrase 	The privacy passphrase from the supplied username. 	defPrivPassphrase passphrase

Using this information, you can construct an appropriate snmp.conf file. For this guide, it will look like this:

snmp.conf
defSecurityName demo
defSecurityLevel authPriv
defAuthType MD5
defPrivType DES
defAuthPassphrase new_password
defPrivPassphrase new_password

When you are finished, save and close the file.

Now, you can issue commands without supplying the authentication details. You will only need the SNMP command, the host, and the command arguments.

Instead of typing:

snmpget -u demo -l authPriv -a MD5 -x DES -A new_password -X new_password agent_server_ip_address sysUpTime.0

You can type:

snmpget agent_server_ip_address sysUpTime.0

As you can see, this significantly reduces the amount of information you need to supply in each request. Next, you will remove the bootstrap account to tighten the network security.

Step 7 — Removing the Bootstrap Account

Now that your regular account is configured correctly, you can remove the insecure bootstrap account.

On your agent server, open the /etc/snmp/snmpd.conf file again with sudo privileges.

sudo nano /etc/snmp/snmpd.conf

Find and comment out (or remove) both of the lines that you previously added that reference the bootstrap user:

/etc/snmp/snmpd.conf
...
#createUser bootstrap MD5 temp_password DES
#rwuser bootstrap priv
...

Save and close the file.

Now, restart the SNMP daemon:

sudo systemctl restart snmpd

This will fulfill the recommendation of not having createUser directives in the normal snmpd.conf file. It will also remove privileges from that temporary user.

If you want to completely remove the bootstrap user from the usmUserTable, you can do so by issuing this command from the manager server:

snmpusm agent_server_ip_address delete bootstrap

You will receive the following response:

Output
User successfully deleted.

Conclusion

At this point, you have a fully configured client-server setup that can communicate securely using the SNMP protocol. You can now add additional daemons on other hosts and configure account access across your entire infrastructure.

For further study, you can use our How To Use the Net-SNMP Tool Suite To Manage and Monitor Servers tutorial to learn about SNMP tools and how to use them to retrieve values one-by-one or by bulk and how to modify data.

Referensi

Pranala Menarik