# [SOLVED] Setting up a router/NAT

## ipartola

Good time of day.

I have a machine that has eth0 connected to the internet and eth1 and eth2 looking into my LAN. 

eth1 and eth2 will have two laptops connected to them. Now on a regular router (e.g. a D-Link I used to have) all of the computers that I connected to it had the same gateway address. Is there any way to set that same idea up using two distinct network cards? Essentially I want to bind eth1 and eth2 into the same device if that is possible.

If this is not possible how do I go about setting up NAT for eth1 and eth2 separately?

Thanks.

IgorLast edited by ipartola on Sun Dec 04, 2005 10:32 pm; edited 1 time in total

----------

## rev138

You have each laptop plugged into its own NIC? Why?

It is possible to "bond" two NICs into one virtual device, but I don't see how that's going to help in your situation.

As far as setting up separate NAT'ing, it's entirely possible with iptables. The only experience I have with it personally is through shorewall, which is very easy to set up.

----------

## ipartola

The reason why I have two laptops plugged into their own NICs is because I don't have a router/switch other than the Gentoo machine with the three NICs.  :Sad: 

The idea of "bonding" the two NICs into one device is that the laptops will see the same gateway IP. This will make eth1 and eth2 exactly identical and it doesn't matter which I plug a laptop into, I'll still be able to ssh into 192.168.0.1. Also the two laptops would be on the same subnet so iTunes could work for sharing music.

Right now I have set up only eth1 for NAT and eth2 is down. To set up eth1 I followed the Gentoo router HOWTO on gentoo-wiki.org. Would I have to follow the same basic steps to set things up for eth2?

I took a look at shorewall and it seems like I could do the same thing it does with just iptables, but thanks for pointint it out.

Thanks,

Igor

----------

## rev138

 *ipartola wrote:*   

> The reason why I have two laptops plugged into their own NICs is because I don't have a router/switch other than the Gentoo machine with the three NICs. 

 

Eeeeew.

 *ipartola wrote:*   

> The idea of "bonding" the two NICs into one device is that the laptops will see the same gateway IP.

 

Not sure that it would work. Read up on "ifenslave".

 *ipartola wrote:*   

> I took a look at shorewall and it seems like I could do the same thing it does with just iptables, but thanks for pointint it out.

 

Yeah, shorewall is a front-end for iptables. You'll get the exact same results with either one. Shorewall's just a little friendlier.

----------

## magic919

Have a look at creating a bridge using your interfaces and then giving that an IP.  Sounds like what you are asking for.

----------

## ipartola

Okay so I did manage to get it to work thanks to your help.

For those interested this is how (setting up of the bridge was taken from http://gentoo-wiki.com/HOWTO_setup_a_gentoo_bridge):

First eth1 and eth2 are bridged into br0. Then you simply set up iptables as outlined in http://www.gentoo.org/doc/en/home-router-howto.xml but your WAN=eth0 and LAN=br0. I also did not enter the line that drops packets within the LAN: 

```

#this line will block communication between computers on the LAN

iptables -I FORWARD -i ${LAN} -d 192.168.0.0/255.255.0.0 -j DROP

```

The only config I had to modify was /etc/conf.d/net

```
config_eth0=( "dhcp" )

config_eth1=( "null" )

config_eth2=( "null" )

bridge_br0="eth1 eth2"

config_br0=( "192.168.0.1/24" )
```

Then i made the softlink for br0 and added it to the default runlevel:

```
ln -s /etc/init.d/net.lo /etc/init.d/net.br0

rc-update add net.br0 default

/etc/init.d/net.br0
```

DNSMasq was set up to work on br0. In /etc/dnsmasq.conf I just included

```
interface = br0
```

One problem I had was the cables. Unlike the standalone router boxes, PCI ethernet cards do not understand regular CAT 5 cables: you need to use crossover cables to connect two PCs together. For me it manifested itself in saying that the network cable wasn't plugged in on a Windows XP machine.

Thanks again everybody!

Igor

----------

