Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Networking & Security
  • Search

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

Having problems getting connected to the internet or running a server? Wondering about securing your box? Ask here.
Post Reply
Advanced search
16 posts • Page 1 of 1
Author
Message
bassvandijk
Guru
Guru
User avatar
Posts: 306
Joined: Fri Sep 13, 2002 9:22 pm
Location: Haps, Netherlands

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

  • Quote

Post by bassvandijk » Mon Aug 29, 2005 10:52 am

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

Code: Select all

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

Code: Select all

...
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

Code: Select all

...
routes_eth1=( "84.29.178.0/24 gw 84.29.178.1"
                      "84.29.179.0/24 gw 84.29.178.1" )
...
and

Code: Select all

...
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 :-(

If I specify:

Code: Select all

...
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.
Top
Ph0eniX
Guru
Guru
User avatar
Posts: 502
Joined: Fri Sep 24, 2004 8:59 pm
Location: New York, U.S.

Re: HOWTO add routes using /etc/conf.d/net

  • Quote

Post by Ph0eniX » Mon Aug 29, 2005 1:27 pm

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

Code: Select all

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

Code: Select all

...
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

Code: Select all

...
routes_eth1=( "84.29.178.0/24 gw 84.29.178.1"
                      "84.29.179.0/24 gw 84.29.178.1" )
...
and

Code: Select all

...
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 :-(

If I specify:

Code: Select all

...
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.
I'm not sure what the format for /etc/conf.d/net is but you can add

Code: Select all

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.
Top
bassvandijk
Guru
Guru
User avatar
Posts: 306
Joined: Fri Sep 13, 2002 9:22 pm
Location: Haps, Netherlands

Re: HOWTO add routes using /etc/conf.d/net

  • Quote

Post by bassvandijk » Mon Aug 29, 2005 1:36 pm

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

Code: Select all

route add -net 84.29.178.0 netmask 255.255.254.0 gw 84.29.178.1
to /etc/conf.d/local.star
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!
Top
Ph0eniX
Guru
Guru
User avatar
Posts: 502
Joined: Fri Sep 24, 2004 8:59 pm
Location: New York, U.S.

  • Quote

Post by Ph0eniX » Mon Aug 29, 2005 1:39 pm

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

Code: Select all


routes_eth1=( "84.29.178.0 netmask 255.255.254.0 via 84.29.178.1" )

Top
bassvandijk
Guru
Guru
User avatar
Posts: 306
Joined: Fri Sep 13, 2002 9:22 pm
Location: Haps, Netherlands

  • Quote

Post by bassvandijk » Mon Aug 29, 2005 2:51 pm

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

Code: Select all


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

Code: Select all

# 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" )

Code: Select all

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
Top
Ph0eniX
Guru
Guru
User avatar
Posts: 502
Joined: Fri Sep 24, 2004 8:59 pm
Location: New York, U.S.

  • Quote

Post by Ph0eniX » Mon Aug 29, 2005 2:56 pm

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.
Top
bassvandijk
Guru
Guru
User avatar
Posts: 306
Joined: Fri Sep 13, 2002 9:22 pm
Location: Haps, Netherlands

  • Quote

Post by bassvandijk » Mon Aug 29, 2005 3:25 pm

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):

Code: Select all

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:

Code: Select all

0.0.0.0         84.29.178.1     0.0.0.0         UG    0      0        0 eth1 
Top
UberLord
Retired Dev
Retired Dev
User avatar
Posts: 6838
Joined: Thu Sep 18, 2003 10:26 am
Location: Blighty
Contact:
Contact UberLord
Website

  • Quote

Post by UberLord » Tue Aug 30, 2005 7:14 am

I've just tested your config and it works with baselayout-1.12.0_pre6-r3
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Top
bassvandijk
Guru
Guru
User avatar
Posts: 306
Joined: Fri Sep 13, 2002 9:22 pm
Location: Haps, Netherlands

  • Quote

Post by bassvandijk » Tue Aug 30, 2005 10:28 am

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).

Code: Select all

/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:

Code: Select all

# 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

Code: Select all

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
Top
bassvandijk
Guru
Guru
User avatar
Posts: 306
Joined: Fri Sep 13, 2002 9:22 pm
Location: Haps, Netherlands

  • Quote

Post by bassvandijk » Tue Aug 30, 2005 10:43 am

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

Code: Select all

routes_eth1=( "84.29.178.0/23 via 84.29.178.1" )
However, now my routing table is:

Code: Select all

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:

Code: Select all

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?
Top
UberLord
Retired Dev
Retired Dev
User avatar
Posts: 6838
Joined: Thu Sep 18, 2003 10:26 am
Location: Blighty
Contact:
Contact UberLord
Website

  • Quote

Post by UberLord » Tue Aug 30, 2005 11:21 am

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.
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Top
bassvandijk
Guru
Guru
User avatar
Posts: 306
Joined: Fri Sep 13, 2002 9:22 pm
Location: Haps, Netherlands

  • Quote

Post by bassvandijk » Tue Aug 30, 2005 11:53 am

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

man dhcpcd

Code: Select all

...
-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:

Code: Select all

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

Code: Select all

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 :-)
Top
UberLord
Retired Dev
Retired Dev
User avatar
Posts: 6838
Joined: Thu Sep 18, 2003 10:26 am
Location: Blighty
Contact:
Contact UberLord
Website

  • Quote

Post by UberLord » Tue Aug 30, 2005 11:57 am

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

Code: Select all

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?
You can't - that's added by the kernel based on the netmask.
You could manually delete it in a postup() function though.
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Top
bassvandijk
Guru
Guru
User avatar
Posts: 306
Joined: Fri Sep 13, 2002 9:22 pm
Location: Haps, Netherlands

  • Quote

Post by bassvandijk » Tue Aug 30, 2005 12:15 pm

UberLord wrote:...You could manually delete it in a postup() function though.
Great tip! It works now with this /etc/conf.d/net:

Code: Select all

# 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!
Top
zomps
n00b
n00b
User avatar
Posts: 59
Joined: Wed Dec 08, 2004 7:35 pm

  • Quote

Post by zomps » Tue Aug 30, 2005 2:18 pm

routes_eth0=(
"-net 192.168.0.0/24 via 192.168.1.1"
"-host 192.168.2.1 via 192.168.1.1"
)
Top
dl7und
n00b
n00b
Posts: 13
Joined: Sat Nov 08, 2003 4:17 pm

  • Quote

Post by dl7und » Thu Dec 15, 2005 7:05 am

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

16 posts • Page 1 of 1

Return to “Networking & Security”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic