Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
/etc/conf.d/net and multiple interfaces
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
exazoid
n00b
n00b


Joined: 01 Nov 2002
Posts: 6

PostPosted: Sun Jan 05, 2003 1:08 am    Post subject: /etc/conf.d/net and multiple interfaces Reply with quote

Hi.

I have a setup with multiple interfaces (eth0..2) .

eth0 is dhcp controlled so it is set up correctly automaticly.

I have set static ip-addresses for both eth1 and eth2, but I am having trouble to figure out how to set the "gateway" variable in the end of /etc/conf.d/net, I tried (w/o success) :

gateway="eth1/192.168.0.1 eth2/192.168.1.1"

Any help is greatly appriciated ;)

Exazoid
Back to top
View user's profile Send private message
steveb
Advocate
Advocate


Joined: 18 Sep 2002
Posts: 4564

PostPosted: Sun Jan 05, 2003 1:44 am    Post subject: Reply with quote

why don't you add the stuff in /etc/conf.d/local.start:
Code:
route add default gw 192.168.0.1 dev eth1
route add default gw 192.168.1.1 dev eth2

or
Code:
route add 0.0.0.0 gw 192.168.0.1 dev eth1
route add 0.0.0.0 gw 192.168.1.1 dev eth2


cheers

SteveB
Back to top
View user's profile Send private message
klieber
Bodhisattva
Bodhisattva


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Sun Jan 05, 2003 1:37 pm    Post subject: Re: /etc/conf.d/net and multiple interfaces Reply with quote

exazoid wrote:
I am having trouble to figure out how to set the "gateway" variable in the end of /etc/conf.d/net, I tried (w/o success) :

gateway="eth1/192.168.0.1 eth2/192.168.1.1"


Code:
gateway="eth1/192.168.0.1"
gateway="eth2/192.168.1.1"


--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
exazoid
n00b
n00b


Joined: 01 Nov 2002
Posts: 6

PostPosted: Sun Jan 05, 2003 1:45 pm    Post subject: Re: /etc/conf.d/net and multiple interfaces Reply with quote

klieber wrote:
exazoid wrote:
I am having trouble to figure out how to set the "gateway" variable in the end of /etc/conf.d/net, I tried (w/o success) :

gateway="eth1/192.168.0.1 eth2/192.168.1.1"


Code:
gateway="eth1/192.168.0.1"
gateway="eth2/192.168.1.1"


--kurt


Doesn't they overwrite each other (ie. first line is killed...) ?
Back to top
View user's profile Send private message
klieber
Bodhisattva
Bodhisattva


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Sun Jan 05, 2003 2:04 pm    Post subject: Re: /etc/conf.d/net and multiple interfaces Reply with quote

exazoid wrote:
Doesn't they overwrite each other (ie. first line is killed...) ?

Not if you've followed the instructions in the install guide correctly and created separate init scripts for each of your interaces. (code listing 23.3)

--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
exazoid
n00b
n00b


Joined: 01 Nov 2002
Posts: 6

PostPosted: Sun Jan 05, 2003 2:10 pm    Post subject: Re: /etc/conf.d/net and multiple interfaces Reply with quote

klieber wrote:
exazoid wrote:
Doesn't they overwrite each other (ie. first line is killed...) ?

Not if you've followed the instructions in the install guide correctly and created separate init scripts for each of your interaces. (code listing 23.3)

--kurt


I mean, the file is sourced ( = parsed regular by bash) so two lines after each other must collide.

Anyways, the machine is not standing at my place, and guess who forgot to compile in XFS support while upgrading kernel :oops:
Back to top
View user's profile Send private message
klieber
Bodhisattva
Bodhisattva


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Sun Jan 05, 2003 2:13 pm    Post subject: Re: /etc/conf.d/net and multiple interfaces Reply with quote

exazoid wrote:
I mean, the file is sourced ( = parsed regular by bash) so two lines after each other must collide.

No, they don't. Not if you have separate init scripts for each ethernet interface. Read /etc/init.d/net.eth0 to see how this is done. Here's the relevant snippet:

Code:
        if [ -n "${gateway}" ] && [ "${gateway%/*}" = "${IFACE}" ]
        then
                ebegin "  Setting default gateway"
                /sbin/route add default gw ${gateway#*/} dev ${gateway%/*} \
                        netmask 0.0.0.0 metric 1 >/dev/null || {

                        local error=$?
                        ifconfig ${IFACE} down &>/dev/null
                        eend ${error} "Failed to bring ${IFACE} up"
                        stop
                        return ${error}
                }
                eend 0
        fi


--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
jukka
Apprentice
Apprentice


Joined: 06 Jun 2002
Posts: 249
Location: Zurich, Switzerland

PostPosted: Sun Jan 05, 2003 5:56 pm    Post subject: Re: /etc/conf.d/net and multiple interfaces Reply with quote

i think exazoid is right. let's see:
  • to get their config data, all /etc/init.d/net.* scripts source /etc/conf.d/net, don't they? if variable 'gateway' is set as you told, it is first assigned the value 'eth1/192.168.0.1', but this is subsequently overwritten with 'eth2/192.168.1.1'.
  • when /etc/init.d/net.eth1 is executed, the line
    Code:
    if [ -n "${gateway}" ] && [ "${gateway%/*}" = "${IFACE}" ]
    returns 1, so the route command is not executed, and no default gateway is set for eth1.
  • when /etc/init.d/net.eth2 is executed, both tests after the if clause return zero, so the default gateway is set.

btw, if i was wrong, why do you have to set the variables iface_ethN, dhcpcd_ethN, alias_ethN, broadcast_ethN and netmask_ethN for every ethernet interface N?

greetings, jukka
Back to top
View user's profile Send private message
klieber
Bodhisattva
Bodhisattva


Joined: 17 Apr 2002
Posts: 3657
Location: San Francisco, CA

PostPosted: Sun Jan 05, 2003 6:27 pm    Post subject: Reply with quote

Welp -- don't know without combing through the net init script. I do know, however, that that's what my net config file looks like on my firewall and it works for me.

--kurt
_________________
The problem with political jokes is that they get elected
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Mon Jan 06, 2003 4:16 pm    Post subject: Reply with quote

This thread covers the same problem. One solution is to have your gateway line as you had it at first:
Code:

gateway="eth1/192.168.0.1 eth2/192.168.1.1"

and modify net.ethX to add this snippet:
Code:

gateway=`echo $gateway|sed 's#.*\('${IFACE}'/[^ ]*\).*#\1#'`

before the line that says:
Code:

if [ -n "${gateway}" ] && [ "${gateway%/*}" = "${IFACE}" ]

Note: I haven't tried it out myself, so YMMV.
Back to top
View user's profile Send private message
relyt
Apprentice
Apprentice


Joined: 29 Aug 2002
Posts: 238
Location: Massachusetts

PostPosted: Mon Jan 06, 2003 5:12 pm    Post subject: Reply with quote

Isn't the "gateway" variable only for the default route? (ie: there's only one)
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Mon Jan 06, 2003 5:55 pm    Post subject: Reply with quote

There can be more than one "default" route though with the "Equal cost multipath" routing option enabled in the kernel.
relyt wrote:
Isn't the "gateway" variable only for the default route? (ie: there's only one)
Back to top
View user's profile Send private message
exazoid
n00b
n00b


Joined: 01 Nov 2002
Posts: 6

PostPosted: Mon Jan 06, 2003 6:23 pm    Post subject: Reply with quote

No, when you have multiple NICs with multiple connections out to the big cyberspace, you need a default route per connection AND a system default. To make sure the computer is answering through the right ip-number when processing requests.

In "plain ip", you write something like :
Code:

# setup table1
ip route add $GW1_NET dev $GW1_IF src $GW1_IP table $GW1_TABLE
ip route add default via $GW1_GATEWAY table $GW1_TABLE

# setup table2
ip route add $GW2_NET dev $GW2_IF src $GW2_IP table $GW2_TABLE
ip route add default via $GW2_GATEWAY table $GW2_TABLE

# add the two routes (may be redundant)
ip route add $GW1_NET dev $GW1_IF src $GW1_IP
ip route add $GW2_NET dev $GW2_IF src $GW2_IP

# add rules to let interfaces use right table
ip rule add from $GW1_IP table $GW1_TABLE
ip rule add from $GW2_IP table $GW2_TABLE

# add default gateway (ie. the one this systems uses)
ip route add default via $DFL_GATEWAY
# or if you want to loadbalance
#ip route add default equalize nexthop via $GW1_GATEWAY dev $GW1_IF nexthop via $GW2_GATEWAY dev $GW2_IF
Back to top
View user's profile Send private message
relyt
Apprentice
Apprentice


Joined: 29 Aug 2002
Posts: 238
Location: Massachusetts

PostPosted: Mon Jan 06, 2003 6:35 pm    Post subject: Reply with quote

exazoid wrote:
No, when you have multiple NICs with multiple connections out to the big cyberspace, you need a default route per connection AND a system default. To make sure the computer is answering through the right ip-number when processing requests.

Ah yes. I was referring to the system default. I thought that was all that "gateway" set.
Back to top
View user's profile Send private message
relyt
Apprentice
Apprentice


Joined: 29 Aug 2002
Posts: 238
Location: Massachusetts

PostPosted: Mon Jan 06, 2003 7:15 pm    Post subject: Reply with quote

Naan Yaar wrote:
There can be more than one "default" route though with the "Equal cost multipath" routing option enabled in the kernel.

I haven't played with this yet. Does it just allow you to assign a route to multiple devices? Or does it create a meta-device which balances between physical devices?
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Mon Jan 06, 2003 7:31 pm    Post subject: Reply with quote

AFAIK, you would assign multiple default routes to multiple interfaces. The kernel will do "load balancing" on an IP by IP basis.
relyt wrote:
...
I haven't played with this yet. Does it just allow you to assign a route to multiple devices? Or does it create a meta-device which balances between physical devices?
Back to top
View user's profile Send private message
exazoid
n00b
n00b


Joined: 01 Nov 2002
Posts: 6

PostPosted: Mon Jan 06, 2003 8:21 pm    Post subject: Reply with quote

The way the kernel does it actually depends a little on your setup. AFAIK, if you specify :

Code:
ip route add default nexthop via $ip1 dev $if1 nexthop via $ip2 dev $if2


Then it would be on IP-basis (ie. all requests to nn.nn.nn.nn wold go through the same route)

But if you do :

Code:
ip route add default equalize nexthop via $ip1 dev $if1 nexthop via $ip2 dev $if2


Then it will be on stream to stream basis meaning each UDP packet will be load balanced and each distinct TPC-stream will be loadbalanced (even to the same IP)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum