TECH SOLUTION

TECH SOLUTION

Monday, 28 October 2013

Configuring Linux Machine As a Router(GATEWAY & ROUTERS)



Gateways and Routers
1.     Even though after subnetting individual network segments cannot communicate with each other, to configure a path for them we use router.

2.     Router is necessary for separate networks to communicate with each other, each network must be connected to a router in order for this communication to take place.

3.     This router that is connected to each network is called its gateway.

4.     In Linux, you can use a computer with two network interfaces to route between two or more subnets. To be able to do this you need to make sure that you enable IP Forwarding.

5.     You can check this by entering the following query at a command prompt:
cat /proc/sys/net/ipv4/ip_forward

6.     If forwarding is enabled, the number 1 is displayed; if forwarding is not enabled, the number 0 is displayed.

7.     To enable Ip forwarding if it is not already enabled, type the following command:
Echo “0” > /proc/sys/net/ipv4/ip_forward

Assume that a computer running Linux is acting as a router for your network, It has two network interfaces to the local LANs using the lowest available IP address in each subnetwork on its interface to that network.

Configuring Dynamic Host Configuration Protocol(DHCP) Basic Theory



Configuring Dynamic Host Configuration Protocol

1.     Using DHCP, you can have an IP address and the other information automatically assigned to the hosts connected to your network.

2.     This method is quite efficient and convenient for large networks with many hosts, because the process of manually configuring each host is quite time consuming.

3.     By using DHCP, you can ensure that every host on your network has a valid IP address, subnet mask, broadcast address, and gateway, with minimum effort on your part.

4.     You should have a server configured for each of your subnets and Each host on the subnet needs to be configured as a DHCP client.

5.     You may also need to configure the server that connects to your ISP as a DHCP client if your ISP dynamically assigns your IP address

Setting up the server

1.     The program which runs on the server is dhcpd and is included as an RPM on Red Hat 7.2 installation CD 2.

2.     Look for the file dhcp-2.0pl5-1.i386.rpm and use the Gnome-RPM (the graphical RPM tool) from the desktop, or use the rpm command from a command prompt to install it.

3.     In Red Hat Linux the DHCP server is controlled by the text file /etc/ dhcpd.conf.

4.     If this file does not exist on your server, you can create it using a text editor. Be sure to use the proper addresses for your network.

5.     To start the server, run the command dhcpd. To ensure that the dhcpd program runs whenever the system is booted, you should put the command in one of your init scripts.
Configuring the client

1.     First you need to check if the dhcp client is installed on your system. You can check for it by issuing command: which dhcpcd

2.     If the client is on your system, you will see the location of the file.

3.     If the file is not installed, you can find it on Red Hat Installation CD 1.

4.     Install the client using the rpm command. After you install the client software, start it by running the command dhcpcd.

5.     Each of your clients will now receive its IP address, subnet mask, gateway, and broadcast address from your dhcp server.

Since you want this program to run every time the computer boots, you need to place it in the /etc/rc.local file. Now whenever the system starts, this daemon will be loaded.

Classless Interdomain Routing (CIDR)



Classless Interdomain Routing (CIDR)
1.     CIDR was invented several years ago to keep the Internet from running out of IP addresses.

2.     The class system of allocating IP addresses can be very wasteful. Anyone who could reasonably show a need for more than 254 host addresses was given a Class B address block of 65,533 host addresses.

3.     Even more wasteful was allocating companies and organizations Class A address blocks, which contain over 16 million host addresses.

4.     People realized that addresses could be conserved if the class system was eliminated. By accurately allocating only the amount of address space that was actually needed, the address space crisis could be avoided for many years.

5.     This solution was first proposed in 1992 as a scheme called supernetting. Under supernetting, the class subnet masks are extended so that a network address and subnet mask could, for example, specify multiple Class C subnets with one address.

6.     For example, if you needed about a thousand addresses, you could supernet 4 Class C networks together.

7.     CIDR will probably keep the Internet happily in IP addresses for the next few years at least.

8.     After that, IPv6, with 128 bit addresses, will be needed. Under IPv6,0 even careless address allocation would comfortably enable a billion unique IP  addresses for every person on earth

Setting Up a Network Interface Card(NIC) & Loopback Interface(lo)



Setting Up a Network Interface Card
Loopback Interface
1.     Even if the computer is not connected to outside networks, an internal network functionality is required for some applications.

2.     This address is known as the loopback and its IP address is 127.0.0.1.

3.     You should check that this network interface is working before configuring your network cards.

4.     To do this, you can use the ifconfig utility to get some information. If you type ifconfig at a console prompt, you will be shown your current network interface configuration.

5.     If your loopback is configured, the ifconfig shows a device called lo with the address 127.0.0.1. If this device and address are not shown, you can add the device by using the ifconfig command as follows: ifconfig lo 127.0.0.1

6.     You then need to use the route command to give the system a little more information about this interface. For this you type: route add -net 127.0.0.0

7.     You now have your loopback set up and the ifconfig command shows the device lo in its listing.


Configuring the network card

1.     Configuring a network card follows the same procedure as configuring the loopback interface.

2.     You use the same command, ifconfig, but this time use the name ‘eth0’ for an Ethernet device.

3.     You also need to know the IP address, the netmask, and the broadcast addresses.

4.     These numbers vary depending on the type of network being built.

5.     For an internal network that never connects to the outside world, any IP numbers can be used, however there are IP numbers typically used with these networks.

RESERVED NETWORK NUMBERS

Network Class
Netmask
Network Addresses
A
255.0.0.0
10.0.0.0–10.255.255.255
B
255.255.0.0
172.16.0.0–17.31.255.255
C
255.255.255.0
192.168.0.0–192.168.255.255


6.     If you are connecting to an existing network, you must have its IP address, netmask, and broadcast address. You also need to have the router and domain name server addresses.

7.     In this example, you configure an Ethernet interface for an internal network. You need to issue the command:
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255

8.     The result of above is file get created in /etc/sysconfig/network-scripts called ifcfg-etho

9.     We can check this file by issuing following command  :
[root@main~]# cat /etc/sysconfig/network-scripts/ifcfg-etho


Note : A broadcast address is a logical address at which all devices connected to a multiple-access communications network are enabled to receive datagrams. A message sent to a broadcast address is typically received by all network-attached hosts, rather than by a specific host.

Configuring an internal network

1.     Now you have a network device configured for one computer, to add additional computers to your network you need to repeat this process on the other computers you want to add.

2.     The only change is that you need to assign a different IP address. For example, the second computer on your network could have the address 192.168.1.2, the third could have 192.168.1.3, and so on.

3.     In addition to configuring the network cards on each of the computers in the network, three files on each computer need to be modified. These files are all located in the /etc directory and they are:
                                                              i.      /etc/hosts
                                                            ii.      /etc/hosts.conf
                                                          iii.      /etc/resolv.conf

4.     The /etc/hosts.conf file contains configuration information for the name resolver and should contain the following:
order hosts, bind   multi on

5.     This configuration tells the name resolver to check the /etc/hosts file before attempting to query a nameserver and to return all valid addresses for a host found in the /etc/hosts file instead of just the first.

6.     The /etc/hosts file contains the names of all the computers on the local network.

7.     For a small network, maintaining this file is not difficult, but for a large network keeping the file up to date is often impractical.

The /etc/resolv.conf file provides information about name servers
employed to resolve hostnames.
[root@main~]# cat /etc/resolv.conf
search rcn.com
nameserver 192.168.2.1