# [SOLVED] HOWTO add routes using /etc/conf.d/net

## bassvandijk

I would like to add the following routes using the /etc/conf.d/net file:

```
route add -net 84.29.178.0 netmask 255.255.255.0 gw 84.29.178.1

route add -net 84.29.179.0 netmask 255.255.255.0 gw 84.29.178.1
```

I tried the follwing:

/etc/conf.d/net

```
...

routes_eth1=( "84.29.178.0 netmask 255.255.255.0 gw 84.29.178.1"

                      "84.29.179.0 netmask 255.255.255.0 gw 84.29.178.1")

...
```

and

```
...

routes_eth1=( "84.29.178.0/24 gw 84.29.178.1"

                      "84.29.179.0/24 gw 84.29.178.1" )

...
```

and 

```
...

routes_eth1=( "84.29.178.0/24 via 84.29.178.1"

                      "84.29.179.0/24 via 84.29.178.1")

...
```

But none of them work  :Sad: 

If I specify:

```
...

routes_eth1=( "84.29.178.0 via 84.29.178.1"

                      "84.29.179.0 via 84.29.178.1")

...
```

It will add the routes. But those are obviously not the routes I want because I need all the adresses from 84.29.178.0 to 84.29.178.255 to be routed to 84.29.178.1.Last edited by bassvandijk on Tue Aug 30, 2005 12:16 pm; edited 1 time in total

----------

## Ph0eniX

 *bassvandijk wrote:*   

> I would like to add the following routes using the /etc/conf.d/net file:
> 
> ```
> route add -net 84.29.178.0 netmask 255.255.255.0 gw 84.29.178.1
> 
> ...

 

I'm not sure what the format for /etc/conf.d/net is but you can add

```

route add -net 84.29.178.0 netmask 255.255.254.0 gw 84.29.178.1

```

to /etc/conf.d/local.start ...note the 23 bit subnet (.254.0) which allows for both of your Class C (84.29.178.0/24 and 84.29.179.0/24)  ranges to be included on one line.

----------

## bassvandijk

 *Ph0eniX wrote:*   

> ...
> 
> I'm not sure what the format for /etc/conf.d/net is but you can add
> 
> ```
> ...

 

I know, but I would like to have my network settings in one place.

 *Ph0eniX wrote:*   

> ...
> 
> note the 23 bit subnet (.254.0) which allows for both of your Class C (84.29.178.0/24 and 84.29.179.0/24)  ranges to be included on one line.

 

Good tip, thanks!

----------

## Ph0eniX

I'd try this in your /etc/conf.d/net:

```

routes_eth1=( "84.29.178.0 netmask 255.255.254.0 via 84.29.178.1" )

```

----------

## bassvandijk

 *Ph0eniX wrote:*   

> I'd try this in your /etc/conf.d/net:
> 
> ```
> 
> routes_eth1=( "84.29.178.0 netmask 255.255.254.0 via 84.29.178.1" )
> ...

 

Unfortunately that didn't work.

This is my /etc/conf.d/net

```
# eth0 = LAN

# eth1 = Internet

config_eth0=("192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255")

config_eth1="dhcp"

dhcpcd_eth1="-R -h CP179741-A"

routes_eth1=( "84.29.178.0 netmask 255.255.254.0 via 84.29.178.1" )
```

```
pts/1 ~

[root@tooslow] route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

84.29.178.0     0.0.0.0         255.255.254.0   U     0      0        0 eth1

127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo

0.0.0.0         84.29.178.1     0.0.0.0         UG    0      0        0 eth1

pts/1 ~

[root@tooslow] /etc/init.d/net.eth1 restart

 * Caching service dependencies ...                                                                [ ok ]

 * Stopping eth1

 *   Bringing down eth1

 *     Stopping dhcpcd on eth1 ...                                                                 [ ok ]

 *     Shutting down eth1 ...                                                                      [ ok ]

 * Starting eth1

 *   Bringing up eth1

 *     dhcp

 *       Running dhcpcd ...                                                                        [ ok ]

 *       eth1 received address 84.29.179.201

 *   Adding routes

 *     84.29.178.0 netmask 255.255.254.0 gw 84.29.178.1 ...                                        [ !! ]

pts/1 ~

[root@tooslow] route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

84.29.178.0     0.0.0.0         255.255.254.0   U     0      0        0 eth1

127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo

0.0.0.0         84.29.178.1     0.0.0.0         UG    0      0        0 eth1
```

----------

## Ph0eniX

Wait, what exactly are you trying to accomplish? ...from your routing table it looks like 84.29.178.1 is already your default router so adding static routes for specific nets to it will have no effect.

----------

## bassvandijk

 *Ph0eniX wrote:*   

> Wait, what exactly are you trying to accomplish?...

 

I need to communicate (HTTP/FTP/Whatever) with a host that's on the same network as I am. My ISP (@Home) blockes all connections between hosts that are on the same @Home network (They say this is for security reasons, which I understand). If I route @Home destinated packages (84.29.178.0 netmask 255.255.254.0) to the @Home gateway (84.29.178.1) then they will reach their target.

If I manually add the routes using route it works, but I would like to do it using the /etc/conf.d/net file because then I have all my network settings in one place.

Note that deleting the following route will also work (I think):

```
84.29.178.0     0.0.0.0         255.255.254.0   U     0      0        0 eth1 
```

Because then @Home destinated packages will use the default route:

```
0.0.0.0         84.29.178.1     0.0.0.0         UG    0      0        0 eth1 
```

----------

## UberLord

I've just tested your config and it works with baselayout-1.12.0_pre6-r3

----------

## bassvandijk

 *UberLord wrote:*   

> I've just tested your config and it works with baselayout-1.12.0_pre6-r3

 

I just emerged the masked baselayout-1.12.0_pre6-r3 (and dhcpcd-2.0.0 because baselayout gives an error when using a lower version).

```
/etc/init.d/net.eth1 restart

 * Caching service dependencies ...                                                              [ ok ]

 * Stopping eth1

 *   Bringing down eth1

 *     Stopping dhcpcd on eth1 ...                                                               [ ok ]

 *     Shutting down eth1 ...                                                                    [ ok ]

 * Starting eth1

 *   Bringing up eth1

 *     dhcp

 *       Running dhcpcd ...                                                                      [ ok ]

 *       eth1 received address 84.29.179.201/23

 *   Adding routes

 *     84.29.178.0 netmask 255.255.254.0 via 84.29.178.1 ...

Error: either "to" is duplicate, or "netmask" is a garbage.
```

with this /etc/conf.d/net:

```
# eth0 = LAN

# eth1 = Internet

config_eth0=("192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255")

config_eth1="dhcp"

dhcpcd_eth1="-R -h CP179741-A"

routes_eth1=( "84.29.178.0 netmask 255.255.254.0 via 84.29.178.1" )
```

Could this be caused by the fact that there alreay are routes with gateway 84.29.178.1 or with destination 84.29.178.0?

route -n

```
Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

84.29.178.0     0.0.0.0         255.255.254.0   U     0      0        0 eth1

127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo

0.0.0.0         84.29.178.1     0.0.0.0         UG    0      0        0 eth1

```

----------

## bassvandijk

I just figured out (by looking at the net.lo source) that I need to specify it as:

```
routes_eth1=( "84.29.178.0/23 via 84.29.178.1" )
```

However, now my routing table is:

```
Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

84.29.178.0     0.0.0.0         255.255.254.0   U     0      0        0 eth1

84.29.178.0     84.29.178.1     255.255.254.0   UG    0      0        0 eth1

127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo

0.0.0.0         84.29.178.1     0.0.0.0         UG    0      0        0 eth1
```

I think this will give problems because the newly added route comes after this route:

```
84.29.178.0     0.0.0.0         255.255.254.0   U     0      0        0 eth1
```

So packages with destination 84.29.178.0/23 won't go via the gw but will be sent directly.

How do I get the route to be "above" this route, just like when I add them manuallly?

----------

## UberLord

baselayout-1.12.0_pre7 will allow net-tools route style commands (using the netmask bit) to work with iproute2 which fixes the bug.

As to the routing problem, I'm not too sure what a viable solution is as they would probably block at their end.

----------

## bassvandijk

I was thinking, 

who adds all those routes? Well obviously it's dhcpcd, so lets disable that by adding -G to dhcpcd:

man dhcpcd

```
...

-G [gateway]

Prevents  dhcpcd from installing default routes provided by DHCP server.  If optional gateway ip address parameter is supplied then use it for default route.

...
```

After restarting net.eth1, my routing table is:

```
Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

84.29.178.0     0.0.0.0         255.255.254.0   U     0      0        0 eth1

84.29.178.0     84.29.178.1     255.255.254.0   UG    0      0        0 eth1

127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
```

Well, the default route is gone but there's still this strange route 

```
84.29.178.0     0.0.0.0         255.255.254.0   U     0      0        0 eth1
```

Who is adding that route and how can I disable that?

BTW Thanks for all your replies so far  :Smile: 

----------

## UberLord

 *bassvandijk wrote:*   

> Well, the default route is gone but there's still this strange route 
> 
> ```
> 84.29.178.0     0.0.0.0         255.255.254.0   U     0      0        0 eth1
> ```
> ...

 

You can't - that's added by the kernel based on the netmask.

You could manually delete it in a postup() function though.

----------

## bassvandijk

 *UberLord wrote:*   

> ...You could manually delete it in a postup() function though.

 

Great tip! It works now with this /etc/conf.d/net:

```
# eth0 = LAN

# eth1 = Internet

config_eth0=("192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255")

config_eth1="dhcp"

dhcpcd_eth1="-R -h CP179741-A"

routes_eth1=( "84.29.178.0/23 via 84.29.178.1" )

postup()

{

        route del -net 84.29.178.0 netmask 255.255.254.0

        return 0

}
```

Thanks for all the help!

----------

## zomps

routes_eth0=(

"-net 192.168.0.0/24 via 192.168.1.1"

"-host 192.168.2.1 via 192.168.1.1"

)

----------

## dl7und

Thanks zomps! Your example finally put me on the right path.

----------

