# Problem with using two onboard NICs

## nowitzness

Hi everyone,

I ran into a very annoying problem with my Gentoo machine which caused me to register  :Smile: 

(I tried the search engine to solve the problem before, but without luck)

I got two onboard network interfaces on my DFI Lanparty NF4 SLI DR mainboard, using a Vitesse VSC8201 Gigabit Phy and and a Marvell 88E8001 Gigabit PCI chipset. I got both interfaces working by compiling the forcedeth and the skge driver into the kernel. OK, so far so good.

My /etc/conf.d/net contains the following lines:

```
config_eth0=( "192.168.1.2 netmask 255.255.255.0 brd 192.168.1.255" )

routes_eth0=( "default gw 192.168.1.1" )

config_eth1=( "192.168.1.4 netmask 255.255.255.0 brd 192.168.1.255" )

routes_eth1=( "default gw 192.168.1.1" )
```

after booting, ifconfig says:

```
eth0      Link encap:Ethernet  HWaddr 00:01:29:D2:F1:7D  

          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0

          inet6 addr: fe80::201:29ff:fed2:f17d/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000 

          RX bytes:33588 (32.8 Kb)  TX bytes:32100 (31.3 Kb)

          Interrupt:18 

eth1      Link encap:Ethernet  HWaddr 00:01:29:D2:F4:BB  

          inet addr:192.168.1.4  Bcast:192.168.1.255  Mask:255.255.255.0

          inet6 addr: fe80::201:29ff:fed2:f4bb/64 Scope:Link

          UP BROADCAST MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000 

          RX bytes:120 (120.0 b)  TX bytes:552 (552.0 b)

          Interrupt:23 Base address:0x2000 
```

As the handbook suggests, I created a symlink to net.eth0 by running

```
ln -s net.lo net.eth1
```

I added both initscripts into the default runlevel by typing

```
rc-update add net.eth0 default

rc-update add net.eth1 default
```

If my network cable is plugged into eth0, pinging another computer on my LAN works perfectly:

```
PING 192.168.1.3 (192.168.1.3) 56(84) bytes of data.

64 bytes from 192.168.1.3: icmp_seq=1 ttl=128 time=0.123 ms

--- 192.168.1.3 ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2000ms

rtt min/avg/max/mdev = 0.123/0.143/0.155/0.020 ms
```

But if my network cable is plugged into eth1, I somehow cannot ping that computer:

```
PING 192.168.1.3 (192.168.1.3) 56(84) bytes of data.

From 192.168.1.2 icmp_seq=1 Destination Host Unreachable

--- 192.168.1.3 ping statistics ---

1 packets transmitted, 0 received, 100% packet loss, time 0ms
```

When I run

```
ifconfig eth0 down
```

 and the cable is still connected to eth1, eth1 works fine. 

Can somebody please post a solution to get BOTH working at the same time no matter in what interface the cable is plugged to?

----------

## NeddySeagoon

nowitzness,

Welcome to Gentoo.

I'm not sure where to start.

First, you may not have two interfaces in the same subnet which is what your net file sets up. You don't post your 

```
route
```

output but it will help with understanding your issue.

What are you trying to achieve with your network setup?

Perhaps if we work to solving your problem, rather than fixing your symptoms we shall have a better outcome.

----------

## wynn

The problem is that both interfaces are on the same subnet, 192.168.1.0, and routing will choose one to send packets to this subnet and ignore the other entirely. It is choosing eth0 and eth1 might as well not be there.

----------

## nowitzness

First off, thanks for the help, guys.

 *NeddySeagoon wrote:*   

> You don't post your route output but it will help with understanding your issue.
> 
> 

 

The output is:

```
Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     *               255.255.255.0   U     0      0        0 eth0

192.168.1.0     *               255.255.255.0   U     0      0        0 eth1

loopback        *               255.0.0.0       U     0      0        0 lo

default         mygateway1.ar7  0.0.0.0         UG    0      0        0 eth0

default         mygateway1.ar7  0.0.0.0         UG    1      0        0 eth1
```

 *Quote:*   

> What are you trying to achieve with your network setup?

 

Nothing special, actually. If have a small LAN consisting of three computers connected to the internet via a d-link router. As said, my computer has two network interfaces. But only one works (can access the internet and other computers on the LAN) if eth0 and eth1 are running. But I want to be able to use both interfaces. 

 *Quote:*   

> The problem is that both interfaces are on the same subnet, 192.168.1.0, and routing will choose one to send packets to this subnet and ignore the other entirely. It is choosing eth0 and eth1 might as well not be there.

 

Ok, but what can I do now to fix the problem?  :Surprised: 

The annoying thing is that I can switch cables to use any of both interfaces for networking at any time under windows, i just want to do that under linux, too.

----------

## NeddySeagoon

nowitzness,

You need to use DHCP to automatically configure your interfaces and ifplug (or similar) to bring the interfaces up and down as your move the network cable around. Then you can make it work like Windows.

However, Linux isn't Windows so its a bad habit to get into, wanting everything to work like windows.

You will find Linux doesn't fail like windows and nobody will want to help you make it do so either.

When your networking works, you will only have one set of entries in route. As you have posted, only eth0 can be used.

----------

## nowitzness

 *Quote:*   

> You need to use DHCP to automatically configure your interfaces and ifplug (or similar) to bring the interfaces up and down as your move the network cable around. Then you can make it work like Windows. 

 

aaaaaaaaah, ok! i think that will solve the problem, I'll try it later. Thanks for the help.

----------

## LinuxLoader

The other way is to bridge the 2 NIC .. at /etc/conf.d/net.example you may see how it can be made.

----------

## Kingmilo

You still haven't really told us what you plan to do with 2 network cards but this is my suggestion;

Use eth0 to access the internet

Use eth1 to access your LAN

As mentioned above you can setup a bridge but from what i read that isin't really what you are looking for.

So leave the network cards as is, the only change you will need to make is to remove the default gateway

for eth1 in /etc/conf.d/net

That way your machine will know that if it wants to access the internet it must use eth0, and if it wants to

access the LAN it can use eth1, if they are on a different subnet of course.

for example i have 2 network cards as follows;

Eth0 --> 192.168.0.2

GW --> 192.168.0.1

(This NIC cant interact with my LAN but it does all the Internet work)

Eth1 --> 10.0.0.5

(And the rest of my LAN is on the same subnet, so Eth1 does all the work on my LAN)

Let me know if this helps or if you don't follow.  :Wink: 

----------

## Macindy

I am working yesterday on the exactly same problematic:

I have 2 nics - one public with its gateway and one on the service-lan for internal purpose.

I haven't to setup any route for 192.168.0.0/24 (which is service-lan) - if somebody whats anything out of 192.168.0.0/24 it will take eth1 automaticly?

----------

## NeddySeagoon

Macindy,

Yes - but there will be no way for other PCs to reach the internet unless you set up the one with the two NICs as a router. See the Gentoo Home Router Guide.

----------

## Cyker

You can if you use Bridging.

I got it working on this box when I upgraded the mobo and it's cool - One port goes to the router which also has the WiFi stuff plugged into; The other goes to the LAN on a gigabit switch (Used to just be my workstation via a standard non-crossover CAT5e cable  :Smile: ).

The server only has ONE address for both cards - it just sees the bridge as br0 - and I even got IPTABLES working on it  :Smile: 

It's smart enough to figure out which port to use too: Even if I swap the cables around, it re-learns who's on what interface automatically and routes things in/out the right real eth? accordingly. It even has that Spanning Tree thing we learned about in 1st year CS to stop loops forming  :Razz: 

It's much better than routing if you want to have a LAN with an untrusted part to it (i.e. the Router+WiFi side in mine), because you don't need to have two subnets and the configuration of everything is a lot easier.

----------

## NeddySeagoon

Cyker,

Well caught. 

I have always found that setting up several subnets is conceptually easier.

You also have move confidence in your firewall, since you don't have the same IP everywhere.

I'm still not sure I understand how routing works on a firewall between two ends of a bridge.

----------

