Debian – Linking Ethernet interfaces

debianethernetlinuxnetworking

I'm quite new to Linux networking.

I have a Debian PC with two Ethernet interfaces, one embedded on the motherboard and another on a PCI card. The first one, let say eth0 is connected to my router (which is connected to Inet). I want to "link" eth1 to eth0, in order to access my router (and Inet) when I plug a cable in eth1. The same way the eth0 cable is connected to one of my router's Ethernet ports.

The Debian PC should also be able to access Inet and LAN, and thus not simply behave as a "virtual link" between the cable plugged in eth0 (coming from my router) and the cable plugged in eth1 (going to another PC).

Is this achievable? How?

Best Answer

You can use a bridge interface. You can use brctl from bridge-utils to create a bridge interface. For example,

$ brctl addbr br0
$ brctl addif br0 eth0 eth1
$ brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.00004c9f0bd2       no              eth0
                                                        eth1

So after adding interfaces eth0 & eth1 into the bridge device br0 you're left with the following setup. You can use ifconfig to see it:

$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr BC:AE:AA:34:22:11  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
...

$ ifconfig eth1
eth1      Link encap:Ethernet  HWaddr BC:AE:AA:34:11:22  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
...

And the bridge device with the IP address:

$ ifconfig br0
br0       Link encap:Ethernet  HWaddr BC:AE:C5:11:22:33  
          inet addr:192.168.1.20  Bcast:192.168.1.255  Mask:255.255.255.0
...
Related Question