Archive for the ‘Notes’ Category

URL redirection at freeshell.de

Monday, November 22nd, 2010

This blog is hosted by freeshell.de – Nic Nac Project server. Great! :-)

Since the same page of this server can be reached by several URL, I decided to add a little trick for redirecting my blog visitor to the same address. This may be useful to help web spiders in indexing my pages.

For this reason if  You try to reach

http://www.freeshell.de/~jose

http://nic-nac-project.de/~jose

or any other equivalent URL, Your browser will be redirected to

http://www.nic-nac-project.de/~jose/

Since my blog is a WordPress one, a .htaccess file has been made by my software configuration. I set up the redirection by adding two lines to the .htaccess file created by WordPress in my public_html directory:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~jose/
RewriteCond %{HTTP_HOST}    !^www\.nic-nac-project\.de [NC]
RewriteRule ^(.*)$    http://www.nic-nac-project.de/~jose/$1 [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~jose/index.php [L]
</IfModule>

backup or dump a micro$oft DHCP configuration

Tuesday, August 31st, 2010

On a Microsoft 2003 server It’s possible to backup the DHCP configuration with the command

C:\Documents and Settings\server\Desktop>netsh dhcp server export dumpfilename.netsh all

while If You need a plain text dump (e.g. to plan a migration to a free-software DHCP server)

C:\Documents and Settings\server\Desktop> netsh dhcp server dump all >dumpfilename.txt

Human readers usually like the last way…
dhcp_dump

playing with iSCSI

Monday, May 31st, 2010

Internet SCSI, shortly iSCSI, is an IP based protocol used for networking storage. With iSCSI it’s possible to send commands to remote SCSI storage on remote hosts, for this reason it is quite common in the SAN world.
Since IP networks are very common, iSCSI can be used to transmit data over LAN, WAN, or the Internet and can enable location-independent data storage and retrieval.

Once installed the package iscsitarget, You can specify the location of a shared area

vlinux19:/root# grep -v \# /etc/ietd.conf

Target iqn.2010-03.my.domain:my.storage.id
Lun 0 Path=/dev/sdc,Type=fileio
Alias Test

and, once started the daemon, any Windows client can see the storage with the Microsoft iSCSI initiator.iscsi client

batch ftp script

Sunday, February 7th, 2010

If for some reason You need a quick and dirty script to retrieve some file from a ftp server, just open your text editor and write some things into your file. Then a simple command line command will download the file You have just write the path.

MS-DOS way:

C:\TMP> TYPE COMMANDFILE.TXT

username

password

dir

get wp-config.php

quit

C:\TMP> FTP -S:COMMANDFILE.TXT ftp.server.name

UNIX/LINUX way:

$ cat test

user username password

dir

get wp-config.php

quit

$ ftp -n ftp.server.name < test

wrapped nagios plugin to enable performance data

Tuesday, December 29th, 2009

In the nagios world, PNP4Nagios is an useful tool for collecting measures and drawing a graphic, e.g. to show the use of a monitored resource.
A plugin for PNP4Nagios is useful if it’s able to write some performance data.

So, the plugin output should be something like

PING OK – Packet loss = 0%, RTA = 0.26 ms|’ping reply time’=26ms

instead of

PING OK – Packet loss = 0%, RTA = 0.26 ms

If Your plugin does’n write performance data, You can put a simple shell scritp between nagios and the plugin with a small modification of Your nagios config.

  1. /etc/nagios/commands.cfg

    define command{
    command_name wrapped_ping
    command_line /usr/lib/nagios/plugins/wrapped_ping $HOSTADDRESS$ $ARG1$ $ARG2$
    }

  2. /etc/nagios/services.cfg

    define service{
    use generic-service ; Name of service template to use

    host_name intranet
    service_description PING
    is_volatile 0
    check_period 24×7
    max_check_attempts 3
    normal_check_interval 5
    retry_check_interval 1
    contact_groups admins
    notification_interval 120
    notification_period 24×7
    notification_options w,u,c,r
    check_command wrapped_ping!100.0,20%!500.0,60%
    }

  3. /etc/nagios/serviceextinfo.cfg

    define serviceextinfo {
    host_name intranet
    service_description PING
    action_url /nagios/share/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
    }

Here You can download my version of the wrapped_ping shell script I wrote.

nagios plugin using expect and shell scripting

Tuesday, October 13th, 2009

In some cases, if You need to monitor some remote host resource without SNMP or any other simplest way, maybe You need to write a shell nagios plugin calling an expect script. A quite strange way, I admit.

Well, You can write something like that:

MYRESULT=$(/usr/bin/expect – << EOF
set timeout -1

spawn ssh $MYUSERNAME@$MYHOSTNAME
expect {
ssword: {
send “$MYPASSWORD\r”
}
}
expect {
bash-prompt {
send “$MYCOMMAND\r”
}
}
expect {
bash-prompt {
send “exit\r”
}
}
EOF)

ssh tunnel to get into a private network

Sunday, September 13th, 2009

If Your Linux box is inside a private network and You need some friend of yours get in, ssh may help You: from the linux box try

ssh -R afreeport:localhost:22 user@remote.host.name

E.g. the command

ssh -R 2048:localhost:22 jose@nic-nac-project.de

opens a shell on the nic-nac-project.de host redirecting all connections to port 22 (ssh) to the 2048 port.
It means while your ssh session is opened, all the users logged into nic-nac-project.de host can get inside your Linux box opening a ssh session to 2048 port of localhost.

ssh -p 2048 localhost

Obviously ssh server daemon have to be running on the linux box!

How to make a Debian Lenny Box leave a M$ Active Directory Domain

Thursday, July 9th, 2009

In order to remove a linux box from an Active Directory domain, just do a

# net ads leave  -U adminaccount -W DOMAIN

Joining a Debian Lenny Box to a M$ Active Directory Domain

Thursday, May 7th, 2009

Install the software You need:

# apt-get install samba-common heimdal-clients winbind ntpdate ntp samba

set the right timezone and the righ system time

# /etc/init.d/ntp stop
# dpkg-reconfigure tzdata
# ntpdate your.domain.controller

then insert Your domain controller into the time servers list:

# vi /etc/ntp.conf

add in the right place the line

# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example
server your.domain.controller
# /etc/init.d/ntp start

Edit Your file /etc/krb5.conf

# cat /etc/krb5.conf
[libdefaults]
default_realm = DOMAIN.NAME
clockskew = 300
[realms]
DOMAIN.NAME = {
kdc = your.domain.controller IP Address
admin_server = your.domain.controller IP Address
}

Edit Your file /etc/samba/smb.conf

# cat /etc/samba/smb.conf
[global]
realm = DOMAIN.NAME
workgroup = domain
security = ADS
idmap uid = 10000-20000
idmap gid = 10000-20000
template shell = /bin/bash
template homedir = /home/%D/%U
winbind use default domain = yes

[homes]
valid users = %U

check your modification with

# testparm

and then

# mkdir /home/DOMAIN

Then edit the /etc/nsswitch.conf file:

passwd:        files winbind
group:          files winbind
#passwd:         compat
#group:          compat

Now issue the command:

# net ads join -U DomainAdminUsername -W DOMAIN.NAME

Ignoring the error notice saying something like “Unable to perform DNS Update”.

Then restart some services:

# /etc/init.d/samba restart
# /etc/init.d/winbind restart

And verify You have joined the Domain, e.g. asking for some data to be displayed:

# wbinfo -u |xargs getent passwd

… and remember to modify theese files

# cat /etc/pam.d/common-account:
account    sufficient    pam_winbind.so
account    required    pam_unix.so

# cat /etc/pam.d/common-auth:
auth    sufficient    pam_winbind.so
auth    required    pam_unix.so use_first_pass

# cat /etc/pam.d/common-session:
session    required    pam_mkhomedir.so skel=/etc/skel/ umask=0022
session    sufficient    pam_winbind.so
session required    pam_unix.so

Static IP address for a VirtualBox Debian Lenny

Wednesday, May 6th, 2009

In order to give a ststic adress instead of the DHCP assigned one, You can chose bridge network in the mail VirtualBox Control panel for You host (in settings -> Network).

If during the boot You see the error

SIOCSIFADDR: no such device
eth0 ERROR …. etc….

maybe You have a wrong MAC address in your file /etc/udev/rules.d/70-persistent-net.rules matching the eth0 interface. So verify

  • the MAC address assigned by VirtualBox from the VirtualBox console,
  • the MAC showed by /sbin/ifconfig and
  • the /etc/udev/rules.d/70-persistent-net.rules file one assigned to eth0.

Obviously the MAC address for this interface have to be the same!