Thursday, June 16, 2011

/bin/rm: Argument list too long.

root@mx /var/virusmails # ls
razor-agent.log
spam-3398a20c9a59797df9b57fbe34feeace-20040519-084342-19051-05.gz
spam-57e230b6d1dca0dadf83d858d0b10788-20040519-084400-19144-03.gz
spam-6f3be6d2304f90e418db23443916101a-20040519-082357-18227-10.gz
virus-20040419-091017-12544-01
virus-20040419-130621-14993-07
virus-20040421-120113-57877-07
virus-20040421-165651-61698-07
virus-20040423-020850-90966-03
virus-20040423-090733-97665-04
virus-20040427-211030-99133-07
virus-20040427-225312-01622-01
virus-20040428-190241-18845-05
virus-20040505-103654-59956-10

root@mx /var/virusmails # rm spam-*
/bin/rm: Argument list too long.
How many files was I dealing with here?
root@mx /var/virusmails # ls -1 | grep virus | wc -l
1667

This is not a limitation of the rm command, but a kernel limitation on the size of the parameters of the command. Since I was performing shell globbing (selecting all the files with extension .wrk), this meant that the size of the command line arguments became bigger with the number of the files involved. For who cares this is defined by:
egrep ARG_MAX /usr/include/linux/limits.h

#define ARG_MAX 131072 /* # bytes of args + environ for exec() */


Solution is to remove file through following find command

root@mx /var/virusmails # find . -name 'spam-*' | xargs rm
it works like a charm.

Wednesday, June 15, 2011

LVM


LVM


Logical volume management is a widely-used technique for deploying logical rather than physical storage. With LVM, «logical» partitions can span across physical hard drives and can be resized. A physical disk is divided into one or more physical volumes (PVs), and logical volume groups (VGs) are created by combining PVs. Notice the VGs can be an aggregate of PVs from multiple physical disks.

Example Configuration

This article describes a Linux logical volume manager by showing an example of configuration and usage. We use RedHat Linux for this example.

Physical Volumes PV
With LVM, physical partitions are simply called «physical volumes» or «PVs». These PVs are usually entire
disks but may be disk partitions, for example /dev/sda3 in the above figure. PVs are created with pvcreate to initialize a disk or partition.
Command
Remarks
pvcreate
Initialize a disk or partition for use by LVM
pvchange
Change attributes of a physical volume
pvdisplay
Display attributes of a physical volume
pvmove
Move physical extents
pvremove
Remove a physical volume
pvresize
Resize a disk or partition in use by LVM2
pvs
Report information about physical volumes
pvscan Scan all disks for physical volumes
Example: pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
Physical Volume Groups VG
The PVs in turn are combined to create one or more large virtual disks called «volume groups» or «VGs». While you can create many VGs,one may be sufficient. A VG can grow or shrink by adding or removing PVs from it.
The command vgcreate creates a new volume using the block special device previously configured with pvcreate.
Command
Remarks
vgcreate
Create a volume group
vgchange
Change attributes of a volume group
vgdisplay
Display attributes of volume groups
vgcfgbackup
Backup volume group descriptor area
vgcfgrestore
Restore volume group descriptor area
vgck
Check volume group metadata
vgconvert
Convert volume group metadata format
vgexport
Make volume groups unknown to the system
vgextend
Add physical volumes to a volume group
vgimport
Make exported volume groups known to the system
vgmerge
Merge two volume groups
vgmknodes
Recreate volume group directory and logical volume special files
vgreduce
Reduce a volume group
vgremove
Remove a volume group
vgrename
Rename a volume group
vgs
Report information about volume groups
vgscan
Scan all disks for volume groups and rebuild caches
vgsplit
Split a volume group into two
Example: vgcreate VGb1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
Logical Volumes LV
Once you have one or more physical volume groups you can create one or more virtual partitions called «logical volumes» or «LVs». Note each LV must fit entirely within a single VG.
The command lvcreate creates a new logical volume by allocating logical extents from the free physical extent pool of that volume group.
Command
Remarks
lvcreate
Create a logical volume in an existing volume group
lvchange
Change attributes of a logical volume
lvdisplay
Display attributes of a logical volume
lvextend
Extend the size of a logical volume
lvmchange
Change attributes of the logical volume manager
lvmdiskscan
Scan for all devices visible to LVM2
lvreduce
Reduce the size of a logical volume
lvremove
Remove a logical volume
lvrename
Rename a logical volume
lvresize
Resize a logical volume
lvscan
Scan (all disks) for logical volumes
Example: lvcreate -L 400 -n LVb1 VGb1
This creates a logical volume, named «LVb1», with a size of 400 MB from the virtual group «VGb1».
Filesystems

   Finally, you can create any type of filesystem you wish on the logical volume, including as swap space. Note that some filesystems are more
  useful with LVM than others. For example not all filesystems support growing and shrinking. ext2, ext3, xfs, and reiserfs do support such operations and would be good choices.

Creating the Root Logical Volume «LVa1» during Installation

The physical volumes are combined into logical volume groups, with the exception of the /boot partition. The /boot partition (/dev/sda1) cannot be
on a logical volume group because the boot loader cannot read it. If the root partition is on a logical volume, create a separate /boot partition which is not a part of a volume group.
In this example the swap space (/dev/sda2) is also created on a normal ext3 partition. The setup of the LVM for the root filesystem (/dev/sda3) is done during the installation of RedHat Linux.
After creating the /boot filesystem and the swap space, select the free space and create the physical volume for /dev/sda3 as shown in the next figure.
  1. Select New.
  2. Select physical volume (LVM) from the File System Type pulldown menu.
  3. You cannot enter a mount point yet.
  4. A physical volume must be constrained to one drive.
  5. Enter the size that you want the physical volume to be.
  6. Select Fixed size to make the physical volume the specified size, select Fill all space up to (MB) and enter a size in MBs to give range for the physical volume size,

  1. or select Fill to maximum allowable size to make it grow to fill all available space on the hard disk.
  2. Select Force to be a primary partition if you want the partition to be a primary partition.
  3. Click OK to return to the main screen.
The result is shown in the next figure, the physical volume PV is located on /dev/sda3.
Once all the physical volumes are created, the volume groups can be created.
  1. Click the LVM button to collect the physical volumes into volume groups. A volume group is basically a collection of physical volumes.

  1. You can have multiple logical volumes, but a physical volume can only be in one volume group.
  2. Change the Volume Group Name if desired.
  3. Select which physical volumes to use for the volume group.
Enter the name for the logical volume group as shown in the next figure.
The result is the logical volume group VGa1 located on the physical volume /dev/sda3.

Creating the Logical Volume «LVb1» manually

Create Partitions
For this LVM example you need an unpartitioned hard disk /dev/sdb. First you need to create physical volumes.
To do this you need partitions or a whole disk. It is possible to run pvcreate command on
but I prefer to use partitions and from partitions I later create physical volumes.


fdisk -l
....
vice Boot Start End Blocks Id System
/dev/sda1 * 1 127 1020096 83 Linux
/dev/sda2 128 382 2048287+ 82 Linux swap / Solaris
/dev/sda3 383 2610 17896410 8e Linux LVM
....

The partition type for LVM is 8e.

fdisk /dev/sdb

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):
1
First cylinder (1-2136, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2136, default 2136):
Using default value 2136

Command (m for help):
t
Selected partition 1
Hex code (type L to list codes):
8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help):
w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
This is done for all other disks as well.

Create physical volumes

Use the pvcreate command to create physical volumes.
pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1

Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
Physical volume "/dev/sdd1" successfully created
Physical volume "/dev/sde1" successfully created

Create physical volume group VGb1
At this stage you need to create a physical volume group which will serve as a container for your physical volumes. To create a virtual group with the name «VGb1» which will include all partitions, you can issue the following command.
vgcreate VGb1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1

Volume group "VGb1" successfully created

vgdisplay

--- Volume group ---
VG Name VGb1
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 4
Act PV 4
VG Size 65.44 GB
PE Size 4.00 MB
Total PE 16752
Alloc PE / Size 16717 / 65.30 GB
Free PE / Size 35 / 140.00 MB
VG UUID 2iSIeo-dw0Q-NA07-HUt0-Pjxq-m3gh-f33lAh
Create Logical Volume Group LVb1
To create a logical volume, named «LVb1», with a size of 400 MB from the virtual group «VGb1» use the following command.
lvcreate -L 65.3G -n LVb1 VGb1

Rounding up size to full physical extent 65.30 GB
Logical volume "LVb1" created
Create File system on logical volumes
The logical volume is almost ready to use. All you need to do is to create a filesystem.
mke2fs -j /dev/VGb1/LVb1

mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
8568832 inodes, 17118208 blocks
855910 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
523 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
mount -a
You can now use the filesystem, for the maintenance use one of the above LVM commands.
Moving a VG to another server:

To do this we use the vgexport and vgimport commands.

vgexport and vgimport is not necessary to move disk drives from one server to another.
 It is an administrative policy tool to prevent access to volumes in the time it takes to move them.

1. Unmount the file system
First, make sure that no users are accessing files on the active volume, then unmount it

# unmount /appdata

2.Mark the volume group inactive
Marking the volume group inactive removes it from the kernel and prevents any further activity on it.

# vgchange -an appvg
vgchange -- volume group "appvg" successfully deactivate


3. Export the volume group

It is now must to export the volume group. This prevents it from being accessed on the old server and prepares it to be removed.

# vgexport appvg
vgexport -- volume group "appvg" successfully exported

Now, When the machine is next shut down, the disk can be unplugged and then connected to it's new machine

4. Import the volume group

When it plugged into the new server, it becomes /dev/sdc (depends).

so an initial pvscan shows:

# pvscan
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- inactive PV "/dev/sdc1" is in EXPORTED VG "appvg" [996 MB / 996 MB free]
pvscan -- inactive PV "/dev/sdc2" is in EXPORTED VG "appvg" [996 MB / 244 MB free]
pvscan -- total: 2 [1.95 GB] / in use: 2 [1.95 GB] / in no VG: 0 [0]

We can now import the volume group (which also activates it) and mount the file system.

If you are importing on an LVM 2 system, run:

# vgimport appvg
Volume group "vg" successfully imported

5. Activate the volume group

You must activate the volume group before you can access it.

# vgchange -ay appvg

Mount the file system

# mkdir -p /appdata
# mount /dev/appvg/appdata /appdata

The file system is now available for use.

Monday, June 13, 2011

TOP Descriptions

PID - process ID of the process

USER - User who is running the process

PR - The priority of the process

NI - Nice value of the process (higher value indicates lower priority)

VIRT - The total amount of virtual memory used

RES - Resident task size

SHR - Amount of shared memory used

S - State of the task. Values are S (sleeping), D (uninterruptible sleep), R (running), Z (zombies), or T (stopped or traced)

%CPU - Percentage of CPU used

%MEM - Percentage of Memory used

TIME+ - Total CPU time used

COMMAND - Command issued
Interacting with TOP

Now that we are able to understand the output from TOP lets learn how to change the way the output is displayed.

Just press the following key while running top and the output will be sorted in real time.

M - Sort by memory usage

P - Sort by CPU usage

T - Sort by cumulative time

z - Color display

k - Kill a process

q - quit

If we want to kill the process with PID 3161, then press “k” and a prompt will ask you for the PID number, and enter 3161.
Command Line Parameters with TOP

You can control what top displays by issuing parameters when you run top.

- d - Controls the delay between refreshes

- p - Specify the process by PID that you want to monitor

-n - Update the display this number of times and then exit

If we want to only monitor the http process with a PID of 3166

$ top -p 3166

If we want to change the delay between refreshes to 5 seconds

$ top -d 5

Monday, June 6, 2011

NIS Linux

======================================
Configure NIS Linux:
======================================

portmap The foundation RPC daemon upon which NIS runs.
yppasswdd Lets users change their passwords on the NIS server from NIS clients
ypserv Main NIS server daemon
ypbind Main NIS client daemon
ypxfrd Used to speed up the transfer of very large NIS maps

You need to add the NIS domain you wish to use in the /etc/sysconfig/network file.
For the school, call the domain NIS-SCHOOL-NETWORK and Install ypserv rpm.


#/etc/sysconfig/network
NISDOMAIN="NIS-SCHOOL-NETWORK"

NIS servers also have to be NIS clients themselves, so you'll have to edit the NIS
client configuration file /etc/yp.conf to list the domain's NIS server as being the
server itself or localhost.

# /etc/yp.conf - ypbind configuration file
ypserver 127.0.0.1

Start the necessary NIS daemons in the /etc/init.d directory and use the chkconfig
command to ensure they start after the next reboot.

[root@bigboy tmp]# service portmap start
Starting portmapper: [ OK ]
[root@bigboy tmp]# service yppasswdd start
Starting YP passwd service: [ OK ]
[root@bigboy tmp]# service ypserv start
Setting NIS domain name NIS-SCHOOL-NETWORK: [ OK ]
Starting YP server services: [ OK ]
[root@bigboy tmp]#

[root@bigboy tmp]# chkconfig portmap on
[root@bigboy tmp]# chkconfig yppasswdd on
[root@bigboy tmp]# chkconfig ypserv on

Table 30-1 Required NIS Server Daemons
Daemon
portmap The foundation RPC daemon upon which NIS runs.
yppasswdd Lets users change their passwords on the NIS server from NIS clients
ypserv Main NIS server daemon
ypbind Main NIS client daemon
ypxfrd Used to speed up the transfer of very large NIS maps

Make sure they are all running before continuing to the next step. You can use the
rpcinfo command to do this.

[root@bigboy tmp]# rpcinfo -p localhost
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100009 1 udp 681 yppasswdd
100004 2 udp 698 ypserv
100004 1 udp 698 ypserv
100004 2 tcp 701 ypserv
100004 1 tcp 701 ypserv
[root@bigboy tmp]#

Now that you have decided on the name of the NIS domain, you'll have to use the
ypinit command to create the associated authentication files for the domain. You
will be prompted for the name of the NIS server, which in this case is bigboy.

With this procedure, all non privileged accounts are automatically accessible via
NIS.

[root@bigboy tmp]# /usr/lib/yp/ypinit -m
At this point, we have to construct a list of the hosts which will run NIS
servers. bigboy is in the list of NIS server hosts. Please continue to add
the names for the other hosts, one per line. When you are done with the
list, type a .
next host to add: bigboy
next host to add:
The current list of NIS servers looks like this:

bigboy

Is this correct? [y/n: y] y
We need a few minutes to build the databases...
Building /var/yp/NIS-SCHOOL-NETWORK/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/NIS-SCHOOL-NETWORK'
Updating passwd.byname...
Updating passwd.byuid...
Updating group.byname...
Updating group.bygid...
Updating hosts.byname...
Updating hosts.byaddr...
Updating rpc.byname...
Updating rpc.bynumber...
Updating services.byname...
Updating services.byservicename...
Updating netid.byname...
Updating protocols.bynumber...
Updating protocols.byname...
Updating mail.aliases...
gmake[1]: Leaving directory `/var/yp/NIS-SCHOOL-NETWORK'

bigboy has been set up as a NIS master server.

Now you can run ypinit -s bigboy on all slave server.
[root@bigboy tmp]#

Note: Make sure portmap is running before trying this step or you'll get errors, such
as:

failed to send 'clear' to local ypserv: RPC: Port mapper failureUpdating
group.bygid...

You will have to delete the /var/yp/NIS-SCHOOL-NETWORK directory and restart portmap,
yppasswd, and ypserv before you'll be able to do this again successfully.

You can now start the ypbind and the ypxfrd daemons because the NIS domain files have
been created.

[root@bigboy tmp]# service ypbind start
Binding to the NIS domain: [ OK ]
Listening for an NIS domain server.
[root@bigboy tmp]# service ypxfrd start
Starting YP map server: [ OK ]
[root@bigboy tmp]# chkconfig ypbind on
[root@bigboy tmp]# chkconfig ypxfrd on

All the NIS daemons use RPC port mapping and, therefore, are listed using the rpcinfo
command when they are running correctly.

[root@bigboy tmp]# rpcinfo -p localhost
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100021 1 udp 1024 nlockmgr
100021 3 udp 1024 nlockmgr
100021 4 udp 1024 nlockmgr
100004 2 udp 784 ypserv
100004 1 udp 784 ypserv
100004 2 tcp 787 ypserv
100004 1 tcp 787 ypserv
100009 1 udp 798 yppasswdd
600100069 1 udp 850 fypxfrd
600100069 1 tcp 852 fypxfrd
100007 2 udp 924 ypbind
100007 1 udp 924 ypbind
100007 2 tcp 927 ypbind
100007 1 tcp 927 ypbind
[root@bigboy tmp]#

New NIS users can be created by logging into the NIS server and creating the new user
account. In this case, you'll create a user account called nisuser and give it a
new password.

Once this is complete, you then have to update the NIS domain's authentication files
by executing the make command in the /var/yp directory.

This procedure makes all NIS-enabled, nonprivileged accounts become automatically
accessible via NIS, not just newly created ones. It also exports all the user's
characteristics stored in the /etc/passwd and /etc/group files, such as the login
shell, the user's group, and home directory.

[root@bigboy tmp]# useradd -g users nisuser
[root@bigboy tmp]# passwd nisuser
Changing password for user nisuser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@bigboy tmp]# cd /var/yp
[root@bigboy yp]# make
gmake[1]: Entering directory `/var/yp/NIS-SCHOOL-NETWORK'
Updating passwd.byname...
Updating passwd.byuid...
Updating netid.byname...
gmake[1]: Leaving directory `/var/yp/NIS-SCHOOL-NETWORK'
[root@bigboy yp]#

You can check to see if the user's authentication information has been updated by
using the ypmatch command, which should return the user's encrypted password
string.

[root@bigboy yp]# ypmatch nisuser passwd
nisuser:$1$d6E2i79Q$wp3Eo0Qw9nFD/::504:100::/home/nisuser:/bin/bash
[root@bigboy yp]

You can also use the getent command, which has similar syntax. Unlike ypmatch, getent
doesn't provide an encrypted password when run on an NIS server, it just provides
the user's entry in the /etc/passwd file. On a NIS client, the results are
identical with both showing the encrypted password.

[root@bigboy yp]# getent passwd nisuser
nisuser:x:504:100::/home/nisuser:/bin/bash
[root@bigboy yp]#

Now that the NIS server is configured, it's time to configure the NIS clients. There
are a number of related configuration files that you need to edit to get it to
work. Take a look at the procedure.

The authconfig or the authconfig-tui program automatically configures your NIS files
after prompting you for the IP address and domain of the NIS server.

[root@smallfry tmp]# authconfig-tui

Once finished, it should create an /etc/yp.conf file that defines, amongst other
things, the IP address of the NIS server for a particular domain. It also edits the
/etc/sysconfig/network file to define the NIS domain to which the NIS client
belongs.

# /etc/yp.conf - ypbind configuration file
domain NIS-SCHOOL-NETWORK server 192.168.1.100

#/etc/sysconfig/network
NISDOMAIN=NIS-SCHOOL-NETWORK

In addition, the authconfig program updates the /etc/nsswitch.conf file that lists
the order in which certain data sources should be searched for name lookups, such
as those in DNS, LDAP, and NIS. Here you can see where NIS entries were added for
the important login files.

#/etc/nsswitch.conf
passwd: files nis
shadow: files nis
group: files nis

Note: You can also locate a sample NIS nsswitch.conf file in the
/usr/share/doc/yp-tools* directory.

Start the ypbind NIS client, and portmap daemons in the /etc/init.d directory and use
the chkconfig command to ensure they start after the next reboot. Remember to use
the rpcinfo command to ensure they are running correctly.

[root@smallfry tmp]# service portmap start
Starting portmapper: [ OK ]
[root@smallfry tmp]# service ypbind start
Binding to the NIS domain:
Listening for an NIS domain server.
[root@smallfry tmp]#

[root@smallfry tmp]# chkconfig ypbind on
[root@smallfry tmp]# chkconfig portmap on

Note: Remember to use the rpcinfo -p localhost command to make sure they all started
correctly.

As the configuration examples refer to the NIS client and server by their hostnames,
you'll have to make sure the names resolve correctly to IP addresses. This can be
configured either in DNS, when the hosts reside in the same domain, or more simply
by editing the /etc/hosts file on both Linux boxes.

#
# File: /etc/hosts (smallfry)
#
192.168.1.100 bigboy


#
# File: /etc/hosts (bigboy)
#
192.168.1.102 smallfry

You can run the ypcat, ypmatch, and getent commands to make sure communication to the
server is correct.

[root@smallfry tmp]# ypcat passwd
nisuser:$1$Cs2GMe6r$1hohkyG7ALrDLjH1:505:100::/home/nisuser:/bin/bash
quotauser:!!:503:100::/home/quotauser:/bin/bash
ftpinstall:$1$8WjAVtes$SnRh9S1w07sYkFNJwpRKa.:502:100::/:/bin/bash
www:$1$DDCi/OPI$hwiTQ.L0XqYJUk09Bw.pJ/:504:100::/home/www:/bin/bash
smallfry:$1$qHni9dnR$iKDs7gfyt..BS9Lry3DAq.:501:100::/:/bin/bash
[root@smallfry tmp]#

[root@smallfry tmp]# ypmatch nisuser passwd
nisuser:$1$d6E2i79Q$wp3Eo0Qw9nFD/:504:100::/home/nisuser:/bin/bash
[root@smallfry tmp]#

[root@smallfry tmp]# getent passwd nisuser
nisuser:$1$d6E2i79Q$wp3Eo0Qw9nFD/:504:100::/home/nisuser:/bin/bash
[root@smallfry tmp]#

Once your basic NIS functionality testing is complete, try to test a remote login.
Failures in this area could be due to firewalls blocking TELNET or SSH access and
the TELNET and SSH server process not being started on the clients.
Logging In Via Telnet

Try logging into the NIS client via telnet if it is enabled

[root@bigboy tmp]# telnet 192.168.1.201
Trying 192.168.1.201...
Connected to 192.168.1.201.
Escape character is '^]'.
Red Hat Linux release 9 (Shrike)
Kernel 2.4.20-6 on an i686
login: nisuser
Password:
Last login: Sun Nov 16 22:03:51 from 192-168-1-100.simiya.com
[nisuser@smallfry nisuser]$

Logging In Via SSH

Try logging into the NIS client via SSH.

[root@bigboy tmp]# ssh -l nisuser 192.168.1.102
nisuser@192.168.1.102
[nisuser@smallfry nisuser]$

In some versions of Linux, the NIS client's SSH daemon doesn't re-read the
/etc/nsswitch.conf file you just modified until SSH is restarted. SSH logins,
therefore, won't query the NIS server until this is done. Restart SSH on the NIS
client.

[root@smallfry root]# service sshd restart
Stopping sshd:[ OK ]
Starting sshd:[ OK ]
[root@smallfry root]#

IP Addressing

Class1st Octet Decimal Range1st Octet High Order BitsNetwork/Host ID (N=Network, H=Host)Default Subnet MaskNumber of NetworksHosts per Network (Usable Addresses)
A1 – 126*0N.H.H.H255.0.0.0126 (27 – 2)16,777,214 (224 – 2)
B128 – 19110N.N.H.H255.255.0.016,382 (214 – 2)65,534 (216 – 2)
C192 – 223110N.N.N.H255.255.255.02,097,150 (221 – 2)254 (28 – 2)
D224 – 2391110Reserved for Multicasting
E240 – 2541111Experimental; used for research
Note: Class A addresses 127.0.0.0 to 127.255.255.255 cannot be used and is reserved for loopback and diagnostic functions.

Private IP Addresses

ClassPrivate NetworksSubnet MaskAddress Range
A10.0.0.0255.0.0.010.0.0.0 - 10.255.255.255
B172.16.0.0 - 172.31.0.0255.240.0.0172.16.0.0 - 172.31.255.255
C192.168.0.0255.255.0.0192.168.0.0 - 192.168.255.255

======================================
NETMASK:
======================================
Net bits Subnet mask total-addresses
/20 255.255.240.0 4096
/21 255.255.248.0 2048
/22 255.255.252.0 1024
/23 255.255.254.0 512
/24 255.255.255.0 256
/25 255.255.255.128 128
/26 255.255.255.192 64
/27 255.255.255.224 32
/28 255.255.255.240 16
/29 255.255.255.248 8
/30 255.255.255.252 4
Netmask Netmask (binary) CIDR Notes
255.255.255.255 11111111.11111111.11111111.11111111 /32 Host (single addr)
255.255.255.254 11111111.11111111.11111111.11111110 /31 Unuseable
255.255.255.252 11111111.11111111.11111111.11111100 /30 2 useable
255.255.255.248 11111111.11111111.11111111.11111000 /29 6 useable
255.255.255.240 11111111.11111111.11111111.11110000 /28 14 useable
255.255.255.224 11111111.11111111.11111111.11100000 /27 30 useable
255.255.255.192 11111111.11111111.11111111.11000000 /26 62 useable
255.255.255.128 11111111.11111111.11111111.10000000 /25 126 useable
255.255.255.0 11111111.11111111.11111111.00000000 /24 "Class C" 254 useable
255.255.254.0 11111111.11111111.11111110.00000000 /23 2 Class C's
255.255.252.0 11111111.11111111.11111100.00000000 /22 4 Class C's
255.255.248.0 11111111.11111111.11111000.00000000 /21 8 Class C's
255.255.240.0 11111111.11111111.11110000.00000000 /20 16 Class C's
255.255.224.0 11111111.11111111.11100000.00000000 /19 32 Class C's
255.255.192.0 11111111.11111111.11000000.00000000 /18 64 Class C's
255.255.128.0 11111111.11111111.10000000.00000000 /17 128 Class C's
255.255.0.0 11111111.11111111.00000000.00000000 /16 "Class B"
255.254.0.0 11111111.11111110.00000000.00000000 /15 2 Class B's
255.252.0.0 11111111.11111100.00000000.00000000 /14 4 Class B's
255.248.0.0 11111111.11111000.00000000.00000000 /13 8 Class B's
255.240.0.0 11111111.11110000.00000000.00000000 /12 16 Class B's
255.224.0.0 11111111.11100000.00000000.00000000 /11 32 Class B's
255.192.0.0 11111111.11000000.00000000.00000000 /10 64 Class B's
255.128.0.0 11111111.10000000.00000000.00000000 /9 128 Class B's
255.0.0.0 11111111.00000000.00000000.00000000 /8 "Class A"
254.0.0.0 11111110.00000000.00000000.00000000 /7
252.0.0.0 11111100.00000000.00000000.00000000 /6
248.0.0.0 11111000.00000000.00000000.00000000 /5
240.0.0.0 11110000.00000000.00000000.00000000 /4
224.0.0.0 11100000.00000000.00000000.00000000 /3
192.0.0.0 11000000.00000000.00000000.00000000 /2
128.0.0.0 10000000.00000000.00000000.00000000 /1
0.0.0.0 00000000.00000000.00000000.00000000 /0 IP space