Posts Tagged ‘Tips and Tricks’

How to disable IPv6 in Debian

Thursday, April 23rd, 2009

I’ve recently installed a new LDAP server on Debian Lenny and I wanted to disable IPv6 as it is unnecessary for me in this moment. With netstat I checked the listening processes:

netstat -tunlp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0* LISTEN 2226/slapd
tcp 0 0* LISTEN 2215/sshd
tcp6 0 0 :::389 :::* LISTEN 2226/slapd
tcp6 0 0 :::22 :::* LISTEN 2215/sshd

and lsmod showed something like this:

Module Size Used by
ipv6 235364 12

So, to disable IPv6 I changed /etc/modprobe.d/aliases:
# alias net-pf-10 ipv6
# Disable ipv6
alias net-pf-10 off
alias ipv6 off

I also disabled these lines in /etc/hosts to avoid confusions:

## The following lines are desirable for IPv6 capable hosts
#::1 localhost ip6-localhost ip6-loopback
#fe00::0 ip6-localnet
#ff00::0 ip6-mcastprefix
#ff02::1 ip6-allnodes
#ff02::2 ip6-allrouters
#ff02::3 ip6-allhosts

Finally I restarted the server.

shutdown -r now

Now the situation is like this:

netstat -tunlp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0* LISTEN 2233/slapd
tcp 0 0* LISTEN 2216/sshd

lsmod|grep ipv6


No IPv6.

OpenSSH: simplifying logins

Thursday, December 6th, 2007

OpenSSH provides a per-user configuration file usually located in ~/.ssh/config. This file can help ease your life as Sysadmin. Let’s say that you frequently connect to a server in this way:


With OpenSSH there is an easy way to do the job. Edit or create a config file:

vi ~/.ssh/config

and then add the following:

Host servername
     User admin

Where Host is the alias for the remote server you want to connect to, HostName is the full name of the remote server and User is the login name.


Perl on the command line

Sunday, May 27th, 2007

Perl, you know perl, is not just a jewel for scripting, it ‘s also a potent onliner.

The magic trick is the diamond:

perl -e ‘while (){print}’ file1

says perl “keep on as long as you read something in the standard in”, in the case of the example above, “print the line” … and each line goes in the memory but not the whole file: you have a powerful stream editor.

The ” -e” switch says to perl that what follows in the command line between the single quotations is a script and not a script file name.

But you can have it quicklier :

perl -ane ‘print’ file1

The switches “-ane” do the “while stuff” for you. It says “do a while () loop” (-n) “and split each record in the @F array” (-a), I haven’t used the array yet.
Perl has a difficulty : you can implicit everything. Some guys abuse of it in scripting, like spirits, but it’s good for an onliner.

This line will print file1. Great (in fact implicit in “print $_” ; $_ is the variable where perl puts what you do not explicit). Printing is great but let do some awkish things :

perl -ane ‘/$m[aiy]/ && print $_’

That will print the lines that contain $ma, $mi or $my, (have a look at the article from karkoma about sed), patterns in perl are like sed’s ones but larger. Take a look at the tutorial of perl for pattern or type “perldoc perlreftut” if you have installed perldoc.

Well, just let do some sedish thinks :

perl -ane ‘s/

]*)>//; s/
/;print’ file1.html

replaces the paragraph in html( by newline () but keeps the options of the paragraph ($1, first match, here the parenthesis are not optional) in an html comment.

perl -F”:” -ane ‘/pascal/ && print $F[2]‘ /etc/passwd

will print the UID of user pascal (third field), the field separator is “:” (-F$-1òý:òý)

perl -ane ‘/$m[aiy][^ s]*/ && print “line : $. variable : $&n”‘

will print the number of line ($.) where the variables that begin with “$ma”, “$mi” o “$my” and the variables that have matched the description ($&)

bad news, you received this bad MS file with carriage return (r) and newline and you want only the newline :

perl -pi.old -ane ‘s/rn$/n/;print;’ file1

and I obtain directly a file1 without carriage return and I have a backup of the original in file1.old (-pi.old)
you can have a look to a quick look at some useful perl onliners.

Changing MAC address

Sunday, October 22nd, 2006

The acronym MAC stands for Media Access Control and it is a unique number that identifies your network interface. In an interconnected computer network a so called ARP table relates your IP address to your network interface card’s MAC.

Despite the fact that physical MAC addresses are permanent, it is possible to change this address. In Linux proceed as follows:

ifconfig eth0 down
ifconfig eth0 hw ether 01:01:02:02:03:03

Automatisation of telnet, ftp or ssh

Monday, June 12th, 2006

For ftp you have a quick and dirty trick :

$ ftp -n yourhost <<-here
> quote USER youruser
> quote PASS yourpassword
> ls
> quit
> here

(you can do a put, get, whatever you want instead of “ls”)

For telnet similar idea:

$ (echo -e “open yourhostr”; sleep 2;echo -e “youruserr”; sleep 1; echo -e “yourpassword”; sleep 1; echo -e “unamer”; sleep 1; echo -e “exit”) | telnet

That sound pretty good but … it does not work on solaris (ok on Linux), and no way for ssh :(

So if this shoddy doesn’t meet your expectations…

Expect is what you are looking for. Available for GNU-linux, solaris… MSwindows… at
For debian do it cool:

apt-get install expect

I do it with 2 scripts. I’m sure that you can do better, but that’s work ;-)

– script to call the expect and to make things good looking:
os=$( ./expectaTion.tcl $host $psswd $cmd| awk “/$cmd/ “‘{getline; print}’|tr -d ‘

Linux: skip or force fsck on reboot

Tuesday, April 11th, 2006

shutdown is the typical way to bring your system down in a Unix environment. It takes care of notifying logged in users that the system is going down, takes care of sending SIGTERM to processes and more.

One interesting feature of shutdown is the ability to force or skip the check and repair of the filesystem after a reboot. This is done by two flags that could be passed to the command. According to the man pages:

The -f flag means 'reboot fast'. This only creates an advisory file /fastboot which can be tested by the system when it comes up again. The boot rc file can test if this file is present, and decide not to run fsck(1) since the system has been shut down in the proper way. After that, the boot process should remove /fastboot.

The -F flag means 'force fsck'. This only creates an advisory file /forcefsck which can be tested by the system when it comes up again. The boot rc file can test if this file is present, and decide to run fsck(1) with a special 'force' flag so that even properly unmounted file systems get checked. After that, the boot process should remove /forcefsck.