Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-19-2008, 04:59 AM   #1
Registered: Aug 2008
Posts: 66

Rep: Reputation: 18
1 linux box with 2 nic cards connecting 2 different networks

1 linux box with 2 nic cards should be able to connect between 2 networks. In order to run one linux box on 2 networks .

any corrections need in the following steps ?

Steps i follow are :

1 ) /etc/resolv.conf :
i will add 2 networks dns server IP's .
1 st network :
nameserver XXX.XXX.XXX.XXX - IP address of primary name server nameserver XXX.XXX.XXX.XXX - IP address of secondary name server

2 nd network :
nameserver XXX.XXX.XXX.XXX - IP address of primary name server nameserver XXX.XXX.XXX.XXX - IP address of secondary name server

2) /etc/hosts
I will add ips here.
1 st network IP :
XXX.XXX.XXX.XXX node-name
2 nd network IP :
XXX.XXX.XXX.XXX node-name

Assigning IP address :
In each file :
if 2 nic cards are in static
Static IP address configuration:
ONBOOT=yes - Will activate upon system boot

if 2 nic cards are in DHCP configuration :

If DHCP configuration :

Configuring gateway address :


i will add :

HOSTNAME=my-hostname - Hostname is defined here and by command hostname FORWARD_IPV4=true - True for NAT firewall gateways and linux routers.
False for everyone else - desktops and servers.

GATEWAY="XXX.XXX.XXX.YYY" - Used if your network is connected to another network or the internet.
Static IP configuration. Gateway not defined here for DHCP client

Enable Forwarding :
Turn on IP forwarding to allow Linux computer to act as a gateway or router.
echo 1 > /proc/sys/net/ipv4/ip_forward

net.ipv4.ip_forward = 1

Special routing information may be specified :
eth1 net XXX.XXX.XXX.0 netmask gw XXX.XXX.XXX.XXX

Access ISP network identified by the network address and netmask using network interface card eth0:
route add -net netmask gw eth0
Conversly: route del -net netmask gw eth0

i same way i will add other other nic card to connect to local lan

next :
/etc/sysconfig/network-scripts/ifup to bring the various network interfaces on-line

In order for updated information in any of these files to take effect, one must issue the command: service network restart

Commands for starting and stopping TCP/IP network services on an interface :

Activate: /sbin/ifup eth0
(Also: ifconfig eth0 up - Note: Even if no IP address is assigned you can listen.) De-Activate: /sbin/ifdown eth0
(Also: ifconfig eth0 down)

Last edited by vamsi_k; 10-19-2008 at 05:01 AM.
Old 10-19-2008, 09:46 AM   #2
ReliaFree Maintainer
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
You really should tell us which distro you're using. Not all
distros do networking the with the same files. For example,
what you describe wouldn't work on my CLFS boxes. Might work
for whaterver distro you're using though. I do suspect that you'd need an /etc/sysconfig/network-scripts/ifcfg-eth1 for the second NIC.
Old 10-19-2008, 11:09 AM   #3
LQ Newbie
Registered: Mar 2005
Location: Jakarta
Distribution: RedHat 9
Posts: 3

Rep: Reputation: 0
i always use this configuration.
As example first network connect to eth0 the network id, the second network connect to eth1 the network id

so i just do :
ifconfig eth0
ifconfig eth1
route add -net netmask gw
route add -net netmask gw
echo 1 > /proc/sys/net/ipv4/ip_forward

And another computer at the first network assign as their gateway and the second network assign as their gateway.

it works for me. But you just make it permanent.
Old 10-20-2008, 01:21 AM   #4
Registered: Aug 2008
Posts: 66

Original Poster
Rep: Reputation: 18
Operating system : centos

thanks jejen. i will try the same.
Old 10-22-2008, 06:39 AM   #5
Registered: Aug 2008
Posts: 66

Original Poster
Rep: Reputation: 18
success. thanks jejen it worked.

Last edited by vamsi_k; 10-24-2008 at 09:01 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
linux box as a router between two networks LinuxLover Linux - Server 1 08-04-2007 02:25 AM
setting up routes - box with two nic cards josh_mcqueen Linux - Networking 2 07-21-2005 09:53 AM
Linux with multiple network cards, and bridging both networks together fuckyou Linux - Networking 2 07-10-2005 08:21 PM
Connecting Linux box to Internet through Windowx XP box over LAN pcd007 Linux - Networking 1 03-14-2004 10:02 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:01 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration