Monday, December 6, 2010

Howto - Find broken symbolic links

2 cool ways to find broken symbolic links on your system:
for i in `find /`; do if (test -h $i); then file $i|grep broken; fi; done

./bar_link: broken symbolic link to `/etc/foo'

Any Shell:
find / -type l ! -exec test -r {} \; -print


When measuring the results with "time" command - the 2nd command wins, so if performance is critical in your case, use the 2nd one :)

Friday, October 15, 2010

Generate IPV6 Addresses with BASH

A fast way to generate some IPV6 addresses via BASH, with tool called "wcalc" that will help generating hexadecimal values.
First make sure "Wcalc" package is installed on your system:

root@paul-laptop:~# rpm -qa Wcalc

Next, using bash "for" loop let's generate some addresses (values selected randomly):

root@paul-laptop:~# for i in $(seq 600 610) ;do echo -n '2001:fade:28e1:3712::1'; echo ${i} |wcalc -h|awk -F x '{print $2}';done



Tuesday, October 12, 2010

Reinstall MBR with GRUB stage1

Creating a dual-boot Linux system such as the Red Hat/Debian is a neat way to experiment with both distributions another advantage is  having a fallback point.
A small downside is that the GRUB stage1 information in the MBR can be overwritten by the second install. In our example, Red Hat is installed on the first disk, and Debian is installed on the second. After Debian is installed, however, the Debian GRUB menu is displayed instead of the Red Hat menu that we are used to and that has been customized for our installation.

Let's see how we can solve this issue -

step 1 
Boot to grub CLI

step 2
The root (hd0,0) command sets the (hd0,0) partition as the location of the boot directory. This command tells GRUB in which partition the stage2 and grub.conf or menu.lst files are located.

step 3
The find /boot/grub/stage1 command returned the first stage1 entry it found.
Both disks should have this file. In this instance, GRUB shows the stage1 file from the second disk.Because we want GRUB to format the MBR on the first disk, /dev/hd0 is used.

step 4
The setup (hd0) command writes the MBR of the selected disk or partition.

That's it! The whole process should look like this :

Tuesday, September 14, 2010

Change ILO settings via CLI from Linux

ILO - aka "Integrated Lights Out" is an advanced console technology that HP has implemented in most of their servers, it includes dozens of cool features and allows total remote control on the server in all kinds of aspects. ILO includes lot's of advanced configurations such as IP configuration, DNS, SNMP, LDAP integration, Users, Permissions and many more.

The "traditional" way to change these settings is via server downtime and booting it to ILO BIOS (usually by pressing F8 at boot time) and changing it there.

But what if we have hundreds of servers that require immediate change, going the first way would be a huge waste of time, therefore HP introduced a cool scripting tool (for both Linux & Windows) called  - "hponcfg". In this short tutorial we will understand how to use it - read on:

To use "hpconfg" we first have to make sure a service called "hprsm" is installed properly & running and that the needed modules are loaded into kernel:

linux01 #rpm -q hprsm hponcfg

linux01 #/etc/init.d/hprsm start

The service is running and we are ready to configure our ILO settings, to see the current settings we can generate an XML template with our current settings, to achieve this execute:

linux01 #hponcfg -w /tmp/ilo_cfg_`uname -n`.xml
Firmware Revision = 1.81 Device type = iLO 2 Driver name = cpqci
RILOE II/iLO configuration successfully written to file "/tmp/ilo_config_linux01.xml"

Now, we can see our current ILO configuration represented in the XML template we saved to /tmp, let's see what it contains:

linux01 #cat /tmp/ilo_config_linux01.xml

Ok, now you can edit whatever parameter you like and upload the updated XML template to ILO via "hpocnfg tool".

To upload the XML template, execute:
linux01 #hponcfg -f /tmp/ilo_config_`uname -n`.xml

Please note that  restart of ILO is needed for changes to take effect.

Sunday, August 29, 2010

Check Hyper Threading - Linux

When you need to know whether hyper-threading is enabled without rebooting your system (and checking BIOS/UEFI), you can simply look at the output of /proc/cpuinfo and compare the siblings with the cpu cores fields.
Even though /proc/cpuinfo shows you all the logical CPUs (processor field) in the system, the siblings field holds the number of logical CPUs for the physical CPU this entry belongs to (including both the cores and the hyper-threaded LCPUs).

For example, if you see:
processor : 7
physical id : 9
siblings : 4
cpu cores : 2

That means that LCPU #7 (the eight logical CPU in your system) is one of the 4 logical CPUs on the physical CPU that has 2 cores. So - hyper-threading is enabled.

Friday, July 30, 2010

Alias with arguments (BASH,CSH)

A neat way to make your life abit easier in Linux/Unix is using aliases, but how do you use an alias with an argument?
Let's say you want make a special "change directory" (we will call it cdd) command that will also display your current position in the file system tree.

Bash uses $1,$2,$3..etc for passed arguments, so we will add a little function inside our .bashrc file that will accomplish this mission:

cdd () { cd ${1} ; echo $PWD ; }

In C shell thing are little bit different, this will achieve the same effect when put into .cshrc:

alias cdd 'cd \!*;echo $cwd;'

Wednesday, July 14, 2010

Installing & Configuring Bind 9 (Ubuntu/Debian)

Numerous articles have been written about bind9, most of them are long, clumpy and not really explain how things work in detail. In this fairly short article I will try to give my point of view and make thing a bit more clear especially for new admins, so lets start!

First install bind9:

#apt-get install bind9

Next, open /etc/bind/named.conf.local, here you will need to add your zone name + the appropriate zone db file.
You will also need to add reverse look zone + db file (for reverse lookups), this is how your file will generally look like. 

* Note:I've used subnet in my case:

#vi /etc/bind/named.conf.local

zone "linux.lan" {
type master;
file "/etc/bind/zones/linux.lan.db";

zone "" {
type master;
file "/etc/bind/zones/";

Next, add your ISP's DNS server to /etc/bind/named.options as a forwarder, This means is when your DNS server will not know the answer it will query the forwarder and provide a non-authoritative answer.

Create the directory that will contain the zones db:

# mkdir /etc/bind/zones

Create the db file:

#vi /etc/bind/zones/linux.lan.db 

linux.lan. IN SOA dns1.linux.lan. admin.linux.lan. (

38400 )

linux.lan. IN NS dns1.linux.lan.
dns1 IN A

It's time to create a reverse zone db-file, pay attention that the servers PTR record has 7, that stands for

#vi /etc/bind/zones/

@ IN SOA linux.lan. admin.linux.lan. (
86400 );

IN NS dns1.linux.lan.
7 IN PTR linux.lan.

Next, restart bind to changes to take effect:

# /etc/init.d/bind9 restart

To make searches more convinient, you can (and should) add your domain suffix to /etc/resolv.conf

#echo "search linux.lan" >> /etc/resolv.conf

Test your DNS via host,nslookup or dig commands:

#host dns1
dns1.linux.lan has address

Works like magic!

Thursday, June 17, 2010

Change MTU size in Linux

Maximum Transmission Unit(MTU), the largest physical packet size, measured in bytes, that a network can transmit. Any messages larger than the MTU are divided into smaller packets before being sent .
By optimizing the MTU setting you can gain substantial network performance.
In IPv4 the values range between 576 and 1500 bytes being the max size.

The general syntax is: ifconfig "interface" mtu "size"

For example:ifconfig eth0 mtu 1420

Will change MTU to 1420 bytes.

For permanent change, you can add the MTU parameter into your interface configuration file,
For example in Debian the configuration will look like this:

iface eth0 inet static
mtu 1420

Tuesday, March 30, 2010

Cisco router memory types.

When it often seems transparent to the user Cisco routers rely on 4 different
types of
memory for it's operations. This is an important concept in the Cisco world and as a Network administrator you need to be familiar with them
The types memory types are: Flash, RAM, ROM, and NVRAM.

Flash Memory: Flash memory is used to store and run the Cisco IOS software - the router's operating system. When a router is powered down, the contents of Flash memory are not lost. However, its contents can be upgraded by "flashing" the chip. While a router is running, the contents of Flash are set to a read-only mode. Flash memory for a Cisco 2500 series router ranges in size from a minimum of 4MB up to a maximum of 16MB. You might consider adding additional Flash memory to meet the space requirements of the IOS version that you have chosen to run. For a Cisco 2501, the base IP version of IOS 12.0 requires a minimum of 8MB of Flash memory. So, if you had a Cisco 2501 that shipped with only 4MB of Flash, you would require at least one additional 4MB SIMM. For IOS versions with more advanced feature sets, it is not uncommon to require at least 16MB of Flash.

RAM: Random Access Memory (RAM) represents the non-permanent or volatile working area of memory on a Cisco router. When the router is powered down, the contents of RAM are lost. By default, RAM is broken up into two main areas - Main Processor Memory, and Shared I/O Memory. Main Processor Memory is where the routing table, ARP tables, and running configuration are stored. Shared I/O Memory is used as a buffer location for temporarily storing packets prior to processing. Most Cisco 2500 routers will have 2MB of RAM soldered to the system board (this amount, however, depends on the revision number of the router), along with one SIMM slot to add additional RAM. The maximum amount of RAM that can be added to a Cisco 2500 is 16MB. If 16MB is added, that provides a maximum of 18MB of available RAM. In cases where a RAM SIMM is installed, its capacity will be used as Main Processor Memory, while the onboard RAM (2MB) will be used as Shared I/O memory. If no SIMM chip is present, that 2MB of on-board RAM will be split between both areas, providing each with 1MB of working space. This should be avoided for performance reasons.

ROM : In older Cisco router models, Read-Only Memory (ROM) chips were used to store the IOS software. In newer models, this is no longer the case. As mentioned previously, the IOS image is now stored in Flash memory (it can also be stored on a TFTP server, as I'll discuss in the next chapter). ROM is now used as the memory area from which a Cisco router begins the boot process, and is made up of a number of elements. These elements are implemented via microcode, a set of programming instructions that are contained in ROM.

NVRAM: Non-Volatile Random Access Memory (NVRAM) is used as the storage
location for the router's startup configuration file. After the router loads its IOS image,
the settings found in the startup configuration are applied.
When changes are made to a router's running configuration,
they should always be saved to the startup configuration (stored in NVRAM)
or they will be lost when the router shuts down.
Remember that the running configuration is stored in RAM,
which is erased when the router is powered down.
On a Cisco 2500 series router, NVRAM is a relatively tiny 32KB in size.

Knowing what's going on where is an important part of not only understanding how a
Cisco router operates, but will also help to determine the source of problems or issues,should the need arise.

Friday, February 19, 2010

Generate hosts file with Perl

A sweet way to add couple of servers to your hosts file/NIS map using a tiny perl script:

#!/usr/bin/perl -w

use strict;
use warnings;
print `clear`;
my $j=10;

open (HOSTS ,">>/etc/hosts.txt") or die $!;
for (my $num=0;$num <= 10; $num++) {
printf(HOSTS "server$j \t server$ \t 192.168.0.$num\n");
close (HOSTS) or die $! ;


The output will be:



Monday, January 11, 2010

Finding Specific MAC - (Cisco IOS)

Finding a specific MAC in Cisco IOS can be accomplished via:

show mac-address-table

This gives a complete table of Port vs. Mac Addr.

If you want to find a specific mac address, lets say 00:11:22:33:44:5e use:

show mac-address-table | include 445e

The output is similar to Unix "grep" command.

For further debugging you can use show interface status and/or show cdp neighbors to see where it connects to.

Howto change NIC order in Linux (SUSE 10)

I recently had an issue with a mother board that was replaced on some server, after renaming the configuration file to the correct MAC address (ifcfg-eth-id-00:1a:64:7a:d0:be), the new NIC was recognized as eth4, (and not eth0 as previously),after digging abit in the depths of the OS I have found a solution:


Through this file you can configure the NIC order by MAC address.
For example:

SUBSYSTEM=="net", ACTION=="add", SYSFS{address}=="00:1a:64:7a:d0:be", IMPORT="/lib/udev/rename_netiface %k eth0"

To change take place you will probably need to reboot the machine so udev will re-read it's configurations(restarting networking service is not enough).