Monday, September 25, 2006

DNS Short Hand For Netmasks

The number in the "/xx" shorthand stands for the number of bits (technically, bits set to one) in the subnet mask. The convention is always to start at the left end of the 32-bit subnet mask. The table below shows the correspondence between the "/xx" notation and the actual numeric representation.

Subnet Mask # of Addresses
/1 128.0.0.0 2.1 billion
/2 192.0.0.0 1 billion
/3 224.0.0.0 536 million
/4 240.0.0.0 268 million
/5 248.0.0.0 134 million
/6 252.0.0.0 67 million
/7 254.0.0.0 34 million
/8 255.0.0.0 17 million (Class A)
/9 255.128.0.0 8.4 million
/10 255.192.0.0 4.2 million
/11 255.224.0.0 2.1 million
/12 255.240.0.0 1 million
/13 255.248.0.0 524 thousand
/14 255.252.0.0 262 thousand
/15 255.254.0.0 131 thousand
/16 255.255.0.0 65,534 (Class B)
/17 255.255.128.0 32,766
/18 255.255.192.0 16,382
/19 255.255.224.0 8,190
/20 255.255.240.0 4,094
/21 255.255.248.0 2,046
/22 255.255.252.0 1,022
/23 255.255.254.0 510
/24 255.255.255.0 254 (Class C)
/25 255.255.255.128 126
/26 255.255.255.192 62
/27 255.255.255.224 30 (254-224)
/28 255.255.255.240 14 (254-240)
/29 255.255.255.248 6 (254-248 or 2*2*2-2)
/30 255.255.255.252 2 (254-252 or 2*2-2)
/31 255.255.255.254 RFC 3021
/32 255.255.255.255 Loopback address

Friday, September 01, 2006

Reboot a Linux server without remote power access

Once a Linux box has a hung daemon in /proc, one will not be able to reboot the box in the normal manner. The 'ps' commands will hang - and an 'init 6' will not work because the running processes on the server cannot be killed. Without physical access and remote power control, a SA may use the "Magic System Request" method to force kernel operations like sync, remount of all filesystems read-only, and reboot. Solaris administrators may be familiar sys the 'uadmin' command which also does the same thing.

The short form:

If you're on the console, you must first enable the subsystem with a command:

echo 1 > /proc/sys/kernel/sysrq
Alternatively, you may use the equivalent sysctl command as follows:

sysctl -w kernel.sysrq="1"
kernel.sysrq = 1

Then you can press Alt+SysRq followed by one of the following commands
(and there are many more commands than these):

s Sync Forces a sync, and prints 'OK' to the console when complete.
u Umount Try to umount all filesystems & remount read-only
b Boot Reboot the system without killing any processes

Best if you use Alt+SysRq-s and Alt-SysRq-u first to avoid data loss

Similarly, you can also control sysrq via /proc/sysrq-trigger by:

echo ‘key’ > /proc/sysrq-trigger

Below are some examples:

echo s > /proc/sysrq-trigger (like Alt+SysRq-s)
echo u > /proc/sysrq-trigger (like Alt+SysRq-u)
echo b > /proc/sysrq-trigger (like Alt+SysRq-b)

Here is a list of ‘key’ available:
'r' - Turns off keyboard raw mode and sets it to XLATE.
'k' - Secure Access Key (SAK) Kills all programs on the current virtual console. NOTE: See important comments below in SAK section.
'b' - Will immediately reboot the system without syncing or unmounting your disks.
'c' - Intentionally crash the system without syncing or unmounting your disks.
'o' - Will shut your system off (if configured and supported).
's' - Will attempt to sync all mounted filesystems.
'u' - Will attempt to remount all mounted filesystems read-only.
'p' - Will dump the current registers and flags to your console.
't' - Will dump a list of current tasks and their information to your console.
'm' - Will dump current memory info to your console.'0'-'9' - Sets the console log level, controlling which kernel messages will be printed to your console.
'0', for example would make it so that only emergency messages like PANICs or OOPSes would make it to your console.
'e' - Send a SIGTERM to all processes, except for init.
'i' - Send a SIGKILL to all processes, except for init.
'l' - Send a SIGKILL to all processes, INCLUDING init. (Your system will be non-functional after this.)
'h' - Will display help ( actually any other key than those listed above will display help.

See sysrq.txt somewhere underneath /usr/src/linux-XXX/Documentation for more information.