Tuesday, September 24, 2013

TCP/IP Configuration with Linux

TCP/IP stands for Transmission Control Protocol/Internet Protocol.This protocol is used for computer communications.All the computers which have a LAN card installed in them,has a unique MAC address i.e. a unique hardware address.This is data-link layer address and used by switches to identify a node.
The IP address on the other hand , is a network layer addressing process and is known and stored by routers.Every node of network has a unique IP address.(Pvt. IP can be same for different networks).The ip addresses has two parts, a network part to indicate a network and a host part to indicate a host in the network.It is a 4 byte address in case of ip4 addressing, and denoted by converting them decimal and put a dot inbetween them. e.g. 192.168.8.15.The network id is divided in class A(First byte 0-127), class B(128-191),class C(192-223),class D(224-239) and class E(240-255).
To see what is the IP of your machine,type on your linus machine
$ /sbin/ifconig or ifconfig(for windows type ipconfig in the command prompt)
it will give output like that-
inet addr: 192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0
.........and all the needed info.
The address 127.0.0.1 is called loopback address.
To configure your ethernet card type the following command
ifconfig eth0 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255
 Type
$cat /etc/sysconfig/network-scripts/ifcfg-eth0
for details of settings of eth0 adapter.
Understanding Subnetting:
IP numbers are not assigned to host ; they are assigned nnetwork interfaces on the host.It is possible to assign more than one IP address to single NIC card.This can be possible by ifconfig and route command.To add another IP to eth0,we issue the command given below-
$ ifconfig eth0:1 192.168.1.4
$ route add -host 192.168.1.4 dev eth0
The first command binds the IP address to virtual interface eth0:1 and second command directs it to eth0.

We can write IP address in Binary notation too.
192.168.1.2 will become
11000000.10101000.00000001.00000010
(128+64).(128+32+8).(1).(2)
Left two on bits means the IP is class C IP.The remaining bits are used to identify the network interface.
Class A uses left quad to identify the network,rest quads for finding host.The first bit of the class A is always 0 and so it has total 128 network ID and 33,554,430 possible host ID per network ID.
Class B IP address has left two bits turned to 10 and so it has 14 bits left to specify network ID and rest bits to specify host ID.
Two identify a network we have to see if its first two three bits are 0,10 or 110.0 means A,10 means B,110 means C and so on.In every network e.g.
192.168.3.0- It is called network number(First IP of the network)
192.168.3.42 - A host IP of the network
192.168.3.255- Broadcast ID of the network
Every network reserves its first and last IP.Whenever we subnet a network we create two unusable IPs.So don't subnet your network more than necessary.
Next we have to find out the network mask. It is the used to find out the network part of the IP address i.e if we bitwise and it with the IP address we get netID. so, for class C network it is 11111111.11111111.11111111 i.e. 255.255.255.0. for class B it si 255.255.0.0.Subnetwork takes one or more host bit and make them network bit.If we want to divide class C network into two subnetwork,we should change the first host bit to 1, and get subnet mask of 255.255.255.128.This would give 126 possible IP for each of your subnet.
Class C subnets and subnet mask:

No. of Bits       NO. of subnets    subnet mask      no. of host
1                         2                   255.255.255.128           126
2                         4                   255.255.255.192            62
3                         8                   255.255.255.224             31
4                         16                 255.255.255.240             14
5                         32                 255.255.255.248               6
6                         64                 255.255.255.252               2
ecf2a426ff


Awesome Watches

No comments:

Post a Comment

Feautured Post

Python Trivia Post: enumerate()

Python has a very useful inbuilt function, which is called enumerate(). This is needed whenever you need the numbering of a certain element...