# eth0 and eth1 up but not working, possible routing issue?

## anton

After many attempts to get my nvidia nic working, it finally worked!  But now I have run into problem number two.  I have two nic's in my machine, eth0 (3com pci) and eth1 (nvidia built-in).  I intend on using eth0 to connect to my lan and eth1 to connect to my dsl modem.  As of right now I can use eth0 or eth1 connected to my dsl modem and everything works great; I have access to the internet   :Surprised: 

The problem lies when I try to assign IP's to either card using DHCP from my router.  I have a second machine set to use dhcp and it works perfect everytime.  On my machine with two nic's, even if I manually set the IP's to that of my lan, neither one is able to ping even the router.  I've checked /etc/conf.d/net and everything looks fine in there, I have checked the routing table with route -n and everything appears to be ok in there.  I have even tried multiple gateway settings in the routing table to see if that would help, but to no avail.  Whenever I try to set either card using dhcp I can see the lights on the router flashing and whatnot, as if it were going to work, but eventually it just times out.   :Evil or Very Mad: 

Anyone have any suggestions?  I am baffeled.

----------

## NeddySeagoon

anton,

Which card comes up as eth0 and which card is eth1 depends on the  kernel module load order.

If you haven't built the Ethernet drivers as modues I don't know what determines the order.

You should have two network startup scripts called net.eth0 and net.eth1.  You need to make a copy of net.eth0 and rename it. (In /etc/init.d/. They will both read the /etc/conf.d/net file, so you need to add some more entries for eth1.

Its important that you determine which is which and apply the configs you want.

Post your 

```
/sbin/ifconfig
```

 and 

```
/sbin/route -n
```

 results for more help

----------

## anton

I have /etc/init.d/net.eth0 and /etc/init.d/net.eth1.

(the IP's I am listing are irroneous of course, and my MAC addresses do exist)

my router in this example would be 192.168.71.1

```
ifconfig
```

eth0      Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX

          inet addr:192.168.71.3  Bcast:192.168.71.255  Mask:255.255.255.0

          UP BROADCAST MULTICAST  MTU:1500  Metric:1

          RX packets:37 errors:19 dropped:0 overruns:0 frame:22

          TX packets:17 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:2220 (2.1 Kb)  TX bytes:5260 (5.1 Kb)

          Interrupt:11 Base address:0xc000

eth1      Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX

          inet addr:192.168.71.4  Bcast:192.168.71.255  Mask:255.255.255.0

          UP BROADCAST MULTICAST  MTU:1500  Metric:1

          RX packets:4553 errors:0 dropped:0 overruns:0 frame:0

          TX packets:4843 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:2307166 (2.2 Mb)  TX bytes:456250 (445.5 Kb)

          Interrupt:10 Base address:0xa000

lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:18 errors:0 dropped:0 overruns:0 frame:0

          TX packets:18 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:1396 (1.3 Kb)  TX bytes:1396 (1.3 Kb)

and 

```
route -n
```

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.71.0    0.0.0.0         255.255.255.0   U       0      0        0 eth0

192.168.71.0    0.0.0.0         255.255.255.0   U       0      0        0 eth1

127.0.0.0        127.0.0.1       255.0.0.0          UG     0      0        0 lo

eth0 is loaded with the 3com module and eth1 is loaded with the forcedeth module.  Both show that they are connected to the router, atleast plugged in anyway.  And like I said, I am able to connect my dsl modem to either one and connect to the internet perfectly.  I just can't ping my other box on the lan, nor can I ping the router itself.

right now, my dsl modem is plugged into eth1 and eth0 is plugged into my router.

----------

## NeddySeagoon

anton,

You may not have two interfaces on the same subnet.

You have 

```
(eth0) net addr:192.168.71.3 Bcast:192.168.71.255 Mask:255.255.255.0

(eth1) net addr:192.168.71.4 Bcast:192.168.71.255 Mask:255.255.255.0 

```

If you have a single DHCP service (from your ISP for example) only the interface connected to your ISP can use DHCP.

You can post real 192.168.*.* IP adddress, since they are not routable from the internet.

Your routing table is also missing a default route, which tells the kernel  what to do with packets that are left after all the other routing rules have been tried and failed.

So, you need  to change one of the 71's to something else and add a default route, which should have come either from DHCP or from the gateway statement at the bottom of /etc/conf.d/net.

There is other other possibility. You mention you have both NICs plugged into your router. If you are trying to do 'channel bonding' you need to build the kernel to do that. Then both NICs appear as a single interface.

An ASCII sketch of your intended/actual network layout would help or a thorough description of what is connected to what, along with the real private IPs you are using. You may omit your real external IP., since you will only have a single point of contact with the outside world.

----------

## anton

```

                                    [ dhcp  (router ip: 192.168.1.1)   dhcp]

                                      |                                 |

                                      |                                 |

                                      |                                 |

                                      |                              [ eth0 box2 ip: 192.168.1.67 (dhcp) ]

                                      |

                                      |

                                   [ eth0   box1  eth1 ip: 192.168.2.4]

                                                      |

                                                      |

                                                      --------> [ dsl modem ] ------> internet     

```

Basically this is what I am trying to do.  Box1 has the two nics in it, one to connect to the internet and one to connect to the lan.  Box2 and Box1 are both plugged into the router and 'should' receive ip's via the dhcp from the router.  Box2 does this fine.  I have the router set to start assigning ip's at 192.168.1.67.  So basically I am making box1 into a gateway machine for all internet traffic for any node plugged into the router.  I have done this before, but with dial-up.  My real problem this time is that box1 cannot for the life of it ping the router nor ping box2.  I have connected to the internet with eth0 to make sure the card atleast worked, and connected fine.  I am currently on the internet via eth1, like in the diagram.  I guess all I need now is to figure out why eth0 cannot ping the lan and set the correct routing information so any internet traffic reaching box1 will be routed out through eth1.  I figure NAT will resolve the later routing issue.  I actually have a good firewall script that uses iptables to setup NAT and all that other good stuff.  I am just truely baffeled at why I am having such a hard time pinging the router from box1.   I have manually set the IP on eth0 to be 192.168.1.2 and that still does nothing for me.  I went ahead and changed the IP of eth1 to be static and set it to something slightly different than eth0/ my lan.  I have tried many different things in the routing table, but maybe I am just not setting the right thing.  I hope this helps clear things up a little.[/code]

----------

## anton

oops, my layout picture looks a little screwy, but I think the general idea can be gathered from it

----------

## anton

going to try and post the layout again and see if this one doesn't look any better

```

[ dhcp   (router ip: 192.168.1.1)   dhcp ]

    |                                |

    |                                |

    |                            [ eth0  box2  ip: 192.168.1.67 (dhcp) ]

    |

    |                                                     

[ eth0  box1 eth1 ip: 192.168.2.4 ]

                    |

                    |

                    -----> [ dsl modem ] ----> internet

```

----------

## NeddySeagoon

anton,

I understand the picture. The router assigns addresses using DHCP  to your two PC internel network. I trust that you are using real 192.168.x.x IP addresses now. I think that was the source of much confusion.

On your internal 192.168.1.x subnet, controlled by the router, The NIC IP addresses must all be different but have 192.168.1. in common. You must not assign 192.168.1.0 to any hardware, nor 192.168.1.225. The .0 is the network address and the.255 is the broadcast address. For completeness, the netmask will be 255.225.255.0.

With the Gentoo setup scripts you can't set up your routing entirely automatically, since each PC is only allowed one gateway. You need to add a static route in the PC with two NICs.

If you use  the automatic gateway command to get to the outside world (eth1) in your drawing. The statice route command you need is 

```
route add 192.168.1.0/24 gw 192.168.1.1 eth0
```

This says to get to the network 192.168.1.x send packets down eth0 via 192.168.1.1. (You may not need the gw 192.168.1.1 bit if your router is a transparent switch too.)

Even when you geth DHCP going on eth0, you will still need the static route.

When you can bring it all up manually, put the staic route in /etc/conf.d/local.start, then it will be added at boot time.

----------

## anton

That definitely helped things to start to work, I knew I needed something of that sorts, just didn't know how to do it,thx!  But ... it is still tweaky.  Here is some output from ping and my most recent routing table.

```
 ping:

PING 192.168.1.1 (192.168.1.1) from 192.168.1.2 eth0: 56(84) bytes of data.

64 bytes from 192.168.1.1: icmp_seq=13 ttl=64 time=1.01 ms

From 192.168.1.2 icmp_seq=14 Destination Host Unreachable

From 192.168.1.2 icmp_seq=15 Destination Host Unreachable

From 192.168.1.2 icmp_seq=16 Destination Host Unreachable

From 192.168.1.2 icmp_seq=17 Destination Host Unreachable

From 192.168.1.2 icmp_seq=18 Destination Host Unreachable

From 192.168.1.2 icmp_seq=19 Destination Host Unreachable

From 192.168.1.2 icmp_seq=20 Destination Host Unreachable

From 192.168.1.2 icmp_seq=21 Destination Host Unreachable

From 192.168.1.2 icmp_seq=22 Destination Host Unreachable

From 192.168.1.2 icmp_seq=23 Destination Host Unreachable

From 192.168.1.2 icmp_seq=24 Destination Host Unreachable

From 192.168.1.2 icmp_seq=25 Destination Host Unreachable

64 bytes from 192.168.1.1: icmp_seq=40 ttl=64 time=0.760 ms

64 bytes from 192.168.1.1: icmp_seq=60 ttl=64 time=0.748 ms

--- 192.168.1.1 ping statistics ---

61 packets transmitted, 3 received, +12 errors, 95% packet loss, time 60000ms

rtt min/avg/max/mdev = 0.748/0.842/1.019/0.127 ms, pipe 4

```

and

```
 route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0   192.168.166.1   255.255.255.255 UGH   0      0        0 eth0

192.168.1.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0

192.168.2.0   0.0.0.0         255.255.255.0   U     0      0        0 eth1

127.0.0.0     127.0.0.1       255.0.0.0       UG    0      0        0 lo

```

I tried the command

```
route add 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 eth0
```

and it didn't work at all, so I reissued the command and just left the netmask part out.  That is why the first entry in the routing table has a genmask of 255.255.255.255.

----------

## NeddySeagoon

anton,

Your ping is OK. The  Destination Host Unreachable report should only occur on the first few packets while each part of the network  finds out about the bits it needs to reach the destination. After that the info is kept in caches (in both PCs and the router) and updated regularly behind your back.

No other packets should get lost.

I don't understand the first route to 192.168.166.1. Do you have a system there at all?

Your route commad failed because you gave a singe host address and a netmask for a network, so route was confused.

You need to say either 

```
route add -host ... 
```

or 

```
route add -net ...
```

The slash notation also avoids confustion

192.168.1.0/24 is the 192.168.1.x network while 192.168.1.2/32 is a single host. The number following the slash is the number of binary bits set to '1' in the netmask.

You are still missing your default route, which tells the kernel what to do with any packets that don't match other routes.

----------

## Sir_Chancealot

If your drawing is indeed correct, it should not work at ALL, unless you are using unnumbered PPP internally, which I don't believe is the case.  Now, if your drawing is INCORRECT, my conclusions will be all wrong.   :Wink: 

First, you have at least TWO routers in this case, and possibly three.  Whether you call it one or not, Box1 in your example functions as a router (unless it acts as a proxy server).  As far as I know, you cannot have a router use dhcp unless it has a reserved IP (functionally equivalent to a static mapping, except more complicated from the router's point of view), or unless you are using RIP/OSPF/BGP or some other ROUTING protocol (TCP/IP is a ROUTED protocol).  Of COURSE box 2 will not be able to ping box 1, because the router does not know where to send the packets.  If it does so, it does so by pure chance.  I had that happen once.  I mistakenly set up a Cisco 2600 with the same network on both sides of the router, which is a big no-no, and technically the router should not have worked.  But it did.  I only found the problem due to performance issues.  I'm still amazed at that one.  But I digress......

Set your network up like I am going to show you, and let me know if it solves the problem.

First, let's address Box 2 in your drawing.  We will assume that box 2 picks up the internal address 192.168.2.67.  It's only route will be a default route of 192.168.1.1, which is the router.  A default route says "Any network I don't know about, send to this IP address".  It only needs a default route, because no matter whether the traffic is staying internal or going external, it still goes to the exact same IP address.

The port of the router connected to Box 2 should be 192.168.1.1. 

The port of the router connected to eth0 Box 1 should be 192.168.3.1, to keep things uniform and, as much as possible, the same as your drawing

The router sitting between box 1 and box 2 will need need 3 routes.  This is because it needs to know where to send information on 3 different networks. Anything going to the 192.168.1.0 network goes out the 192.168.1.1 port.  Anything going to the 192.168.3.0 network goes out the 192.168.3.1 port.  (Your router may or may not recognize the directly connected networks, i.e., the 192.168.1.0 and 192.168.3.0 networks.  If it doesn't, you may have to set up the routes manually, by telling it that the 192.168.1.0 traffic goes out the 192.168.1.1 port, and the same for the 192.168.3.0 traffic, but that is rare.)  The final route it will need is a "default route", which will be the IP address of eth0 on box 1.  Unless you want to learn the difference between a routing protocol and a routed protocol, set eth0 on box 1 to a static IP address.  In keeping with your network, I would set eth0 on box1 to 192.168.3.2.

Now, on box 1, eth0 is set as 192.168.3.2, and eth1 is set to 192.168.2.4. 

Box 1 needs two routes.  You should tell box 1 that to reach the network 192.168.1.0, the traffic is to be routed to 192.168.3.1 (IP address of the router). Box 1 should have a default route to your ISP connection.  Remember that a default route tells a router to send any ip addresses of which it is not EXPLICITY aware to a certain IP number.  

Something else that will help with the next part is to remember this:  A router only cares about the NEXT HOP on the route.  It does NOT care where the packets go after that.  (well, if you used OSPF it would, but that is beyond the scope of this  :Laughing:  )

Now, to know where we send default traffic for Box1, we need to know how your DSL is set up, which can be 1 of 2 ways. 

Does the DSL modem ITSELF have an IP address?  If not, then eth1 on Box1 will route to your ISP's router (i.e., the "gateway").  This is basically an unnumbered PPP link.  For example, in your drawing, eth1 on Box1 shows an IP of 192.168.2.4.  Let's say that your ISP's router is 192.168.2.5.  In this instance, your default route becomes 192.168.2.5, and is located AT your ISP, on THEIR router.

If your DSL modem ITSELF has an IP address (two actually, as it would then function as a router), then eth1 on Box1 has to route to that IP address.

For sake of argument, let's say that the INTERNAL ip address of the DSL modem is 192.168.2.5.  In that case, eth1 (with IP address of 192.168.2.4) on box1 needs to have a default route of 192.168.2.5.  In this case, your DSL modem (which is actually a DSL router) needs three routes.  The first is a default route to the ISP's router.  The second is a route to the 192.168.3.0 network through 192.168.2.4 (eth1, box1 ip address), but ONLY if there are other things on the 192.168.3.0 network besides router and box1.  The third is to the 192.168.1.0 network, again through 192.168.2.4 (eth1, box1 ip address).  Remember, it only cares about the next hop, not what the next router does with it after that.

So, to draw a picture (I suck at this.  I could do it in about 2 minutes in visio, and you would get EXACTLY what I meant.)

If DSL modem does NOT have an IP:

Box 2 192.168.1.67 <--->192.168.1.1 (router)192.168.3.1 <-->192.168.3.2 eth0 Box1 eth1 ("public") 192.168.2.4 <-->192.168.2.1 ISP Router (made up gateway)

If DSL modem DOES have it's own IP address:

Box2 192.168.1.67 <--->192.168.1.1 router 192.168.3.1 <-->192.168.3.2 eth0 Box1  eth1 192.168.2.4 <-->192.168.2.1 (Private) DSL Modem (public) 1.1.1.1 <---> 1.1.1.2 (make up obv.)

In short, make sure each of your computers/routers can answer these questions, (using the numbers above):

(For routers and computers) What IP address do I use to send packets to an network that I do not explicitly know about?

(For routers) Are there network addresses behind other routers that I need to know about?  If so, what is the IP address of the router handling that network address?

Those two questions go a long way toward fixing your issue, though they wouldn't be sufficient if you had a more complicated network.

----------

## anton

hmm, how about trying to solve a more simple problem first...

I want to connect box1 and box2 via my router/switch.  Let's leave DSL out of the picture for now.

My router/switch has built in dhcp.  Box2 obtains an ip address from the router and can ping the router fine.  Box1 cannot do this.  Let's also assume that each box has only one eth card.  All I want to do is get box1 to be able to ping the router and to ping box2.  Since this will now be considered a true LAN, all ip addresses can be on the same network, i.e. 192.168.1.0\24.

Currently the router is 192.168.1.1 and box2 is 192.168.1.67 (via dhcp).  In theory when box1 starts up eth0, it should obtain 192.168.1.68 from the router.  This is not happening.  And the issue with ping only having 'some' of the requests reach the destination bothers me too.  I could understand if I was pinging a machine half-way aournd the world I would lose some packets, but not a machine that is 3-feet away.  Routers and switches are much smarter than this and do not drop packets like that, especially on a lan.  

I've done nothing different in setting up the network on box1 than I have on any other machine I have ever installed various flavors of linux on, just this time it is a big thorn in my side.  I think I will try a different nic and see if that resolves any issues.  Still doesn't account for why the built-in eth card won't do what it is supposed to either.

If it makes any difference at all, I am doing this on a sn41g2 shuttle system.  The right drivers are used for both the 3com (3c9xx) card and the built-in eth card (forcedeth).  I just am finding it wierd that both cards come up fine, either one can be used to connect my dsl modem to, but neither one will have anything to do with dhcp from the router, or even really talk to it for that matter.  Maybe my expectations are too high, but when I ping a machine on a lan I expect to see 

'icmp_seq=1 

 icmp_seq=2

 icmp_seq=3 

 icmp_seq=4 

 icmp_seq=5 

 ... 

 seq=n' 

 not 

'icmp_seq=1 

icmp_seq=7 

icmp_seq=22'

still mind boggled by my issue.

----------

