2012/12/31

RIP version 1 Vs RIP version 2

RIP = Routing Information Protocol

RIP was first introduced in 1988 in RFC 1058 and was developed for exchanging routing information among gateways and other hosts. By the time RIP served it purpose well when networks were small and didn't require complex subnet allocations.

While RIPv1 is still widle used, in modern networks RIPv1 has been replaced with enchaned RIPv2. RIPv2 was developed 1993 and standardized 1998. It was developed to make RIP more effecient and secure.

How RIP works

Basic function of RIP is to send periodic updates every 30 seconds. In this update, routers will exchange their routing tables, so they can keep track how to reach different networks. They will update even when there is no changes in the routing tables.

Originally RIPv1 sent these updates trough broadcast address of 255.255.255.255. RIPv2 protocol uses 224.0.0.9 which is a multicast address, greatly saving bandwidth and increasing performance of updates.

Fastest path will be decided with Hop Count (Hops between subnets). Hop Count is limited to 15 so everything above 16 hops is considered unreachable. This way infinite loops cannot happens in RIP network.

RIPv1 Vs RIPv2


RIPv1 vs RIPv2
Classful vs Classless

RIPv1 used classful routing, it means that RIPv1 couldn't send subnet information in its periodic updates.

Classful routing protocol will look up the first octet of your IP address and determinate which class it belongs to.

For instance if your IP address belongs to Class B, it has a default subnet of  /16 (255.255.0.0). If your network would be 172.10.10.0/24, Classful routing protocol would see only 172.10.0.0/16 and ignore your /24 network.

RIPv2 is a Classless routing protocol and now routers can have subnet masks in their routing tables. Enabling you to have any kind of network and RIP doesn't have to rely on the class of the IP address anymore!

Broadcast updates has been replaced with multicast

Since broadcasting routing tables to every host in your network creates a lot of overhead. RIPv2 multicasts updates are only received by those who are interested about them. Which is a lot more efficient.

Lack of authentication creates security vulnerabilities

Since RIPv1 doesn't support authentication. Any device can send updates to your routers. If malicious device enters your network, it could advertise any networks to neighbouring routers and they would trust it fully.

RIPv2 can exchange passwords with MD5 encryption.

Lack of VLSM made IP addressing inefficient

RIPv2 can send subnetmasks in its periodic updates, which allows RIP to handle any size of subnets. This made IP addressing a lot more efficient since you can allocate smaller blocks of IP addresses for networks that didn't have many hosts.

2012/12/30

Inodes in Linux

What is a inode, Why we need them ?

Have you ever wondered where is your access permissions located? How does your system know that you are the owner of your home folder? Is it written on the file itself ?

Answer to your questions is the Inodes also known as Index nodes.

Inode is a data structure, inodes stores all data about the file objects, except data content and file name. Unix doesn’t use the file name to refer to the file, it uses the inodes and inodes are pointing to actual block addresses where the data is located. inodes reside in Inode table (see Ext4 Disk Layout)

Windows (NTFS) equivalent is Master file table
Max OSX (HFS) equivalent is Catalog File

POSIX standard description for inode is:


  • File size in bytes
  • Owner and Group of the file
  • Device ID (device where file is contained)
  • file mode (access permissions)
  • Timestamps (Content last modified (mtime), Inode last modified(ctime) and Last accessed (atime))
  • Link count (how many hard links point to the inode)
  • Pointers to actual disk blocks that are containing the data
  • Additional system and user flags (limit its use and modification)


Unix or Linux systems doesn't usually store creation date, but ext4 has an attribute for creation date.

crtime (Create time) and also a dtime (Delete time)

inodes allows us to do linking and gives us significant performance increase, because inodes points us to the right data block when we are querying for files.

You can run out of inodes, what happens then ?

inode limit is decided at file system creation time. Its not a fixed value. You can check your current inodes usage with df -i


 Filesystem      Inodes  IUsed  IFree IUse% Mounted on  
 /dev/sda1      14983168  95016 14888152  1% /  

If you happen to run out of Inodes before you run out of disk space, you simply cannot create any more files or directories that consume Inodes, your things start to get very messy and unstable :)

stat command

stat displays file or file system status.

You can query file or file system with stat, for example for file:

 m@srv:~/symlink_test$ stat file1  
  File: `file1'  
  Size: 65         Blocks: 8     IO Block: 4096  regular file  
 Device: 801h/2049d     Inode: 5506851   Links: 1  
 Access: (0644/-rw-r--r--) Uid: ( 1000/  m)  Gid: ( 1000/  m)  
 Access: 2012-12-30 14:38:23.983590932 +0200  
 Modify: 2012-12-30 14:38:49.112092037 +0200  
 Change: 2012-12-30 14:38:49.112092037 +0200  

and for file system (use -f flag)

 m@srv:~/symlink_test$ stat -f /dev/sda1  
  File: "/dev/sda1"  
   ID: 0    Namelen: 255   Type: tmpfs  
 Block size: 4096    Fundamental block size: 4096  
 Blocks: Total: 191863   Free: 191821   Available: 191821  
 Inodes: Total: 191863   Free: 191262  


Inode data pointers, direct blocks and indirect blocks

One inode can point only to 12 blocks of data.

So if your block size is 4096, that would mean 12x4096 = 49152 bytes (48kb). This limitation would suck so that's why inode also has 3 indirect block pointers.

Indirect block pointer points to a block of block pointers, which.. again can point to indirect blocks that will point to new set of block pointers! This allows us to have very large files in our file system.

I tried to illustrate this with a picture but i ended up with a big messy pile of lines. Please check the wikipedia page for more info.


2012/12/29

Linux Symbolic links: Soft and Hard links

What is a symbolic link? Why its important ?

Symlink (Symbolic link) is a reference to another file or directory. It allows you to point multiple file names to single inode that points to a physical block address on the disk.

Symlink's  are mostly used as a shortcut's, they can make your life a lot easier by making your directories of data available for you where you want it.

How do i make a symlink ?

Use the following option in ln command:

 -s, --symbolic
              make symbolic links instead of hard links

For example:

 ln -s file1 file1_symlink  
 ls -l
 -rw-r--r-- 1 m m 0 2012-12-29 14:57 file1  
 lrwxrwxrwx 1 m m 5 2012-12-29 14:58 file1_symlink -> file1  


How do i make a hard link ?


 ln file1 file1_hardlink  
 ls -l  
 -rw-r--r-- 2 m m 0 2012-12-29 15:03 file1  
 -rw-r--r-- 2 m m 0 2012-12-29 15:03 file1_hardlink  

What is the difference between soft and hard link ?

Most important difference between hard and soft is that soft link depends on the original file.

For example, if i create a soft link and delete the original file that i linked, i cannot access my file trough symlink anymore and it becomes broken link.

 m@srv:~/symlink_test$ cat file1_symlink   
 Hello World!  
 m@srv:~/symlink_test$ rm file1  
 m@srv:~/symlink_test$ cat file1_symlink   
 cat: file1_symlink: No such file or directory  

But in the case of hard link, my file is always accessible if there is one hardlink existing of the file

 m@srv:~/symlink_test$ cat original  
 Hello World!  
 m@srv:~/symlink_test$ ln original hard_linked  
 m@srv:~/symlink_test$ cat original hard_linked   
 Hello World!  
 Hello World!  
 m@srv:~/symlink_test$ rm original   
 m@srv:~/symlink_test$ cat hard_linked   
 Hello World!  

Also hard links do not link paths on different volumes or file systems, soft links do. Soft links also consume inodes but hard links always shares the same inode.

Where is the symbolic link stored ?

Symlinks are just references to a physical location of a file, if you make symlinks, its doesn't meant that you are losing disk space by creating a copies. Symbolic links are stored in the same place as inodes, inodes are the place where disks resides its block addresses.