LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 09-07-2009, 12:19 AM   #1
wimnat
Member
 
Registered: Dec 2004
Location: Sydney, AU
Distribution: CentOS 5.x, Backtrack
Posts: 72

Rep: Reputation: 16
Question Route configuration problem


Sorry to hijack but I am faced with a similar problem.

I have two NICs. Eth0 and Eth1.

One is connected to my private network and the other to my public network.

If I specify my default gw in my eth0 config then all is well on the private side but the box is publically inaccessible. Vice versa if I set the gw in my eth1 config.

I can ping both interfaces.

So, time to crack out the route command.

I tried adding a default gw for both networks...

Code:
[root@yum ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
203.38.38.38  0.0.0.0         255.255.255.224 U     0      0        0 eth1
10.0.8.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth1
0.0.0.0         203.38.38.38  0.0.0.0         UG    0      0        0 eth1
[root@yum ~]# route add default gw 10.0.8.1 eth0
[root@yum ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
203.38.38.38  0.0.0.0         255.255.255.224 U     0      0        0 eth1
10.0.8.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth1
0.0.0.0         10.0.8.1        0.0.0.0         UG    0      0        0 eth0
0.0.0.0         203.38.38.38  0.0.0.0         UG    0      0        0 eth1
Now there is no metric differnce but I thought that the interface value would be enough to distinguish the traffic.

However, this is not the case. With the above route table I can reach services on my public IP (like SSH) but not my private. Again, both are pingable.

I have checked config files of services and they are configured to bind to all interfaces.
 
Old 09-07-2009, 06:30 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I moved your post to it's own thread. Please don't highjack someone else's thread. It can cause confusion keeping track which answer is for which post, and may reduce the number of replies as a result.
 
Old 09-07-2009, 06:52 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Having two default gateways doesn't make sense. Does eth1 connect to a router or your ISP's modem?

Code:
203.38.38.38  0.0.0.0         255.255.255.224 U     0      0        0 eth1
The destination address should be a network address, unless you are subnetting the 203.38.38.36 network into several subnets. Something like 203.38.38.32. I just masked 38 with 224 to obtain 32.

Given that you have a host address (the default gateway) of the same value, you entered the gateway IP address instead of the network for the first route.
 
Old 09-07-2009, 09:19 AM   #4
evilted
Member
 
Registered: Aug 2009
Location: Ouagadougou, Burkina Faso
Distribution: centos
Posts: 92

Rep: Reputation: 18
you need something called policy routing. 2 default gateways doesnt work. metric's are not failover, but a measure of distance (hops) and are obselete (apparently) in newer versions of linux.

we have 2 defaults
Code:
0.0.0.0         10.0.8.1        0.0.0.0         UG    0      0        0 eth0
0.0.0.0         203.38.38.38  0.0.0.0         UG    0      0
but if you run a trace route you will see that your are only using the gateway at 10.0.8.1.
remember that the default gateway is also called the gateway of last resort. so when your machine looks up a route in the routing table, it will go to the default when the route doesnt exist. having 2 defaults defeats the purpose. only one default will be used - if the last entered gateway (in your case the 10.0.8.1) is considered/marked a dead gateway will you use the 2nd (first entered gateway 203.38.38.38)

Code:
echo 200 to_local >> /etc/iproute2/rt_tables
ip rule add from 10.8.0.1 table to_local
ip route add default via 10.0.8.1 dev eth0 table to_local
you can leave your gateway for internet access as the default(203.38.38.38) and add a gateway for your local (if you really need it). this should make access to both networks.. (you may need routes for your public net in the routing table for the local net.. you should be able to do this from the code above..

most people dont realize that they are using policy routing. if you type 'ip rule show table main' you will see the entries in the main (default) table. these are created when you make routing in the normal manner.. route add -net (some net)/(some subnet) gw (some gateway)

read here -> http://lartc.org/howto/
and here -> http://lartc.org/howto/lartc.rpdb.html

Last edited by evilted; 09-07-2009 at 09:26 AM. Reason: added info
 
Old 09-07-2009, 11:28 PM   #5
wimnat
Member
 
Registered: Dec 2004
Location: Sydney, AU
Distribution: CentOS 5.x, Backtrack
Posts: 72

Original Poster
Rep: Reputation: 16
Thanks, this works after one small adjustment. I had to add the whole subnet...

Code:
ip rule add from 10.8.0.0/24 table to_local
rather than

Code:
ip rule add from 10.8.0.1 table to_local
How can I make these rules stay in place on a 'service network restart'?
 
  


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
Gateway and route configuration veeruk101 Linux - Networking 1 07-25-2007 07:30 AM
Configuration of a route through 2 networks jmcustiel Slackware 8 07-14-2007 11:24 PM
Route configuration jokobbb Linux - Networking 12 03-31-2006 11:32 AM
static route configuration guide bholler Linux - Networking 4 05-20-2005 12:21 PM
Windows route configuration easier than Linux??? hdalle Linux - Networking 5 08-25-2004 06:14 AM

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

All times are GMT -5. The time now is 09:58 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