Saturday, December 31, 2011

Configure Linux as a Router on Red Hat Enterprise Linux 5


Configure Linux as a Router on RHEL5

In this tutorial you will show that how to configure Linux Machine as a Router. Routers are the devices those are used to connect two or more different networks. Routers are very costly devices. Linux could be a cost effective solution of routing in a small company.

In this practical I am using three computers. One System will be use for routing and two others will remain in two different networks. First we will configure the system which is going to play the role of router.

Pre-requisites for both Router and Other Machines:
  • A Linux Machine named Linuxrouter with two different LAN card
  • Two different IP address of Router Machine on two LAN Card one is 210.207.201.100 another is 192.168.161.10
  • Enable IP forwarding.
  • Configure both of the NIC card on Router machine.
  • Two Client machine, both could be Linux or one could be Linux and another could be Windows machine
  • Client Machine one IP address is 210.207.201.1 and another machine IP address is 192.168.161.1

Necessary configuration for Router Machine

IP Configuration: Change the IP address of both LAN card

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

#Broadcom Corporation Net link BCM57875 Gigabyte Ethernet PCI Express
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29: EB: B2: CA
ONBOOT=yes
TYPE=Ethernet
PEERDNS=no
USERCTL=no
IPV6INIT=no
IPADDR=210.207.201.100
NETMASK=255.255.255.0
NETWORK=210.207.201.0
BROADCAST=210.207.201.255

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1

#Broadcom Corporation Net link BCM57875 Gigabyte Ethernet PCI Express
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29: EB: B2: CA
ONBOOT=yes
TYPE=Ethernet
PEERDNS=no
USERCTL=no
IPV6INIT=no
IPADDR=192.168.161.100
NETMASK=255.255.255.0
NETWORK=210.207.201.0
BROADCAST=210.207.201.255

Changing Host name: Change the host name of your Router machine as Linuxrouter.

[root@localhost ~]# vi /etc/sysconfig/network

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=Linuxrouter

Restart or Reload the NIC card: After changing the NIC card and hosting name you have to restart the network of router machine by following this command.

[root@localhost ~]# service iptables stop
[root@localhost ~]# chkconfig iptables off
[root@localhost ~]# service network restart

Enable IP Forwarding: Enable the IP forwarding by editng /etc/sysctl.conf file. So open the File using vi editor.

[root@Linuxrouter ~]# vi /etc/sysctl.conf

                                         Locate the               net.ipv4. ip_forward =0

Replace the Value ‘0’ to 1. This will enable the IP forwarding with permanently. But this requires a system reboot.

Restart Machine: After editing the sysctl.conf file restart your machine by following command.

[root@Linuxrouter ~]# init 6


Necessary configuration for Client Machine

On windows machine:  Right click on Network Place → Right click Local area connection → Select Internet Protocol (TCP/IP) → Click Properties → Select Use the following IP address then put the following IP configuration.

 
On Linux machine:  Change the IP address of both LAN card

[root@ns1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

#Broadcom Corporation Net link BCM57875 Gigabyte Ethernet PCI Express
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29: EB: B2: CA
ONBOOT=yes
TYPE=Ethernet
PEERDNS=no
USERCTL=no
IPV6INIT=no
IPADDR=210.207.201.1
NETMASK=255.255.255.0
Gateway=210.207.201.100
NETWORK=210.207.201.0
BROADCAST=210.207.201.255
GATEWAY=210.207.201.100

Restart or Reload the NIC card: After changing the NIC card restart the network card by following this command.

[root@ns1 ~]# service iptables stop
[root@ns1 ~]# chkconfig iptables off
[root@ns1 ~]# service network restart

Testing the connection from both Linux and windows machine

On windows machine: Type the Following IP address on your command prompt like below, if you get this message then your router is working properly.


On Linux Machine: Open your terminal window by Right clicking on Desktop and then select Terminal.





Now the the Router is properly working.


2 comments:

  1. i cant understand in your post because so many incorrect lines are there. (eth0 and eth0:1 IPS )

    ReplyDelete