You want eth1 and eth2 on the same subnet so they should be on the same ethernet link: you should configure your linux box as a bridge between eth1 and eth2.
This will create a new network interface (named br0
below): the kernel will work as a switch bridging your eth1
and eth2
(at layer 2). The IP configuration will be done on br0
instead of eth1
and eth2
(based on the MAC addresses). It will not route between client1 eth1
and client2 eth2
.
eth1 eth2
[ IP ]<---------->[IP ]
[ Eth ]<->[Eth ]<->[Eth ]
Client1 bridge Client2
Routing is involved between the clients (br0
) and Internet eth0
based on the IP addresses:
br0 eth0
[ IP ]<->[IP ]<->[IP ]
[ Eth ]<->[Eth]<->[Eth ]
Client1 router to internet
From the commandline:
brctl addbr br0
brctl addif br0 eth1 eth2
ip link up br0
ip addr add br0 $ip/$netmask
Or in /etc/network/interfaces
:
iface br0 inet static
bridge_ports eth1 eth2
address ...
netmaks ...
broadcast ...