View previous topic :: View next topic |
Author |
Message |
blazter n00b

Joined: 07 Jul 2004 Posts: 6
|
Posted: Wed Jul 07, 2004 1:11 am Post subject: Help! Two different gateways on the same machine... |
|
|
Hi there people. I'm facing a very difficult problem.
I've set up a linux gentoo box with 2 ethernet cards. This machine should be a firewall and internet router.
I've 2 different types of internet connection attached to this pc:
1. a Efficient Networks modem on a switch doing NAT. This modem is accessed by the machine through a gateway address.
2. a direct ip conection to the internet. this is a internet connection that's up giving the ethernet card the right ip and gateway.
So this is the configuration:
Internet <-> NAT Modem <-> Switch <-> gentoo box pointing to the modem gateway for internet access.
Internet <-> Ethernet Card configured with a valid ip on the internet
The ethernet cards' configuration:
Eth0:
ip: 10.0.0.100 (local ip)
gateway: 10.0.0.138 (modem)
Eth1:
ip: 200.0.0.100 (a valid ip on the internet)
ip: 200.3.123.123 (the gateway used for internet access through this interface)
I need to use the 2 ethernet cards to route the internet access.
I'm using iptables, and the configuration is all right, the problem is that gentoo is using the default gateway 10.0.0.138, for internet access no matter what rule I set with iptables.
When the gateway is set to 10.0.0.138 (modem), all internet connections are routed through eth0, but eth1 don't work right.
Although when I set 200.3.123.123 (direct ip access) as the default gateway, the internet access is routed to the eth1 interface.
I need some way to set a gateway for eth0 and a gateway for eth1, then things will work.
I've search the internet but no answers for this question have been found.
Thanks, and sorry for the long text.  |
|
Back to top |
|
 |
tuxmin l33t


Joined: 24 Apr 2004 Posts: 838 Location: Heidelberg
|
Posted: Wed Jul 07, 2004 4:29 am Post subject: Re: Help! Two different gateways on the same machine... |
|
|
blazter wrote: |
I'm using iptables, and the configuration is all right, the problem is that gentoo is using the default gateway 10.0.0.138, for internet access no matter what rule I set with iptables.
|
Of course not -- iptables is not about routing! Use /sbin/route
blazter wrote: |
I need some way to set a gateway for eth0 and a gateway for eth1, then things will work.
I've search the internet but no answers for this question have been found.
|
You simply can't have two default gateways. That's why it's called *default* ;P
You will have to set routes for every single net through the interface of your choice, anything else will go through the default route.
Hth, Alex!!! _________________ ALT-F4 |
|
Back to top |
|
 |
blazter n00b

Joined: 07 Jul 2004 Posts: 6
|
Posted: Wed Jul 07, 2004 3:44 pm Post subject: |
|
|
Yes, I can have a default gateway for each interface. Even windows can do it. The problem is that linux always makes things difficult!
Any solution!? |
|
Back to top |
|
 |
blazter n00b

Joined: 07 Jul 2004 Posts: 6
|
Posted: Wed Jul 07, 2004 3:44 pm Post subject: |
|
|
Yes, I can have a default gateway for each interface. Even windows can do it. The problem is that linux always makes things difficult!
Any solution!? |
|
Back to top |
|
 |
nobspangle Veteran


Joined: 23 Mar 2004 Posts: 1318 Location: Manchester, UK
|
Posted: Wed Jul 07, 2004 4:57 pm Post subject: |
|
|
you can't have more than 1 default gateway, even on a windows machine. Here is the routing table for a windows machine that I have tried to set two default gateways.
Code: | ===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.0.1 192.168.0.15 20
0.0.0.0 0.0.0.0 192.168.1.5 192.168.1.1 30
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
192.168.0.0 255.255.255.0 192.168.0.15 192.168.0.15 20
192.168.0.15 255.255.255.255 127.0.0.1 127.0.0.1 20
192.168.0.255 255.255.255.255 192.168.0.15 192.168.0.15 20
192.168.1.0 255.255.255.0 192.168.1.1 192.168.1.1 30
192.168.1.1 255.255.255.255 127.0.0.1 127.0.0.1 30
192.168.1.255 255.255.255.255 192.168.1.1 192.168.1.1 30
224.0.0.0 240.0.0.0 192.168.0.15 192.168.0.15 20
224.0.0.0 240.0.0.0 192.168.1.1 192.168.1.1 30
255.255.255.255 255.255.255.255 192.168.0.15 192.168.0.15 1
255.255.255.255 255.255.255.255 192.168.1.1 192.168.1.1 1
Default Gateway: 192.168.0.1
=========================================================================== |
You will notice there is only one default gateway, there are also two routes to 0.0.0.0 but trust me windows will only use the first one (the default)
Maybe if you explained a little of the background about why you need a computer with 2 Internet connections we can offer you a solution |
|
Back to top |
|
 |
Storm666 n00b

Joined: 21 Jun 2004 Posts: 3
|
Posted: Wed Jul 07, 2004 6:54 pm Post subject: |
|
|
blazter, you may have a gateway per interface, but the concept of a default gateway is to tell your computer what to do when no route match actual destination, then the machine try to speak with the default gateway, expecting a response...
Like Nobspangle said, tell us why you need to use those 2 interfaces to be connected to the net and maybe we will be able to help you. _________________ Never underestimate the power of stupid people in large group... |
|
Back to top |
|
 |
think4urs11 Bodhisattva


Joined: 25 Jun 2003 Posts: 6659 Location: above the cloud
|
Posted: Wed Jul 07, 2004 7:35 pm Post subject: |
|
|
Hi!
From what i understood you want to use one internet for some sort of internet traffic and the other one for some oder kind, correct?
That's called policy or source based routing. As the name implies the routing decision is no longer taken purely by destination address. You can additionally use source ip, port number and other things.
You want to read something about advanced routing e.g.
http://snafu.freedom.org/linux2.2/docs/advanced-routing/
or
http://lartc.org/howto/
and you want to emerge iproute2
HTH
T. _________________ Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself |
|
Back to top |
|
 |
splooge l33t

Joined: 30 Aug 2002 Posts: 636
|
Posted: Wed Jul 07, 2004 8:24 pm Post subject: |
|
|
"Default Gateway" is a misleading term. Think of it as the "Gateway of last resort."
eg: When all routing matches fail, where does it send the packet?
You really can't have more than one last resort, and that's basically what the default gateway is. _________________ http://get.a.clue.de |
|
Back to top |
|
 |
blazter n00b

Joined: 07 Jul 2004 Posts: 6
|
Posted: Thu Jul 08, 2004 2:19 am Post subject: |
|
|
Here is what I want to do:
All internet traffic that comes from eth1, must return to eth1.
eth1 is the direct ip access interface, and I'm running a daemon behind the router. The problem is that, when the client machines connects through the eth1 interface, the server daemon response is routed back through the eth0 interface (modem), and the communication fails.
This occurs because eth0 has the default gateway. I can't set the default gateway for eth1, because all internet traffic used by the employees must use the modem connection, eth0.
That's my problem.  |
|
Back to top |
|
 |
kashani Advocate


Joined: 02 Sep 2002 Posts: 2032 Location: San Francisco
|
Posted: Thu Jul 08, 2004 5:12 am Post subject: |
|
|
Argh! This is approaching the mythic status of T1's not being full duplex.
1. You can have as many default routes as you feel like typing. default route in OS speak means gateway of last resort in the routing world. Go ahead type route add default gw ip.add.re.ss in a few times with different addresses. Then type netstat -rn to see them all.
2. Generally what you want to do is called policy routing. You make a policy and then route according to it. You decide which route you wanted based on destination and source with a few ACLs on a Cisco.
3. If you set two default gateways Linux will alternate between them. Usually an OS will use the local interface gateway by default unless you've got metrics set like splooge's example. Of course it uses the first as the metric is 20 and other was 30.
You haven't explained how you want thing to work though. Something like:
1. users on x IP space need to go to eth0
2. users on y IP space need to go to eth1
3. x users will be natted behind x1 IP address
4. y users will no be natted.
and so on.
I've never done policy routing in Linux, but this link might get you started. Assuming this is what you want to do. You're less than clear in your posts.
http://www.unixreview.com/documents/s=1350/urm0006d/
kashani _________________ Will personally fix your server in exchange for motorcycle related shop tools in good shape. |
|
Back to top |
|
 |
|