# Linux Gateway

## stephenry

Hi Guys,

I'm a noob, trying desperately to get a gentoo box up and running. I am setting up a small home network, an XP box and a gentoo box -through which i wish to connect to the internet. Ideally, i would like set up my system so that my cable modem would connect to through eth0 (on my gentoo box), and having eth1 (on the same machine) connect to my local network (my xp box). I would also like to set up a DHCP server (on my gentoo machine) so that my internal IP addresses could automatically set  up, without me having to set them IP manually.

Over the last couple of days i've been trying to get iptables to work, and i only recently managed to do so. I used the command:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

and it seemed to work okay, (i also updated my ip_forward file to read 1).  I've been looking at how to install a DHCP server but i dont really know where i would find it in my system, also i'm supposed to have a DHCP.conf file in which to set it up, but i can't seem to find it.

Unfortunately, as you probably guessed, xp cannot see my network (complaining that the network connection is unconnected) and i'm really at a loss as what to do next. Could somebody please give me a hand, or at least point me to some information on the net that deals with this kind of stuff.

Just another question: when i use iptables, i believe the command says that i wish to set up a nat table on my system that masquerades everything going through eth0, how does my system know where the data is comming from in order for it to be sent to eth0? (is it something to do with the net.eth* files i had to setup during installation). 

Thanks for any help...

Steve,

----------

## slaisc

for this to be a somewhat complete guide I will start from the beginning..

Interface eth0 should be configured to the external ip address... the address that ISP gives you. Next you have to decide on a private IP range that will be used on the internal network. I like 10.0.0.x., so the IP address of eth1 should be for example 10.0.0.1 and netmask 255.255.255.0 default gateway should be configured to whatever IP your ISP gives you..

so /etc/conf.d/net should look like this: (replace the x's with apropriate numbers of course.. )

```

iface_eth0="x.x.x.x netmask x.x.x.x"

iface_eth1="10.0.0.1 netmask 255.255.255.0"

gateway="eth0/x.x.x.x"

```

remember to add net.eth0 and net.eth1 to runlevel default (initiay net.eth1 doesnt exist, you can just cp /etc/init.d/net.eth0 /etc/init.d/net.eth1)

next edit /etc/conf.d/iptables  and enable ip forwarding like this: 

```

ENABLE_FORWARDING_IPv4="yes" 

```

then do  iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE (you should start iptables before entering that command so that rules get saved on shutdown)

 and add iptables to default runlevel so that rules get restored on every boot 

now you need a dhcp server: 

```

emerge dhcp

```

define your private subnet /etc/dhcp/dhcpd.conf , also  insert your name servers there

```

ddns-update-style ad-hoc;

authoritative;

 

option domain-name-servers XXXX, XXXX;

 

  subnet 10.0.0.1  netmask 255.255.255.0{

  option routers 10.0.0.1;

  range 10.0.0.5 10.0.0.250;

}

 

```

and tell dhcp server on which interface to listen for requests in /etc/conf.d/dhcp

```

 IFACE="eth1"

```

add dhcp to default runlevel, and thats it !

Regarding your question, whell that has to do with your default route:  gateway="eth0/x.x.x.x"  data  to any address which doesnt match a specific entry in the routing table will be sent through eth0. Additionally, now, when you set up NAT, data coming from your internal network will appear as coming from your linux box..

----------

## stephenry

Hi slaisc,

thanks for the reply!

I tried what you said and i've ran into a few problems. My ISP assigns my IP address dynamically so i don't know what to enter in the line (in conf.d/net.eth1):

gateway="eth0/x.x.x.x"

also when i'm configuring my dhcpd.conf file, i don't know what to enter for option domain-name-servers xxxx; (for the reasons above)

I tried running the dhcpd server without the domain-name-server line but it returns an error saying that the line: subnet 10.0.0.1 netmask 255.255.255.0 has the wrong subnet number/mask combination.

I also noticed something strange, i assigned the name Tyran to my xp machine on my gentoo box. So far i haven't been able to establish a communication between them, but, the name now appears on it (i can even ping it! <1ms).

Thanks,

Steve.

----------

## slaisc

first of all, there should not be such a file /etc/conf.d/net.eth1  the network configuration file is /etc/conf.d/net, which contains lines for each interface. If you get an IP address from ISP through dhcp, then it should look like this:

```
iface_eth0="dhcp"

iface_eth1="10.0.0.1 netmask 255.255.255.0"

 
```

You can leave out the gateway line, as the dhcp client sets it up automatically. Also, you can find out your name servers by doing a cat /etc/resolv.conf, to see what addresses the dhcp client has acquired. 

Regarding dhcp config, sorry, I made a mistake... it should be 

```

subnet 10.0.0.0  netmask 255.255.255.0{ 

```

instead of 

```
subnet 10.0.0.1  netmask 255.255.255.0{ 
```

----------

## uzik

You can get a linux router package thats menu driven,

does those things, and boots from a single floppy here

http://www.freesco.org  It comes with a firewall

already setup. The only tweaking I had to do on mine was

forward the ports for directx so I could play Age of Empires

over the internet.

----------

## nero

 *Quote:*   

> I am setting up a small home network, an XP box and a gentoo box -through which i wish to connect to the internet. Ideally, i would like set up my system so that my cable modem would connect to through eth0 (on my gentoo box), and having eth1 (on the same machine) connect to my local network (my xp box).

 

Are you running a cable striaght from your gentoo box to your XP box? If so you would need to use a crossover cable to get it to work.

----------

## reaz82

 *nero wrote:*   

>  *Quote:*   I am setting up a small home network, an XP box and a gentoo box -through which i wish to connect to the internet. Ideally, i would like set up my system so that my cable modem would connect to through eth0 (on my gentoo box), and having eth1 (on the same machine) connect to my local network (my xp box). 
> 
> Are you running a cable striaght from your gentoo box to your XP box? If so you would need to use a crossover cable to get it to work.

 

i agree.. at home i have my pc running windows xp providing internet to my laptop which is connected via crossover cable to my second nic on my pc.. 

btw win xp isnt a security issue if it is behind a firewall so dont bite my head for using that as my gateway..  :Smile: 

----------

## hetman

is there a file which has all the clients currently assigned an ip from the dhcp server listed?

a lease file or something like that?

----------

