LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-11-2007, 02:52 PM   #1
jonfa
Member
 
Registered: Mar 2001
Location: FL
Posts: 257

Rep: Reputation: 30
routing with 2 nics


Hi All,

I am trying to setup my Centos 4.4 box with two nics as a static router. Here is what I have:

Nic1: 10.0.0.80 eth3
Nic2: 192.168.1.1 eth2

I have applied the following iptables rules:

/sbin/iptables -t nat - A POSTROUTING -o eth2
/sbin/iptables -t nat - A POSTROUTING -o eth3
/sbin/iptables -t filter -A FORWARD -d 192.168.1.1 -s 10.0.0.0/24 -j ACCEPT

I then added a route:

route add -net 10.0.0.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth2

I enabled ip_forwarding in /proc/sys/net/ipv4/ip_forward so that is =1.
I cannot ping one nic to the other. Any ideas on what could be cuasing the problem? Thanks
 
Old 04-11-2007, 03:04 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
to route at the simplest level, there's no need for iptables at all, just the ip_forward. you also need do routing commons for those two networks on the routing machine as it already knows where those networks are. what you would need to route is the traffic from each client to that box in the first place.
 
Old 04-11-2007, 03:09 PM   #3
jonfa
Member
 
Registered: Mar 2001
Location: FL
Posts: 257

Original Poster
Rep: Reputation: 30
Thanks for the quick reply. Can you explain "routing commons"? Also, does it matter what their their default gateways are if I'm simply trying to ping from within the machine? For example:

$ping -I eth2 10.0.0.80

where eth2 has the ip address of 192.168.1.1
 
Old 04-11-2007, 03:50 PM   #4
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Rep: Reputation: 65
This is what I do. Setup eth0 as the main nic gateway. Define an IP, netmask, gateway for the interface. Also setup dns ip in /etc/resolv.conf. Then for eth1 set only the IP and netmask values. Do not set a gateway on this nic. Now enable ip_forward like you did that should all that is needed.

Brian
 
Old 04-11-2007, 04:37 PM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
sorry i meant "routing commands"... nothgin cryptic there after all..
 
Old 04-11-2007, 05:09 PM   #6
jonfa
Member
 
Registered: Mar 2001
Location: FL
Posts: 257

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Brian1
This is what I do. Setup eth0 as the main nic gateway. Define an IP, netmask, gateway for the interface. Also setup dns ip in /etc/resolv.conf. Then for eth1 set only the IP and netmask values. Do not set a gateway on this nic. Now enable ip_forward like you did that should all that is needed.

Brian
Tried what you said and still a no go. I have ip_forward enabled, but I can't seem to ping one nic to another within the same physical box. Any suggestions?
 
Old 04-11-2007, 05:58 PM   #7
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Rep: Reputation: 65
Do you have three nics in the machine?

Brian
 
Old 04-11-2007, 07:01 PM   #8
jonfa
Member
 
Registered: Mar 2001
Location: FL
Posts: 257

Original Poster
Rep: Reputation: 30
I have 2 nics:

Nic1 (eth2): 192.168.1.1
Nic2 (eth3): 10.0.0.80
 
Old 04-11-2007, 09:14 PM   #9
bigb0ss
LQ Newbie
 
Registered: Oct 2004
Distribution: Redhat / Open SuSE
Posts: 4

Rep: Reputation: 0
simple Router configuration

Nic1: 10.0.0.80 eth3 - Local system interface
Nic2: 192.168.1.1 eth2 - Internet connected interface

Lets consider 192.168.1.1 which is connected to the internet router


1) ping localy for both interfaces to make sure the interface is up

2) ping your internet gateway from the local system to check whether the system is reachable if it works that subnet(192.168.1.0) is okie

3) you can also make sure by connecting a system in the same subnet like 192.168.1.10 and try pinging 192.168.1.1

4) vi /etc/sysctl.conf

net.ipv4.ip_forward = 1 # Add the above entry in the above file


5) you can set your 192.168.1.10's default gateway as 192.168.1.1 for 10.0.0.0/24 and check whether you receive a reply if you dont want to setup default gateway u can use the route add command

route add -host 10.0.0.80 gw 192.168.1.1 eth1 <------ this is to be configured in the local 192.168.1.10 system

7) ping now 192.168.1.10 ---> 192.168.1.1
ping now 192.168.1.10 ---> 10.0.0.80

As we have enabled forwarding both nic's should be pingable

To Make it as a router we need to configure the table NAT

iptables --table nat --append POSTROUTING --out-interface eth2 -j MASQUERADE

iptables --append FORWARD --in-interface eth3 -j ACCEPT

service iptables save

After issuing the 3 commands hopefully it should work, it works for VPN Server as well.

The above settings are for your settings of eth2 and eth3 nic. In your case eth2 is connected to internet router and eth3 is the local network and systems connected within the 10.0.0.0/24 subnet should point thier gateway as 10.0.0.80 and so that systems in that network will be allowed internet access or to reach the sytem which is reachable via 192.168.1.0/24 subnet
 
Old 04-11-2007, 10:16 PM   #10
jonfa
Member
 
Registered: Mar 2001
Location: FL
Posts: 257

Original Poster
Rep: Reputation: 30
bigb0ss,

I tried as you instucted, but still a no go. I cannot ping the internal nics (by internal I mean nic1 cannot ping nic2).

I double checked my ip_forward and it is set to 1.

I'm stumped!
 
Old 04-12-2007, 12:54 AM   #11
crazyivan
Member
 
Registered: Mar 2007
Distribution: Debian, Ubuntu server
Posts: 40

Rep: Reputation: 15
It might be not of help at all, but I was wondering: since machines usualy start counting nic's starting from eth0, what happend to your eth0 and eth1?
 
Old 04-12-2007, 02:04 AM   #12
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
ok, well run tcpdump on the client, the router and the remote peer and see who sees what icmp packets.
 
  


Reply



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
Two NICs and routing bks Linux - Networking 2 02-19-2007 01:14 PM
Routing between 2 NICs Tinochelli Linux - Networking 4 12-09-2004 11:33 AM
Problem routing between 2 nics linuxdoctor Linux - Networking 3 08-17-2004 06:18 PM
dual nics and routing dhill Linux - Networking 2 11-18-2003 10:12 AM
Routing with 3 nics _TK_ Linux - Networking 2 09-25-2001 11:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:33 AM.

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