Wednesday, December 11, 2013

Prevent SSH connection from freezing

Recently I have experinced my ssh connection to remote server is hung after idle time. this is very annoying because ssh connection was established over vpn and take time to reconnect the session again. If your ssh connection hung/freeze time to time following solution may be helpful.


1) Open the ssh_config file.


location may differ,in centos
vim /etc/ssh/ssh_config

2) Add following lines


Host *
    ServerAliveInterval 300
    ServerAliveCountMax 2



Remember, this configuration is done at client side. client send keep alive message to server every 180 seconds and server send ack (acknowledgement) message.If 2 consecutive ack messages are lost from server side. connection will be dropped as server is not available.

Sunday, November 17, 2013

Installing vpnc - Linux VPN Client for Cisco VPN

This tutorial, I will show you how to configure vpnc on Linux and  connect  Cisco devices through vpn using pcf file. The vpnc is an alternative Linux software for Cisco vpn client.
all the things are done on centos 6.3 but steps should be same for any Linux system.


1) Installing EPEL repo

Since centos repo doesn't contain the vpnc, we need to configure additional repo call EPEL.
It is straightforward installation and  document can be found form here.

http://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F

Please find "How can I install the packages from the EPEL software repository? " from content and install it. you may need to enable EPEL repo sometime.

2) Installing vpnc

once you enabled the rpmforge repo, type following command to install vpnc  
[root@localhost ~]#yum install vpnc

3)Chang folder permission

I installed the vpnc as root.if you wish to run vpnc as normal user other than root .change file permission of vpnc installaion directory
/etc/vpnc/vpnc-script

4)Download pcf2vpnc

[root@localhost ~]#wget http://svn.unix-ag.uni-kl.de/vpnc/trunk/pcf2vpnc

5)Convert pcf file

[root@localhost ~]#perl pcf2vpnc demopcf.pcf demovpnc.conf
change ownership of *.conf file if you need

6)copy *.conf to /etc/vpnc/ 

[root@localhost ~]#cp demovpnc.conf /etc/vpnc/

7)Start vpnc

[root@localhost ~]#vpnc demovpnc
Enter password for user@A.B.C.D:
(A.B.C.D is public ip address where you need to connect, user is username , you need to enter password )

8)disconnect vpnc

[root@localhost ~]#vpnc-disconnect

Sunday, October 27, 2013

nagios snmptt configuration

Hi folks after long time !. Today I'm going to demonstrate how to configure SNMP trap inside Nagios using SNMPTT. This simulation is done at Virtualbox 4.1.26 using two guest OS ( one guest act as server and running Nagios and snmptt, other is to generate SNMP trap and it is the client)

both guest are running Centos 6.3 32bit.

Server info :- ip 192.168.56.103
Client info :- 1p 192.168.56.104

I hope you have installed and configured the Nagios, If not you can follow installation guide
http://nagios.sourceforge.net/docs/nagioscore/4/en/quickstart-fedora.html

-----

So let's install snmptt. :)
download and extract latest version of SNMPTT. you can find official installation document from here
http://www.snmptt.org/docs/snmptt.shtml#Installation-Overview

For both server and client require net-snmp-lib , net-snmp-util so install them using using yum
yum install net-snmp-lib
yum install net-snmp-util


AT Server


1)Install prerequirement such as net-snmp, perl ,perl modules


[root@nagios ~]# yum install net-snmp
[root@nagios ~]# yum install perl

install perl cpan
[root@nagios ~]# yum install perl-CPAN

launch the CPAN using following command
[root@nagios ~]# perl -MCPAN -e shell

install following perlmodules 
(Getopt::Long,  Text::ParseWords ,SNMP, Config::IniFiles, Time::HiRes , Sys::Hostname , File::Basename, Text::Balanced )
for an instance
cpan[1]> install Text::ParseWords


This demonstration is done with Standard handler – with standlone mode which is straightforward (remember there is daemon mode)


2) Copy snmptt to /usr/sbin/ and ensure it is executable (chmod +x snmptt)

[root@nagios snmptt_1.3]# cp s[root@nagios snmptt_1.3]# chmod +x /usr/sbin/snmptt nmptt /usr/sbin/

3) Copy snmptthandler to /usr/sbin/ and ensure it is executable (chmod +x snmptthandler)

[root@nagios snmptt_1.3]# cp snmptthandler /usr/sbin/
[root@nagios snmptt_1.3]# chmod +x /usr/sbin/snmptthandler

4) Copy snmptt.ini to /etc/snmp/ or /etc/ and edit the options inside the file.

[root@nagios snmptt_1.3]# cp snmptt.ini /etc/snmp/

5) Create the log folder /var/log/snmptt/.

[root@nagios snmptt_1.3]# mkdir -p /var/log/snmptt/


6) For standlone mode:  Modify the Net-SNMP snmptrapd.conf file by adding the following line:

[root@nagios ~]# vim /etc/snmp/snmptrapd.conf
traphandle default /usr/sbin/snmptt
disableAuthorization yes

7) Edit the /etc/logrotate.d/snmptt and update the paths and rotate frequency as needed.

[root@nagios snmptt_1.3]# cp snmptt.logrotate /etc/logrotate.d/snmptt


8) Start snmptrapd using the command line:  snmptrapd -On.

[root@nagios snmptt_1.3]# snmptrapd –On

--

9) Convert MIB file


Copy eventhandler
[root@nagios ~]# cp /home/shehan/Downloads/nagios-4.0.1/contrib/eventhandlers/* /usr/local/nagios/libexec/eventhandlers

copy snmpttconvertmib into /usr/sbin/ folder
[root@nagios ~]# cp /home/shehan/Downloads/snmptt_1.3/snmpttconvertmib /usr/sbin/

then issue below command
[root@nagios ~]#snmpttconvertmib --in=/usr/share/snmp/mibs/SNMPv2-MIB.txt --out=/etc/snmp/snmptt.conf.SNMPv2-MIB \
--exec='/usr/local/nagios/libexec/eventhandlers/submit_check_result $r TRAP 1'


10) Edit /etc/snmp/snmptt.ini, and change below settings

[General]
mode = standalone
net_snmp_perl_enable = 1
unknown_trap_log_enable = 1

At end of file you can find line similar to this Add /etc/snmp/snmptt.conf.NET-SNMP-EXAMPLES-MIB like below

snmptt_conf_files = <<END
/etc/snmp/snmptt.conf
/etc/snmp/snmptt.conf.NET-SNMP-EXAMPLES-MIB
END


11) create host cfg file

[root@nagios ~]# vim /usr/local/nagios/etc/objects/remote-host.cfg
And add below (you may need to change ip host_name)


define host {
        use     linux-server
        host_name       remote-host
        alias           remote-host-alias
        address         192.168.56.104
        }

define service{
        use                        generic-service
        name                       trap-service
        register                   0
        service_description        TRAP
        is_volatile                1
        check_command              check-host-alive
        max_check_attempts         1
        normal_check_interval      1
        retry_check_interval       1
        notification_interval      31536000
        active_checks_enabled      0
        passive_checks_enabled     1
    check_period           24x7
        }

define service{
        use                        trap-service
        host_name                  remote-host
        }



12) Add blow command to nagios.cfg

[root@nagios ~]# vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/remote-host.cfg


13)allow snmp trap from firewall

[root@nagios ~]# iptables -I INPUT 1 -p udp --dport snmptrap -j ACCEPT

confirm the changes and then save using below command
[root@nagios ~]# iptabless –list
[root@nagios ~]# service iptables save

14) start service at server

[root@nagios ~]# service snmptrapd start
[root@nagios ~]# service snmpd start

configure to start at boot
[root@nagios ~]#chkconfig snmptrapd on
[root@nagios ~]#chkconfig snmpd on


AT Client,

generate SNMP trap message, this is SNMP v2 message

[root@localhost ~]# snmptrap -v 2c -c public 192.168.56.101 "" SNMPv2-MIB::coldStart coldStart  s "start"


AT Server


check below log messages
/var/log/messages
/var/log/snmptt/snmptt.log
And check nagios web interface.If everything works fine you can have similar output like below


nagios and  snmptt








----


Reference URLS

http://xavier.dusart.free.fr/nagios/en/snmptraps.html
http://hummy.wikidot.com/how-to-send-and-receive-snmp-traps
http://socketubs.org/docs/sysadmin/snmp_traps_nagios.html


Related Posts