# dhcp IFACE's, iproute ... how ?

## Fenixoid

Ok, here's the situation:

i have a router with two NIC's, it's connected to a switch (16 ports). From the switch goes a lot of subnets, like 192.168.0.254 192.168.1.254 192.168.2.254 ... 192.168.16.254

i have a dcsp running. The etc/conf.d/net is this:

```
config_eth0=( "195.14.180.77 netmask 255.255.255.252 brd 195.14.180.79" )

routes_eth0= ( "default gw 195.14.180.78" )

config_eth1:0= ( "192.168.1.253 netmask 255.255.255.0 brd 192.168.1.255" )

config_eth1:2= ( "192.168.2.254 netmask 255.255.255.0 brd 192.168.2.255" )

config_eth1:3= ( "192.168.3.254 netmask 255.255.255.0 brd 192.168.3.255" )

...

config_eth1:16= ( "192.168.4.254 netmask 255.255.255.0 brd 192.168.4.255" )
```

How should /etc/conf.d/dhcp look like?

Maby like this:

```
IFACE="eth1 eth1:0 eth1:1 eth1:2 eth1:n3 eth1:4 eth1:5 eth1:6 eth1:7 eth1:8 eth1:9 eth1:10 eth1:11 eth1:12 eth1:13 eth1:14 eth1:15 eth1:16"
```

?

here's a picture, don't mind the language  :Wink: 

http://www.fenixoid.projektas.lt/planaz-huliganaz.jpg

----------

## UberLord

OK, the first thing you have to realise is that eth1:0 is still just eth1

The second thing you have to know is that iproute2 can assign many addresses without the need to create aliases where you need aliases when using ifconfig. What does this tell us? Forget about aliases! Here's how to do this in Gentoo.

```
config_eth0=(

  "195.14.180.77 netmask 255.255.255.252 brd 195.14.180.79"

  "192.168.1.253 netmask 255.255.255.0 brd 192.168.1.255"

  "192.168.2.254 netmask 255.255.255.0 brd 192.168.2.255"

  "192.168.3.254 netmask 255.255.255.0 brd 192.168.3.255"

  "192.168.4.254 netmask 255.255.255.0 brd 192.168.4.255"

)

routes_eth0= ( "default gw 195.14.180.78" )
```

Tada.

That works for baselayout-1.11

If you're using 1.12 then you can use bash expansion to make things easier

```
config_eth0=(

  "195.14.180.77 netmask 255.255.255.252 brd 195.14.180.79"

  "192.168.{1..16}.253/24"

)

routes_eth0= ( "default gw 195.14.180.78" )
```

By default I leave IFACE in conf.d/dhcp blank so it works out what interfaces it has to listen on.

But it does not work with aliases, as I explained earlier it's all just eth1

----------

## Fenixoid

Hmm... ok

/etc/conf.d/net looks like this:

```
config_eth0=( 

  "195.14.180.77 netmask 255.255.255.252 brd 195.14.180.79" 

  "192.168.1.253 netmask 255.255.255.0 brd 192.168.1.255" 

  "192.168.2.254 netmask 255.255.255.0 brd 192.168.2.255" 

  "192.168.3.254 netmask 255.255.255.0 brd 192.168.3.255" 

  "192.168.4.254 netmask 255.255.255.0 brd 192.168.4.255" 

  ...

  "192.168.16.254 netmask 255.255.255.0 brd 192.168.16.255" 

) 

routes_eth0= ( "default gw 195.14.180.78" )
```

/etc/conf.d/dhcp looks like this:

```
# /etc/conf.d/dhcp: config file for /etc/init.d/dhcp

# Configure which interface or interfaces to for dhcp to listen on

# list all interfaces space separated. If this is not specified then

# we listen on all interfaces.

IFACE=""
```

/etc/dhcp/dhcpd.conf looksl ike this

```
subnet 192.168.0.0 netmask 255.255.255.0 {

    option routers 192.168.0.254;

    option domain-name "balt.net"

    options domain-name-servers 195.14.176.14, 195.14.170.14, 195.14.162.14

    range 192.168.0.71 192.168.0.199;

    }

subnet 192.168.1.0 netmask 255.255.255.0 {

    option routers 192.168.1.253;

    option domain-name "balt.net"

    options domain-name-servers 195.14.176.14, 195.14.170.14, 195.14.162.14

    range 192.168.1.71 192.168.1.199;

    }

subnet 192.168.2.0 netmask 255.255.255.0 {

    option routers 192.168.2.254;

    option domain-name "balt.net"

    options domain-name-servers 195.14.176.14, 195.14.170.14, 195.14.162.14

    range 192.168.2.71 192.168.2.199;

    }

...

subnet 192.168.16.0 netmask 255.255.255.0 {

    option routers 192.168.16.254;

    option domain-name "balt.net"

    options domain-name-servers 195.14.176.14, 195.14.170.14, 195.14.162.14

    range 192.168.16.71 192.168.16.199;

    }
```

So.. hou should look iproutes2?

I need this:

http://www.fenixoid.projektas.lt/lan.jpg

----------

## UberLord

I don't think that diagram will work - the router would need to be the switch as well. But hopefully someone with more routing knowledge than me can say for sure  :Smile: 

----------

## pookey

it will work.

firstly, you could use a 255.255.0.0 subnet mask. 

Avoiding that, the router can route packets out the same interface they came in, so the setup will work just fine.

----------

## Fenixoid

 *pookey wrote:*   

> it will work.
> 
> firstly, you could use a 255.255.0.0 subnet mask. 
> 
> Avoiding that, the router can route packets out the same interface they came in, so the setup will work just fine.

 

that router - tis's just a simple computer, not a device.

But hou to (and where to) config iproutes? Or is it not really needed? i just fire the server, dhcp on it, plug the switch and it will magically work?

----------

