Difference between pages "Pxe" and "Snmp"

From Linuxintro
(Difference between pages)
imported>ThorstenStaerk
 
imported>ThorstenStaerk
 
Line 1: Line 1:
'''PXE''' stands for '''P'''reboot E'''x'''ecution '''E'''nvironment. It is used to boot a computer using booting information from over the network.
+
SNMP allows you to monitor hardware. To do this, there are objects that will be monitored: computers, network switches, storages and so on. These are called agents. They communicate with a "manager" which displays their status. The agents can be queried for their status by a get/set request/response. Or they can alert about a critical status by initiating a communication, this is called a "trap".
  
= Overview =
+
= Trying to build an SNMP prototype =
The typical PXE boot looks like this:
 
# Computer ''A'' starts. Its [http://en.wikipedia.org/wiki/BIOS BIOS] is set to do a PXE boot, so booting from the [[network]].
 
# Computer ''A'' acquires an IP address from [[dhcp]] server ''B''.
 
# Computer ''A'' downloads its booting files ([[initrd]] and kernel) via [[tftp]] from ''B''.
 
# Computer ''A'' executes the kernel just as if it had from its local [[hard disk]].
 
  
= How to start =
+
SUSE Linux:
In this example we use SUSE Linux 12.1.
 
  
== DHCP ==
+
yast -i nagios apache2
To allow your computers to boot from the network, they first need an IP address. So, [[set up a dhcp-server]]. Make sure /etc/dhcpd.conf contains the following lines:
+
/etc/init.d/nagios start
allow booting;
+
  /etc/init.d/apache2 start
allow bootp;
 
authoritative; # I am the one and only here
 
Make sure your "subnet" section contains the following lines:
 
next-server ''192.168.0.5'';
 
filename "pxelinux.0";
 
Make sure you have restarted your dhcpd:
 
  /etc/init.d/dhcpd restart
 
  
== TFTP ==
+
Remember your login nagiosadmin:nagiosadmin and point your browser to http://127.0.0.1/nagios
After your computers have received their IP address, they start asking for their booting file from the TFTP-server, in this case ''192.168.0.5''. So, make sure they can get it.
 
* [[Install]] tftp and syslinux:
 
# yast -i tftp syslinux
 
* copy syslinux' pxelinux.0 to /srv/tftpboot/:
 
# rpm -ql syslinux | grep pxelinux.0
 
/usr/share/syslinux/gpxelinux.0
 
/usr/share/syslinux/pxelinux.0
 
# cp /usr/share/syslinux/pxelinux.0 /srv/tftpboot/
 
* Activate the tftp server. To do this, change /etc/xinetd.d/tftp. Replace
 
disable = yes
 
with
 
disable = no
 
Then restart xinetd which hosts tftpd:
 
/etc/init.d/xinetd restart
 
* Test it:
 
tftp ''192.168.0.5'' -c get pxelinux.0
 
Test your configuration now by booting a connected computer from PXE. You should get an error message saying that the configuration file pxelinux.cfg/default has not been found.
 
  
== pxelinux.cfg/default ==
+
/etc/init.d/snmptrapd
Create a /srv/tftpboot/pxelinux.cfg/default like this:
+
tail -f /var/log/net-snmpd.log
  default linux
+
  snmptrap -v 2c -c public localhost "" NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification netSnmpExampleHeartbeatRate i 42
timeout 0
 
prompt 1
 
display display.msg
 
 
label linux
 
  kernel vmlinuz
 
  append initrd=initrd
 
  
* Now you must supply kernel (vmlinuz) and initrd into the tftp folder:
+
  No access configuration - dropping trap.
  cp /boot/vmlinuz /srv/tftpboot
 
cp /boot/initrd /srv/initrd
 
  
== Change initial ramdisk ==
+
So it seems I have to  
If you now want to change the initrd to actually do something, you can do it like this:
 
cd /srv/tftpboot
 
mkdir tmp
 
cd tmp
 
cp ../initrd ./initrd.gz
 
gunzip initrd.gz
 
mkdir tmp2
 
cd tmp2
 
[[cpio]] -id < ../initrd
 
Do the needed changes now in this folder. Then pack the initrd again:
 
[[find]] . | cpio --create --format='newc' > ../newinitrd
 
cd ..
 
[[gzip]] newinitrd
 
Your new [[initrd]] is now called newinitrd.gz.
 
  
== Basic setup ==
+
cat /etc/snmp/snmptrapd.conf
The goal here is to be able to boot a Linux shell from PXE.
+
disableAuthorization yes
 +
traphandle default /bin/snmppl
  
For this I took the initrd and kernel from the SUSE 12.1 install DVD and modified the initrd. I replaced /init on the initrd by /bin/bash. Then I copied busybox to /bin. Then I booted from PXE. Then I mounted /proc:
+
/etc/init.d/snmptrapd restart
  mount -t proc proc /proc
+
cat /bin/snmppl
 +
#!/bin/bash
 +
date >>/tmp/dates
 +
 
 +
= 2014-05-06 =
 +
Ok, the following command
 +
snmptrap -v 2c -c public hostname "" NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification netSnmpExampleHeartbeatRate i 42
 +
works and I can see on hostname
 +
 
 +
hostname:~ # tcpdump port 162
 +
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
 +
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
 +
12:09:02.418760 IP source.domain.45398 > hostname.domain.snmptrap:  V2Trap(77)  system.sysUpTime.0=60543145 S:1.1.4.1.0=[|snmp]
 +
 
 +
But I cannot receive it with [[netcAt]]. And it does not work on localhost.
 +
 
 +
Using this command I can sniff and display the snmp trap:
 +
 
 +
tcpdump -A port 162 -l | hexdump -C
 +
 
 +
or this command:
 +
 
 +
  netcat -u -l 162 | hexdump -C
  
 
= See also =
 
= See also =
* [http://en.wikipedia.org/wiki/Preboot_Execution_Environment Wikipedia on PXE]
+
* http://nagios.sourceforge.net/docs/3_0/quickstart-opensuse.html
* http://www.digitalpeer.com/id/linuxnfs
+
* http://net-snmp.sourceforge.net/wiki/index.php/TUT:snmptrap
 +
* http://www.linuxforums.org/forum/gentoo-linux/108864-net-snmp.html
 +
* http://paulgporter.net/2013/09/16/nagios-snmp-traps/
  
 
[[Category:Networking]]
 
[[Category:Networking]]
[[Category:Boot]]
+
[[Category:Concept]]
[[Category:Guides]]
 

Revision as of 10:40, 22 January 2015

SNMP allows you to monitor hardware. To do this, there are objects that will be monitored: computers, network switches, storages and so on. These are called agents. They communicate with a "manager" which displays their status. The agents can be queried for their status by a get/set request/response. Or they can alert about a critical status by initiating a communication, this is called a "trap".

Trying to build an SNMP prototype

SUSE Linux:

yast -i nagios apache2
/etc/init.d/nagios start
/etc/init.d/apache2 start

Remember your login nagiosadmin:nagiosadmin and point your browser to http://127.0.0.1/nagios

/etc/init.d/snmptrapd
tail -f /var/log/net-snmpd.log
snmptrap -v 2c -c public localhost "" NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification netSnmpExampleHeartbeatRate i 42
No access configuration - dropping trap.

So it seems I have to

cat /etc/snmp/snmptrapd.conf
disableAuthorization yes
traphandle default /bin/snmppl
/etc/init.d/snmptrapd restart
cat /bin/snmppl
#!/bin/bash
date >>/tmp/dates

2014-05-06

Ok, the following command

snmptrap -v 2c -c public hostname "" NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification netSnmpExampleHeartbeatRate i 42

works and I can see on hostname

hostname:~ # tcpdump port 162
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
12:09:02.418760 IP source.domain.45398 > hostname.domain.snmptrap:  V2Trap(77)  system.sysUpTime.0=60543145 S:1.1.4.1.0=[|snmp]

But I cannot receive it with netcAt. And it does not work on localhost.

Using this command I can sniff and display the snmp trap:

tcpdump -A port 162 -l | hexdump -C

or this command:

netcat -u -l 162 | hexdump -C

See also