How to LINUX machine as a router.

Hi guys, could you help me to configure my Linux machine to behave as router?

Scenario:
Machine OS: CentOS 6.2
NIC: eth0: configured with a static IP by the ISP.
eth1: not configured yet

Virtual Machine: CentOS 5.7
NIC : eth0 : not configured yet
eth1 : not configured yet

Plan is to configure the virtual machine (CentOS 5.7) as a router. After that this machine will also be the dhcp server as well. DHCP is not an issue but the configuration of router you can say.

Please help me in the configuration.

With Best Regards...

What good is a router in a virtual machine?

That's why suggestions are needed please....
Advice me that what machine is good for router...
Virtual machine (CentOS 5.7) or host machine (CentOS 6.2)????

You could try setting up the virtual machine as a router but I wouldn't see the point. Getting the configuration correct to bridge the real traffic into the virtual traffic so you can route anything meaningful would probably be more difficult than the actual work of configuring your router.

I'd try setting up your real machine as a router; set your second NIC to 192.168.1.1, run dnsmasq on it for DHCP and dns, use NAT with masquerade. Unfortunately I don't have instructions for centos.

hhhhmmmm....
so i can understand that we can configure our host machine better then virtual machine.
& " I would like to say that there is nothing difference b/w CentOS, Red Hat & Fedora regarding file locations, commands,configuration etc... But I can assume some of the minor difference, Which I have not see yet"

So its decided that I am going to configure my host machine's second NIC "eth1" as a router & I'll post all the configurations & hope you'll guide me...
Thanks allot ,,,,....

---------- Post updated 02-04-12 at 02:05 AM ---------- Previous update was 02-03-12 at 09:03 PM ----------

Yes I done it...
I configure my Linux machine to behave like a router.
Configurations are as follow!

First we need to enable packet forwarding on the kernel level. So append the following two lines in /etc/sysctl.conf file:

# vim /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 1

Now Configure your interface with the following parameters, In my case the interface was eth1 you may follow yours, So I apply this command to make changes/to set the parameters:

# vim /etc/sysconfig/network-scripts/ifcfg-eth1

Parameters for the eth1 file should like this:

DEVICE=eth1
BOOTPROTO=none
IPADDR=10.3.20.1
IPV6INIT=no
ONBOOT=yes
NAME=eth1
NETMASK=255.255.255.0
HWADDR=00:04:75:EB:D0:A3
TYPE=Ethernet
PREFIX=24
GATEWAY=10.3.20.1
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04

Now add the route followed by the command:

# route add -net 10.3.20.0 netmask 255.255.255.0 gw 10.3.20.1 dev eth1

To define the routing for the 10.3.20.0 network on the 10.3.20.1 interface (eth1) open the file:

# vim /etc/sysconfig/network-scripts/route-eth1

IN this file append the following line:

10.3.20.0/24 via 10.3.20.1

Now restart the network service with the following command:

# service network restart

Check the new route with the following command:

# route -n

In my case the outputs was like this:

[root@rash ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.3.20.0       0.0.0.0         255.255.255.0   U     1      0        0 eth1
192.168.15.0    0.0.0.0         255.255.255.0   U     1      0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
0.0.0.0         192.168.15.1    0.0.0.0         UG    0      0        0 eth0
You have new mail in /var/spool/mail/root

You may easily find the new route in these information.
Conguratulations with this guide you have configured your Linux machine to act as a router.:slight_smile:

Before you spend a lot of time on this, have a look here FREESCO Project

Dear JGT,
if I am not wrong. (plz correct me if I am).
its windows based software hhhmmm...

No, its Linux, but it runs from a DOS FAT16 partition, or diskette. I used it to connect my network to a dial up connection before rural high speed wireless was available

Dear Jgt,
I think the way that I follow is the easy & best way to route our networks. Rather then 1st we have a DOS FAT16 partition or diskette.
only make changes in your files gives the route & enjoy.
What you think about this???