Basic Networking Howto.

July 16th, 2008 by amatesi

 

Since my job deals mainly with Networking stuff, I’m gonna post a summary for me, to remember always how does it works. The following takes into account the structure of LAN Networks with TCP/IP Suite of Protocols.

In the past, I (as many others), have fallen into confusion when talking about IP Addresses/Subnets-Subnet Mask, Broadcasts and Binary Conversion.

The following is my 2cents to help draw this confusion away.

Who invented IPv4 protocols, introduced the Classes concept to better separate and distinguish a Network from another (even if today we have CIDR - but ignore it for now). The Classes concept is just a theory and is not constraining at all; you can have a Class C address layout and yet have a different network. Let’s say you have a 192.168.1.0 Network; it is obviously a class C Network, because the address is on the range 192..203, but if you specify a Subnet Mask that is not the usual one (say 255.0.0.0), you can!

The fact I wish to underline is that, saying it is a class C address, and the Subnet Mask is 255.0.0.0 is not related: the Subnet and the Class simply are unrelated concepts (for the foretold network you’d usually apply the 255.255.255.0 Subnet Mask, but this is just to simplify things). This way we’ll have the Network (aka Subnet) address masked with its own mask, and for the example we would have a 192.0.0.0 network.

Usually the difference between a class A, B or C address lies in the first 4 bits of the first octet.

Octet: a series of 8 bits composing an IP Address; this is an octet -> | 1 1 1 1 1 1 1 1 | wich translates as 255 on decimal, for us humans (try it with the calculator!)

A class A address does have the FIRST bit of the octet as a ZERO, so -> | 0 1 1 1 1 1 1 1 | translates to 127, but 127 class A address is reserved for loopback, so the range for Class A Network is 1..126 (126 is | 0 1 1 1 1 1 1 0 | ) (loopback is a special address that refer always to "YOUR_PC").

Class B address does have the SECOND bit of the octet as a ZERO, so -> | 1 0 0 0 0 0 0 0 | translates to 128, then the range assigned to class B is 128..191 (191 is | 1 0 1 1 1 1 1 1 | ).

Class C address does have the THIRD bit of the octet as a ZERO, so -> | 1 1 0 0 0 0 0 0 | translates to 192, then the range assigned to class B is 192..203 (203 is | 1 1 0 1 1 1 1 1 | ).

Class D is another form of Classes, intuitively Class D range from 224..239 (wich is | 1 1 1 0 0 0 0 0 | to | 1 1 1 0 1 1 1 1 |), where ZERO Lies on the fourth bit position.

After the preview, now let’s analyze how subnetting works.

To understand subnetting, it is important to remember that, inside a Network, there are some constraints:

  1. A network have a well-defined IP address that have usually a zero (ex. 192.168.1.0) [but it can be different from zero just in case].
  2. A Network does have always a Broadcast address (usually in the form of network-address plus last bits set at 1, i.e.: 192.168.1.255).
  3. The Network is an address masked with a Subnet Mask (in fact a Network can also be called just a Subnet).
  4. There is a limited number of possible addresses (based on the Subnet mask).

It is almost impossible to make a huge single network (like a pure class B - 65536 hosts), without considering subnetting, because the network will become clogged, slow and unmaintainable (technically there happens "collisions"). The problem lies on broadcasting: when you have a huge segment, and a client broadcasts, this broadcast spread to the entire, 65536 hosts’ network! So when you logically separate a network from the other, the broadcasts are limited to a subnet.

For this reason we use subnetting, by separating a Network Segment from another and by joining them accordingly by using a router, usually a device with two I/Fs, one on either end, connecting two different networks (maybe next article..).

Enter Subnet Mask.

The Subnet Mask is an IP-like address composed of binary ONES and ZEROS. The SM is a layer applied to an IP Address to "identify" and distinguish a network from the hosts.

An IP address is composed of bits, these bits can be one or zeros; when you specify a mask, you have to apply this mask to the IP address to identify precisely what the network is.

Example:
IP: 192.168.1.0 - netmask: 255.0.0.0

Open questions:

  1. What is the class?
  2. What is the network?
  3. What is the Broadcast?
  4. What IP address the Network’s hosts should have?

 Answers:

  1. The Class of the Network is Class C, because 192 translates to | 1 1 0 0 0 0 0 0 | and the ZERO lies on the third bit.
  2. The Network is 192.0.0.0, because the subnet mask is composed of all | 1 1 1 1 1 1 1 1 | on the first octet, and when we have all 1s on the octet, we want to distinguish the network part from the host part [by assigning a 1 to the net and a 0 to the host]. This is how it works intuitively, in reality it is the result of a logical AND operation.
  3. The Broadcast address is 192.255.255.255, that is because all the host bits part should be set at all 1s, since the hosts part of the network is the 0.0.0 of the 192.0.0.0 network, and we set them to all 1s ( | 1 1 1 1 1 1 1 1 | -> 255 decimal).
  4. A host inside this network could have an address like 192.1.10.14 or 192.100.25.1 or whatever.

Extension of answer 3:
The logical AND operation gives 1 only when applied to two 1s, so:

0 AND 0 -> 0;

0 AND 1 -> 0;

1 AND 0 -> 0;

1 AND 1 -> 1;

If we put into column IP plus Subnet Mask, and we apply the AND operation on ‘em, we’d obtain the right Network address:

IP: | 1 1 0 0 0 0 0 0 | . | 0 0 0 0 0 0 0 0 | . | 0 0 0 0 0 0 0 0 | . | 0 0 0 0 0 0 0 0 |

AND

M: | 1 1 1 1 1 1 1 1 | . | 0 0 0 0 0 0 0 0 | . | 0 0 0 0 0 0 0 0 | . | 0 0 0 0 0 0 0 0 |

we gain the right Network Address:

N: | 1 1 0 0 0 0 0 0 | . | 0 0 0 0 0 0 0 0 | . | 0 0 0 0 0 0 0 0 | . | 0 0 0 0 0 0 0 0 |

 

Addendum:

Today we can find some address expressed in the form IP.Address/number (like 192.168.1.0/24).

What this mean is simple: It is a network that dedicates the first 24 bits on the Subnet Mask (as 1s for the network part), and the rest 8 bits as 0s (on the hosts part). So we intuitively identify this network as 192.168.1.0 (given by the AND operation between the IP and the Subnet Mask,  192.168.1.0 AND 255.255.255.0 -> CONVERTED TO BINARY -> AND OPERATION -> CONVERT THE RESULT TO DECIMAL -> 192.168.1.0 as Network Address).

That seems all.

Posted in System Administrator | No Comments »

XP clone & migrate (without reinstall).

March 2nd, 2008 by amatesi

A new MB doesn’t always mean headaches … OK, OK, I know, I know, let’s take this #### pill.

I got this new super/ultra/cool/powerful ________ Gigabyte GA-P35C-DS3 MB.

It’s intel P35 based. I come from XP and I am an usual (not MMOG addicted), gamer.

So, all of my data stood inside a SATA WD Raptor X 150G, including my OS, XP. I needed to move this XP install from the good old glorious, powerful, full-featured, performing _______ ASUS A7N8X-Deluxe Rev 2 to this new Gigabyte.

I proceeded this way:

  1. Connected a new IDE disk to the IDE controller.
  2. Booted Ubuntu live and cloned the Raptor inside the new IDE HD (dd if=/dev/sda of=/dev/hda bs=32256).
  3. Booted the old MB with the new IDE HD and made sure it worked perfectly and flawlessly.
  4. SYSPREP-PED it with sysprep.exe, found inside XP_CD\SUPPORT\TOOLS\Deploy.cab (I used these options, “MiniSetup” and “Pre-Activate”- get ready for product key).
  5. Switched the IDE HD from the old to the NEW MB.
  6. Booted it.
  7. After some MS XP basic questions, I got my old desktop.
  8. I then installed the new drivers.

All of this can seem daunting, a pain in the ass, but, seriously, it isn’t. For me, everything went just fine but my SATA HDDs: they disappered!…Next arcticle is gonna show you hou I managed to get my SATA HDDs working; I anticipate that I’ve the other SATA HDDs on “AHCI mode” from BIOS (for other reasons…soon I will tell why).

Posted in MS Windows, System Administrator | 1 Comment »

Beagle mess & Evolution error.

February 26th, 2008 by amatesi

Ubuntu Linux aims at being a good OS solution for the desktop. The fact that it aims doesn’t necessarily means it is already…I heard 2008 will have more to say about this.
Form me, I think it is good enough, and I enjoy using it everyday, yet sometimes I encounter “strange” & “correlated” errors that I haven’t saw into a “more” commercial OS couterpart combo (XP+Office+Live Search in that case).
And that’s the great effort were I think Canonical is fully committed to: integration between “bazaar” software.

My actual OS is an upgraded Feisty 7.04 -> Gutsy 7.10.
I’m not saying everything went perfect the first time, but with some sanity, I tried to keep things working correctly as they were. And at 99% I made it behave just fine (without buying anything).

A (bad) reminiscence of Feisty was a little sniffy guardian Beagle (dog).

Beagle is an indexing tool that scans your HD for metadata and indexes it for faster searches (like Google Desktop Search).
In Gutsy, Beagle was (reasonably) replaced by Tracker, another, perhaps more stable, indexing solution.

The error I expected was related to a remnant of beagle that I forgot to remove; so, I had this process in memory, automatically booted everyday, that insanely tracked and Indexed every file inside my PC (maybe more than once).
I ended up locked and with no space left (I have a WD 250Gb HD).
My routine is made of daily emails, browsing (I never delete its cache), and I/O ( I always keep my recycle bin full), etc… well…ordinary stuff as everyone else, but not so much to fill a 250Gb HD with stuff (ex. my Home folder actually is almost 5 Gb).

The (mad) beagle-related process, day after day, filled my home folder (and consequently my HDD), with tons of indexed CRAP. What it was, exactly, I simply ignore it.
So recently I ended up having with a full (99.9%) /.

I figured it after the other (open) programs started complaining,and popped strange errors, especially my email client, Evolution.

The error message received from Evolution was stating: “Error while storing folder ‘inbox’ Summary and folder mismatch even after a sync”. WTF???
So I started to digg and figure what the problem was.

First thing:

  • rm -r /home/andy/.beagle

…to free up some space.

Next, Synaptic and (complete) removal of beagle and beagle-evolution.

Then a fast close/open Send/Receive with Evolution: error message still there :(

Some more research, some more infos: I had to close all Evolution processes, this way:

  • evolution –force-shutdown

…from a terminal.

Next thing: I cd to “.evolution” inside my home folder and searched for the main Inbox folder.

  • cd .evolution/mail/local

There I found a file called Inbox.ibex.index;
I renamed this file with something else, then restarted Evolution.

Everything clean and fixed.

Note: if you like me, never delete something, unless 100% sure, you can now safely rm the previously renamed file.

Back to work, now :-P

Posted in GNU Linux, System Administrator | No Comments »

my rsync fav options

January 30th, 2008 by amatesi

Today I’ll post my rsync fav options;
rsync is a lil program that automates syncronization between two folders, FS or partitions, even remotely by using ssh credentials (better used with keys…).
Its main use is to move every kind of data inside the network, keeping it synchronized. That mean that he check all the files that are on one side and confront them withe the files that are on the other side, transferring efficiently only the stuff that change!
Every standard Linux System Administrator should know it (man rsync), but I understand there is too much options.

At its basic it is used so:
rsync $SOURCE $DESTINATION

were $SOURCE and $DESTINATION can be a local folder or a remote folder accessed via ssh (ex.: andy@192.168.1.1:/home/andy/backup)

But if you tweak it a bit you can gain some more functions/performance.
I usually play with it through bash scripts but occasionally I use it directly from the console. When I use it from console, I need to remember the various settings I like, that I’m gonna share here for convenience.

Generally, for a basic rsync between two places, and with no deletion, I use this:
rsync -aHvzh –progress SRC DST

-a is synonym to using -rlptgoD, “a” does stand for archive; the included “a” options will be analized next.
-H stand for preservation of Hard Links (a synonymous name for an inode, ex. “DATA” is the real, meaningful, data and A.txt and B.txt is a pointer to that data).
-v is for verbose; I like talkative programs.
-z is for gzip compression during transfer (not where it puts the files, it is real time) — Best with powerful processors.
-h is for human readable sizes (in place of telling me: “transfered 10737418240 bytes”, he would say: “Hey mate, your 10Gb it’s already there!”).
–progress does show progress in real time with ASCII gfx.

Now let’s check what does -rlptgoD mean (they are simpler…):

-r is for recursive, essentially I need this to move entire directories, not only files.
-l keeps the symbolic links so.
-p keeps the same file permissions on the receiving side (r,w & x).
-t keeps the same date and time modification (better keep it for efficiency purposes, rsync this way know if the file changed or else).
-g similar as g, keep the same group on the receiving side.
-o similar as o, keep the same owner (the user) on the receiving side.
-D mean that it preserves character devices and block devices (ls /dev to see what these are) on the receiving side.

A very useful option I used in the past was -n

-n does stand for DRY RUN, it means that you are still not sure about wich option to use, and wanna still just try and experiment with the thousand options how the transfer will be, but without making it happen for real…very useful!

Then there are the various –delete-when? They are useful when you are sure that the transfer is ONE WAY (if not sure, don’t use it!) only.
You can use:
–delete-before
–delete-after &
–delere-during
Wich all do DELETE the transfered files at the specified time.

Then we have the exclude-from=files, a good option that allow rsync NOT to transfer the specified directories & files following the “=”. After the “=” can be used also a file containing all the files/dirs not needed during the transfer (say /sys, /dev, /tmp & all).
Example:
Let’s say I do not want to transfer the following folders: tmp, dev, proc, sys, floppy, cdrom, rsync, mnt, media ;
I create a file wich contain, for every line, the name of a folder I don’t need:
echo -e “/tmp\n/dev\n/proc\n/sys\n/floppy\n/cdrom\n/rsync\n/mnt\n/media\n” > /tmp/excluded.txt

…then I recall my rsync with the option exclude-from=/tmp/excluded.txt and the joke is done!

Posted in GNU Linux, System Administrator | No Comments »

change debian hostname.

January 18th, 2008 by amatesi

I stuck into a little problem related to a hostname change; basically I needed to change hostname for a basic debian install.

I then powered up my fav browser with my fav search engine (FF + Google), then searched for that stuff.

Easy as that! You change Hostname by simply doing

vi /etc/hostname (and put your new hostname inside this file, in place of the old one)

and that’s all. NOT!!!

Now launch

vi /etc/hosts

…and change also the other stuff were you see the old name.

Now you can safely reboot (or simply logoff/logon) to see changes take effect immediately.

Posted in GNU Linux, System Administrator | No Comments »

MS Windows XP, Win2k3 & Vista Password Reset mini-Howto.

January 14th, 2008 by amatesi

Generally, I am used to store my _important_ combo of user/password inside a key+strong password encryption DB file.
The Software I love (and hate) is KeepassX (grab your copy here http://www.keepassx.org/ - XP, Linux or Mac OS X).

Once in a while (especially after holidays…), I may forgive to keep my passwords DB updated, as a result, I may end up struggling to gain access at a damn login screen :-((
…and that’s what just happened recently!

So I was in the search of a free method to reset the MS Windows Local User Account’s Password. The case applied to an install of MS Windows 2003 Server, but it should apply as well as for Windows XP and Windows Vista.
After some Goggleing, I ended up to an interesting method that worked fine (and freely) for me: I downloaded a mini CD with a linux kernel from here: http://home.eunet.no/~pnordahl/ntpasswd/ (thanks pnordahl!), mounted the iso inside the VM and booted it. Then I just followed the on screen info (it’s easy: menu driven), you are presented with a List of functions to choose from, simply by pressing corresponding letters/numbers.

Important Note: This method writes data inside windows registry by using ntfs-3G, a GNU/Linux RW NTFS compatibility layer, believed safe to use (no warranties BTW). Be sure to have Windows NTFS partition (were Windows resides) CLEANLY UMOUNTED, else the program won’t work. Some W2k3 (for security reasons I guess), need to be correctly shutdown from an user logged in; if you shut it down by cold reset or power OFF, you’ll end up with an unclean NTFS.
I’ve read somewere (and suggest hereby) first booting Windows in “Safe Mode” (by pressing F8 before the Boot Up process), then Reboot from there.
Next mount the iso and boot from it. Then you’re ready to reset the User Local Account’s Password !

You could now boot your windows & enjoy.

Posted in MS Windows | No Comments »

Do you Active FTP through Firewall+NAT ?

November 23rd, 2007 by amatesi

Here’s my experience on actively contributing in the resolution of a problem related to Active FTP & gnu-linux/ip-tables based firewall solution.

First, make sure your firewall has loaded the following modules:

ip_conntrack_ftp
ip_nat_ftp

Then check that the right Forwarding rules apply:

iptables -I FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

being “RELATED” the important part.

Hope it saves the day to someone…mines already got lost :(

Posted in GNU Linux, System Administrator | 3 Comments »

Boot Debian Installer from USB flash drive.

November 20th, 2007 by amatesi

My primary objective is to make a pc boot from usb flash drive and make him launch the standard debian installer.

Make sure BIOS is set to boot from USB (also called Removable Device).

Get boot.img.gz (here stable):

wget http://ftp.be.debian.org/debian/dists/etch/main/installer-i386/current/images/hd-media/boot.img.gz

unzip & put raw content inside the UNMOUNTED flash drive:

zcat boot.img.gz > /dev/sdc (assuming sdc is yours).

Get current netinst iso image (here etch-netinst):

wget http://cdimage.debian.org/debian-cd/4.0_r1/i386/iso-cd/debian-40r1-i386-netinst.iso

then copy image inside flash drive as is.

Now plug flash drive inside the pc to boot then start it up: if it works, it will boot a kernel and find the iso image for the install process.

Notes: if you see @ partitioning time your flash drive listed before your HDDs, then check BIOS option “Boot Removable Devices First” and put it to “disabled”.

Original Reference: http://www.debian.org/releases/sarge/i386/ch04s04.html.en

Posted in GNU Linux, System Administrator | No Comments »