Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
same static ip for eth0 & wlan0, but only one in use
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
nomadicME
n00b
n00b


Joined: 24 Mar 2012
Posts: 46

PostPosted: Fri Jun 29, 2012 2:43 am    Post subject: same static ip for eth0 & wlan0, but only one in use Reply with quote

I'm switching over from being coddled by wicd to doing it manually via wpa_supplicant. :D

Everything is working more or less, but I just discovered an issue on one laptop that I don't have on another. I put the following lines in /etc/conf.d/net:

On the laptop that works just fine (on wlan0):
config_eth0="192.168.2.7 netmask 255.255.255.0 brd 192.168.2.255"
config_wlan0="192.168.2.7 netmask 255.255.255.0 brd 192.168.2.255"
routes_eth0="default via 192.168.2.11"
routes_wlan0="default via 192.168.2.11"

On the laptop that works just fine (on wlan0) after I issue the command "sudo ifconfig eth0 inet down":
config_eth0="192.168.2.3 netmask 255.255.255.0 brd 192.168.2.255"
config_wlan0="192.168.2.3 netmask 255.255.255.0 brd 192.168.2.255"
routes_eth0="default via 192.168.2.11"
routes_wlan0="default via 192.168.2.11"

I realize that both interfaces cannot have the same ip addresses at the same time. What I was hoping for was that only one interface would have that ip at a time. If an ethernet cable is plugged in I'd like eth0 to have the ip, if not wlan0. Maybe I just got away with being sloppy on the one system that worked. How should this be done? Thanks.
Back to top
View user's profile Send private message
BillWho
Veteran
Veteran


Joined: 03 Mar 2012
Posts: 1600
Location: US

PostPosted: Fri Jun 29, 2012 3:11 am    Post subject: Reply with quote

nomadicME,

This is how I did it. This is added to /etc/conf.d/net
Code:
###############################
# don't configure unplugged interfaces
################################
preup() {
  if [ ${IFACE} == "eth0" ]; then
    if mii-tool "${IFACE}" 2> /dev/null | grep -q 'no link'; then
       ewarn "No link detected on ${IFACE}"
       return 1
    fi
  fi

  if [ ${IFACE} == "wlan0" ]; then
     if ! echo $(lsusb | grep "Ralink" &> /dev/null);then
      ewarn "No wireless device detected on ${IFACE}"
      return 1
    fi
  fi
return 0
}


You'll need to install sys-apps/net-tools for mii-tool and change your wireless adapter accordingly

Good luck
_________________
Good luck :wink:

Since installing gentoo, my life has become one long emerge :)
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Fri Jun 29, 2012 11:47 am    Post subject: Reply with quote

nomadicME ...

'ifconfig' (which, btw, is depreciated in favour of 'ip') has no relation to /etc/conf.d/net ... you can of course use either to configure the interface, but the values in /etc/conf.d/net are used only by /etc/init.d/net.${IFACE}

BillWho ... if you test for the substitution being non-empty then there is no need to 'echo'

Code:
if [[ -z $(lsusb | grep "Ralink" &> /dev/null) ]]; then

Also, we might simply check if one or other interface is currently up (rather than focus on the link or driver) ... at least thats probably the approach I'd take (untested).

Code:
preup() {

if [[ ${IFACE} == "eth0" ]]; then
    if [[ -n $(awk '/started/' <(/etc/init.d/net.wlan0 status)) ]]; then
        /etc/init.d/net.wlan0 stop
    fi
fi

if [ ${IFACE} == "wlan0" ]; then
    if [[ -n $(awk '/started/' <(/etc/init.d/net.eth0 status)) ]]; then
        /etc/init.d/net.eth0 stop
    fi
fi

return 0

}

best ... khay

EDIT: a corrected/working preup is provided later in the thread


Last edited by khayyam on Sat Jun 30, 2012 1:43 am; edited 1 time in total
Back to top
View user's profile Send private message
BillWho
Veteran
Veteran


Joined: 03 Mar 2012
Posts: 1600
Location: US

PostPosted: Fri Jun 29, 2012 3:33 pm    Post subject: Reply with quote

Quote:
BillWho ... if you test for the substitution being non-empty then there is no need to 'echo'

Code:
if [[ -z $(lsusb | grep "Ralink" &> /dev/null) ]]; then

Thanks for pointing that out.

As for the second part, since it's a 'preup' function would there be a valid 'connection status' to check :?:

That's the reason I check to see if the wired connection has a link and wireless adapter is plugged in :?
_________________
Good luck :wink:

Since installing gentoo, my life has become one long emerge :)
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Fri Jun 29, 2012 4:24 pm    Post subject: Reply with quote

BillWho wrote:
As for the second part, since it's a 'preup' function would there be a valid 'connection status' to check?

Bill ... the preup is run for every ${IFACE} that's brought up, all the above does is bring down wlan0 if we bring up eth0 and visa-versa. So yes, there will be a 'status' if the other interface is running, if not then nothing happens (because it's an 'if' conditional).

Your test is fine, but the example I provided is more generic, as its not based on cards, drivers or having mii-tool .. the only factor is the (other) interface.

best ... khay

EDIT: bill, having taken a closer look, I see we are working on two different assumptions. My solution is as per the OP's request (having the same IP for different interfaces) and yours is based on having either a card or link related to that interface. So, two solutions for somewhat different tasks, but for the problem at hand yours might still arrive at two interfaces both with the same IP becuase it only tests for the presence of the card or a link on the interface. Sorry for any confusion ITR.
Back to top
View user's profile Send private message
BillWho
Veteran
Veteran


Joined: 03 Mar 2012
Posts: 1600
Location: US

PostPosted: Fri Jun 29, 2012 5:41 pm    Post subject: Reply with quote

khayyam,

Quote:
all the above does is bring down wlan0 if we bring up eth0 and visa-versa

OK, that light bulb above my head momentarily flickered and then illuminated brightly :D

Quote:
but for the problem at hand yours might still arrive at two interfaces both with the same IP becuase it only tests for the presence of the card or a link on the interface

Code:
eth0      Link encap:Ethernet  HWaddr 00:11:11:43:a7:71 
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:14 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:700 (700.0 B)  TX bytes:700 (700.0 B)

wlan0     Link encap:Ethernet  HWaddr 54:04:a6:dd:66:cf 
          inet addr:192.168.1.103  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::5604:a6ff:fedd:66cf/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:209 errors:0 dropped:0 overruns:0 frame:0
          TX packets:249 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:70258 (68.6 KiB)  TX bytes:51059 (49.8 KiB)

I just booted and as you can see eth0 was not assigned an ip address since it's on wireless. The return 1 indicates to net.lo that the ${IFACE} should be skipped.
Code:
gentoo ~ # awk '/started/' <(/etc/init.d/net.wlan0 status)
 * status: started
gentoo ~ # awk '/started/' <(/etc/init.d/net.eth0 status)
gentoo ~ #


I'm not trying to be argumentative here and, now that I had this epiphany, I intend to use your preup suggestion.

As far as the OP's objective is concerned, either method will yield the same results.

Thanks again :wink:
_________________
Good luck :wink:

Since installing gentoo, my life has become one long emerge :)
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Fri Jun 29, 2012 6:37 pm    Post subject: Reply with quote

BillWho wrote:
Quote:
all the above does is bring down wlan0 if we bring up eth0 and visa-versa

OK, that light bulb above my head momentarily flickered and then illuminated brightly

Billl ... hehe ... I wondered what that was.

BillWho wrote:
[...] I just booted and as you can see eth0 was not assigned an ip address since it's on wireless. The return 1 indicates to net.lo that the ${IFACE} should be skipped.

Yes, it exits with 'return 1', but what if both the Ralink card is inserted and the ethernet cable is connected, it would seem that both will then be true, and so both interfaces started and assinged the (same) IP. Both test conditions for ${IFACE} will be run seperately, as both interfaces are started (the preup will be run for each interface), so I would seem to me that this could infact happen.

BillWho wrote:
I'm not trying to be argumentative here and, now that I had this epiphany, I intend to use your preup suggestion.

Of course, me neither, I would generally assume that someone responds in good faith and not to prove something-or-other, so your good.

As for you "epiphany", well, epiph-away ... the only downside with I can see is that if you have both interfaces in a run level then the first will be started and stoped by the second, however having both interfaces run at boot would be counter to the "one IP for both interfaces" requirement so, thats not something I think can be worked arround.

best ... khay
Back to top
View user's profile Send private message
nomadicME
n00b
n00b


Joined: 24 Mar 2012
Posts: 46

PostPosted: Fri Jun 29, 2012 11:03 pm    Post subject: Reply with quote

khayyam wrote:
nomadicME ...

'ifconfig' (which, btw, is depreciated in favour of 'ip') has no relation to /etc/conf.d/net ... you can of course use either to configure the interface, but the values in /etc/conf.d/net are used only by /etc/init.d/net.${IFACE}

BillWho ... if you test for the substitution being non-empty then there is no need to 'echo'

Code:
if [[ -z $(lsusb | grep "Ralink" &> /dev/null) ]]; then

Also, we might simply check if one or other interface is currently up (rather than focus on the link or driver) ... at least thats probably the approach I'd take (untested).

Code:
preup() {

if [[ ${IFACE} == "eth0" ]]; then
    if [[ -n $(awk '/started/' <(/etc/init.d/net.wlan0 status)) ]]; then
        /etc/init.d/net.wlan0 stop
    fi
fi

if [ ${IFACE} == "wlan0" ]; then
    if [[ -n $(awk '/started/' <(/etc/init.d/net.eth0 status)) ]]; then
        /etc/init.d/net.wlan0 stop
    fi
fi

return 0

}

best ... khay


OK, so I tried to implement your suggestion in /etc/conf.d/net, but I keep getting the following errors when I restart /etc/init.d/net.wlan0:

/etc/init.d/../conf.d/net: command substitution: line 12: syntax error near unexpected token `('
/etc/init.d/../conf.d/net: command substitution: line 12: `awk '/started/' <(/etc/init.d/net.wlan0 status))'

and get two sets of errors on reboot:

/etc/init.d/../conf.d/net: command substitution: line 12: syntax error near unexpected token `('
/etc/init.d/../conf.d/net: command substitution: line 12: `awk '/started/' <(/etc/init.d/net.wlan0 status))'

/etc/init.d/../conf.d/net: command substitution: line 18: syntax error near unexpected token `('
/etc/init.d/../conf.d/net: command substitution: line 18: `awk '/started/' <(/etc/init.d/net.wlan0 status))'

I'm in the process of troubleshooting this, but if you have any suggestions I'm all ears. Thanks.

Here is what I put in /etc/conf.d/net:

Code:

preup() {

if [[ ${IFACE} == "eth0" ]]; then
    if [[ -n $(awk '/started/' <(/etc/init.d/net.wlan0 status)) ]]; then
        /etc/init.d/net.wlan0 stop
    fi
fi

if [[ ${IFACE} == "wlan0" ]]; then
  if [[ -n $(awk '/started/' <(/etc/init.d/net.eth0 status)) ]]; then
    /etc/init.d/net.wlan0 stop
  fi
fi

return 0

}
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Fri Jun 29, 2012 11:44 pm    Post subject: Reply with quote

nomadicME wrote:
OK, so I tried to implement your suggestion in /etc/conf.d/net, but I keep getting the following errors when I restart /etc/init.d/net.wlan0:

/etc/init.d/../conf.d/net: command substitution: line 12: syntax error near unexpected token `('
/etc/init.d/../conf.d/net: command substitution: line 12: `awk '/started/' <(/etc/init.d/net.wlan0 status))'

nomadicME ... oh, the joy that is bash:

Code:
% echo $SHELL
/bin/zsh
% if [[ -n $(awk '/started/' <(/etc/init.d/net.wlan0 status)) ]]; then echo 1 ; fi
1
% exec bash -l
$ if [[ -n $(awk '/started/' <(/etc/init.d/net.wlan0 status)) ]]; then echo 1 ; fi
1

So, it works but ,,, within the confines of /etc/conf.d/net it errors as the 'substitution' contains a redirection from a subshell and thats suddenly a no-no for some mysterious reason, so we have to replace the subshell/redirection with a pipe:

Code:
preup() {

if [[ ${IFACE} = "eth0" ]]; then
    if [[ -n $(/etc/init.d/net.wlan0 status | awk '$3 ~/started/') ]]; then
        /etc/init.d/net.wlan0 stop
    fi
fi

if [ ${IFACE} = "wlan0" ]; then
    if [[ -n $(/etc/init.d/net.eth0 status | awk '$3 ~/started/') ]]; then
        /etc/init.d/net.eth0 stop
    fi
fi

return 0

}

Why? ... no particular reason ... "can't put a redirection within a subsitution, unless its an interactive shell" or some other inconsistancy. So, the above should work as expected ... again, untested.

best ... khay

ps. there was also mistake in the first example which is now fixed.
Back to top
View user's profile Send private message
nomadicME
n00b
n00b


Joined: 24 Mar 2012
Posts: 46

PostPosted: Sat Jun 30, 2012 5:09 am    Post subject: Reply with quote

khay & BillWho,

Thanks again for the help. It has been a frustrating day.

I tried khay's revised preup function and got the same results I was getting with the solution that I found in the meantime. That is, if you stop either interface from starting during boot then it throws an error which leads to netmount, sshd, and apache2 not starting regardless of which interface you stop even if it is eth0 and it is disconnected (obviously not a satisfactory consequence). However, at the end of the boot sequence the interfaces are configured as desired. You also get the same result if you replace the init script stop statement (in the inner if) with return 1 as suggested by BillWho.

I can see the error during boot, but I cannot find the error in any of the log files to pass along. Any ideas on how to keep the rest of the boot process from being affected by one of the interfaces not starting?
Back to top
View user's profile Send private message
nomadicME
n00b
n00b


Joined: 24 Mar 2012
Posts: 46

PostPosted: Sat Jun 30, 2012 5:51 am    Post subject: Reply with quote

I realize my last post was not a lot to go on so here is the entire contents of /etc/conf.d/net:

Code:



# This blank configuration will automatically use DHCP for any net.*
# scripts in /etc/init.d.  To create a more complete configuration,
# please review /usr/share/doc/openrc/net.example and save your configuration
# in /etc/conf.d/net (this file :]!).

#modules="wpa_supplicant"

preup() {

if [[ ${IFACE} = "eth0" ]]; then
  if [[ -n $(/etc/init.d/net.wlan0 status | awk '$3 ~/started/') ]]; then
     /etc/init.d/net.wlan0 stop
  fi
fi

if [[ ${IFACE} = "wlan0" ]]; then
  if [[ -n $(/etc/init.d/net.eth0 status | awk '$3 ~/started/') ]]; then
     /etc/init.d/net.eth0 stop
  fi
fi

return 0

}


To get the log file I needed (/var/log/rc.log) I needed to enable openrc logging in /etc/rc.conf. Here is an excerpt, which shows what I was trying to describe in my previous post:

Code:

...

 * Bringing up interface eth0
 *   Running preup ...
 *     status: starting
 *   No configuration specified; defaulting to DHCP
 *   dhcp ...
 *     Running udhcpc ...
 *     start-stop-daemon: failed to start `/bin/busybox'
 [ !! ]
 [ !! ]
 * ERROR: net.eth0 failed to start
 * Starting mysql ...
 [ ok ]
 * ERROR: cannot start netmount as net.eth0 would not start
 * /run/postgresql: creating directory
 * /run/postgresql: correcting owner
 * Starting PostgreSQL ...
 [ ok ]
 * ERROR: cannot start sshd as net.eth0 would not start
 * ERROR: cannot start apache2 as net.eth0 would not start
...
Back to top
View user's profile Send private message
nomadicME
n00b
n00b


Joined: 24 Mar 2012
Posts: 46

PostPosted: Sat Jun 30, 2012 6:54 am    Post subject: Reply with quote

I found some info here:

http://en.gentoo-wiki.com/wiki/Wireless/Configuration

But apparently some things have changed, since when I add this preup fcn to /etc/conf.d/net:

Code:


preup() {
if [[ ${IFACE} == "wlan0" ]]; then
   if ifplugstatus | grep -q 'eth0: link beat detected'; then
      ewarn "Wired connection on eth0 detected, aborting configuration on ${IFACE}"
      return 1
   fi
fi
return 0
}



I get warnings instead of errors in the rc.conf log. (see below) Functionally this is not much different because netmount, sshd, apache2 never start even after trying to start it manually with sudo/etc/init.d/net.eth0 start. I get the response that it is already started, but sshd has not been started, nor netmount, nor apache2.

Code:


 * WARNING: netmount is scheduled to start when net.eth0 has started
 * /run/postgresql: creating directory
 * /run/postgresql: correcting owner
 * Starting PostgreSQL ...
 [ ok ]
 * WARNING: sshd is scheduled to start when net.eth0 has started
 * WARNING: apache2 is scheduled to start when net.eth0 has started



Being coddled is starting look much better. :D
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Sat Jun 30, 2012 1:25 pm    Post subject: Reply with quote

nomadicME wrote:
if you stop either interface from starting during boot then it throws an error which leads to netmount, sshd, and apache2 not starting regardless of which interface you stop even if it is eth0 and it is disconnected (obviously not a satisfactory consequence). However, at the end of the boot sequence the interfaces are configured as desired.

nomadicME ... of course if you have both interfaces set to start in the default run-level then the first will be stoped by the second, all the preup function does is de-activate one interface if the other is made active.

So, the question is: how to provide for both one interface de-activating the other and at the same time selecting one as sufficent ... essencially two conflicting propositions. To put it another way, there is no criteria for selecting one over the other, as either is sufficent, but none-the-less if one is active then it should have priority. I can't suggest a way to solve this as there is no (obvious) factor that would provide some means of prioritising one interface over another.

nomadicME wrote:
Code:
 * Bringing up interface eth0
 *   Running preup ...
 *     status: starting
 *   No configuration specified; defaulting to DHCP
 *   dhcp ...
 *     Running udhcpc ...
 *     start-stop-daemon: failed to start `/bin/busybox' [ !! ]
 * ERROR: net.eth0 failed to start
 * Starting mysql ... [ ok ]
 * ERROR: cannot start netmount as net.eth0 would not start
 * /run/postgresql: creating directory
 * /run/postgresql: correcting owner
 * Starting PostgreSQL ... [ ok ]
 * ERROR: cannot start sshd as net.eth0 would not start
 * ERROR: cannot start apache2 as net.eth0 would not start

This is unrelated to the preup function, the error is due to your not have a dhcp client (and openrc falls back to busybox's udhcpc, which it seems gentoo's busybox doesn't provide). Anyhow, in your first post static IP's were configured for the interfaces, so I can't understand why "No configuration specified" now appears.

I'd lost my initial, and more detailed, post due to the fact that firefox is braindead, so this is shorter than I might have wished ...

best ... khay
Back to top
View user's profile Send private message
nomadicME
n00b
n00b


Joined: 24 Mar 2012
Posts: 46

PostPosted: Sat Jun 30, 2012 1:46 pm    Post subject: Reply with quote

Maybe I put out too much information. Just tried to document all the steps that were tried. So the question at this point is why the gentoo wiki provides a solution to this exact problem:

http://en.gentoo-wiki.com/wiki/Wireless/Configuration

Under Useful scripts > Wireless + Ethernet connections (emerge ifplugd to get ifplugstatus)

However, when you deploy this solution netmount, sshd, and apache2 will not start despite the fact that the warnings (provided above) say that they will be started once net.eth0 is started which doesn't happen. Further, if wlan0 is up and running why is eth0 needed to run netmount, sshd, and apache2.


Last edited by nomadicME on Sat Jun 30, 2012 5:35 pm; edited 1 time in total
Back to top
View user's profile Send private message
BillWho
Veteran
Veteran


Joined: 03 Mar 2012
Posts: 1600
Location: US

PostPosted: Sat Jun 30, 2012 2:03 pm    Post subject: Reply with quote

nomadicME,

I'm not sure if you did this yet or not, but try setting rc_depend_strict="NO" in /etc/rc.conf

Good luck :wink:
_________________
Good luck :wink:

Since installing gentoo, my life has become one long emerge :)
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Sat Jun 30, 2012 2:47 pm    Post subject: Reply with quote

nomadicME wrote:
Maybe I put out too much information. Just tried to document all the steps that were tried. So the question at this point is why the gentoo wiki provides a solution to this exact problem:

nomadicME ... well, you didn't read it clearly "[i]f the wired ethernet device is controlled via ifplugd", from the /etc/conf.d/net you posted it's not. You need to provide openrc with the information on how a particular interface is to be managed:

Code:
modules_eth0="ifplugd"


nomadicME wrote:
However, when you deploy this solution netmount, sshd, and apache2 will not start despite the fact that the warnings (provided above) say that they will be started once net.eth0 is started which doesn't happen. Further, if wlan0 is up and running why is eth0 needed to run netmount, sshd, and apache2.

This is completely consistant with what openrc is informing you ... you haven't configured (or rather, changed the configuration) so now it defaults to dhcp which you don't have, so there is essencially no network. As for net.wlan0 being "up and running" it isn't, its simply "started" as there is no defined configuration given for handling wlan0 either (at least in the /etc/conf.d/net you've provided).

Take the following example:

Code:
rc_need_wlan0="iptables"
modules_wlan0="!plug wpa_supplicant dhcpcd"
wpa_supplicant_wlan0="-Dwext"
wpa_timeout_wlan0="15"
config_wlan0="dhcp"
dhcp_wlan0="release nontp nonis nosendhost nodns"
dhcpcd_wlan0="-t 10 -h myhostname -I myhostname"
dns_servers_wlan0="127.0.0.1"
enable_ipv6_wlan0="false"

wlan0 "needs" iptables to be running, it is not to be configured via "plug" ("netplugd", or "ifplugd"), it is managed by wpa_supplicant, wpa_supplicant is passed "-Dwext" as parameters, wpa_supplicant will have a "timeout" of 15 seconds, the network is configured via DHCP (in this cased "dhcpcd" ... as per "modules_wlan0="), dhcp is to "release" the lease and not request "ntp, nis, and dns" and it shouldn't send the "hostname", dhcpcd has a timeout of 10 seconds, and should provide the hostname "myhostname", the dns_server is 127.0.0.1 (localhost), and finally, don't run ipv6 on this interface.

So, openrc is provided with everything needed to configure the interface as required, if none of the above exists it will try to configure the interface via DHCP (the default), but to do this it needs a dhcp client (such as dhcpcd).

The configuration also contains 'preup' 'postup' and 'postdown' functions, eg:

Code:
postup() {

if [[ ${IFACE} != "lo" ]] ; then
    if [[ -z $(/usr/bin/mailq | awk '$4 ~/empty/') ]] ; then
        TIMEOUT="10"
        while [[ ${TIMEOUT} -gt 0 && -z "$(ip route show 0.0.0.0/0)" ]] ; do
            let TIMEOUT=${TIMEOUT}-1 ; sleep 1
        done

        if [[ ${TIMEOUT} -eq 0 ]] ; then
            echo "" | mail -s "Mail flush deferred: $(date)" postmaster
            return 1
        else
            /usr/sbin/postfix flush
        fi
    fi       
fi

return 0

}

Here, any mail that was held in the mail que is flushed as and when an interface is brought online ...

Its all very staightforward, once you understand that its not psychic ... it will try and bring the interface up regardless of it being configured but this may not always work, or provide what you need.

best ... khay
Back to top
View user's profile Send private message
nomadicME
n00b
n00b


Joined: 24 Mar 2012
Posts: 46

PostPosted: Sat Jun 30, 2012 3:04 pm    Post subject: Reply with quote

It is finally working the way I wanted (on boot anyway). All of my troubles yesterday can be attributed to that damn rc_depend_strict option in /etc/rc.conf. Thanks BillWho. For anyone else who goes down this path make sure that this option is set to rc_depend_strict="NO"

So ultimately what I ended up with in my /etc/conf.d/net was this:

Code:

# This blank configuration will automatically use DHCP for any net.*
# scripts in /etc/init.d.  To create a more complete configuration,
# please review /usr/share/doc/openrc/net.example and save your configuration
# in /etc/conf.d/net (this file :]!).

#modules="wpa_supplicant"

preup() {

if [[ ${IFACE} == "eth0" ]]; then
        if ifplugstatus | grep -q 'eth0: unplugged'; then
                ewarn "Wired connection on eth0 not detected, aborting configuration on ${IFACE}"
                return 1
        fi
fi

if [[ ${IFACE} == "wlan0" ]]; then
        if ifplugstatus | grep -q 'eth0: link beat detected'; then
                ewarn "Wired connection on eth0 detected, aborting configuration on ${IFACE}"
                return 1
        fi
fi
return 0
}

config_eth0="192.168.2.7 netmask 255.255.255.0 brd 192.168.2.255"
config_wlan0="192.168.2.7 netmask 255.255.255.0 brd 192.168.2.255"
routes_eth0="default via 192.168.2.11"
routes_wlan0="default via 192.168.2.11"


Though I suppose many of the other configurations previously posted in this thread would have worked just as well if rc_depend_strict was set properly. Well I learned some things. Chief among them, read your config files! :D

Next up, swapping interfaces as ethernet cable is plugged in or removed. After a break for few days. :D
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Sat Jun 30, 2012 4:09 pm    Post subject: Reply with quote

nomadicME wrote:
Though I suppose many of the other configurations previously posted in this thread would have worked just as well if rc_depend_strict was set properly.

nomadicME ... no, that's not the case with the example I provided, to reiterate: "all the preup function does is de-activate one interface if the other is made active" ... (I think this is the third or fourth time I've now said this).

nomadicME wrote:
Well I learned some things. Chief among them, read your config files!

Well, if that were only true of reading the responces in this thread, I get the impression you've skimmed most of it ...

nomadicME wrote:
Next up, swapping interfaces as ethernet cable is plugged in or removed.

Which is exactly what the ifplugd.action example provided in the wiki does, and had you read "[i]f the wired ethernet device is controlled via ifplugd" and my subsequent explanation on how to do this, you would understand this. You would also understand how your "solution" is a one-time deal, whereas ifplugd can be configured to manage the interfaces dynamically.

best ... khay
Back to top
View user's profile Send private message
nomadicME
n00b
n00b


Joined: 24 Mar 2012
Posts: 46

PostPosted: Sat Jun 30, 2012 5:31 pm    Post subject: Reply with quote

khay,

You can rant and rave all you want, but the proof is in the results. Everything works now. I tried many of your suggestions verbatim and none of them worked. They all caused errors starting netmount, sshd, and apache2. It wasn't until BillWho suggested I set rc_depend_strict="NO" in /etc/rc.conf that I was able to get past these problems. If you read the comments for this config option you will see that none off the other proposed solutions would have worked until this configuration option was changed.

I have not begun to tackle the dynamic aspect of this problem (pluging and unplugging the ethernet cable) as I said that will come in a couple of days. The first step was getting the configuration to work on boot with the cable plugged in and with the cable unplugged. WE HAVE A SOLUTION. Let it rest. You helped me learn along the way, but ultimately BillWho provided the critical piece of the puzzle.

I wasn't going to say anything, but since you decided to make this a flame war. You need to come down off your high horse. You don't know everything, and you certainly didn't solve this problem.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Sat Jun 30, 2012 7:16 pm    Post subject: Reply with quote

nomadicME wrote:
You can rant and rave all you want, but the proof is in the results. Everything works now. I tried many of your suggestions verbatim and none of them worked. They all caused errors starting netmount, sshd, and apache2. It wasn't until BillWho suggested I set rc_depend_strict="NO" in /etc/rc.conf that I was able to get past these problems. If you read the comments for this config option you will see that none off the other proposed solutions would have worked until this configuration option was changed.

nomadicME ... yes "ranting and raving", that's exactly my MO, and how fabulously broken we're all my "suggestions", and good job BillWho came along and set the whole problem straight. But really, how fancifull ... and more of your failing to read, or reading selectively. I "rant and rave" because your idea of "solving" misses the problem, you accept a "solution" without having really understood, and worse, fail to read and consider the information you were presented with.

As for my "examples", I'll quote what I initally wrote (as you probably missed it entirely) "[..] we might simply check if one or other interface is currently up (rather than focus on the link or driver) ... at least thats probably the approach I'd take (untested)". So, given the problem "that's the approach I take (untested)", so nothing like "this is what you need to do", and note, I'm responding to Bill, I wasn't addressing you or YOUR problem. I even made it clear that "[...] the only downside I can see is that if you have both interfaces in a run level then the first will be started and stoped by the second [...]" so I'm quite aware that you its not simply a matter of copy-pasting it into a file and away-you-go, again "all the preup function does is de-activate one interface if the other is made active". All this is pretty clear, and unambigious.

nomadicME wrote:
I have not begun to tackle the dynamic aspect of this problem (pluging and unplugging the ethernet cable) as I said that will come in a couple of days. The first step was getting the configuration to work on boot with the cable plugged in and with the cable unplugged. WE HAVE A SOLUTION. Let it rest. You helped me learn along the way, but ultimately BillWho provided the critical piece of the puzzle.

OK, let me know when in a couple of days it suddenly dawns on you that "ahh, yes, I can just have ifpluged manage them, and not need a preup, thats probably what that khay was ranting and raving about", actually no need, I already know .... and yes, yes, Bill is absolutely critical in all this, but I quite imagine that like me he simply doesn't care to be used as a tool in your little "who did the best job" distraction. We're not here to win points or prove anything, so your just showing yourself in a bad light to have reduced both our efforts (however feeble) to such comparisons.

nomadicME wrote:
I wasn't going to say anything, but since you decided to make this a flame war. You need to come down off your high horse. You don't know everything, and you certainly didn't solve this problem.

No, a "flame war" is when you attack someone for no apparent reason, my pointing out that you failed to read or take cognisance of what was said is "fact", and my pointing it out to you is simply being honest.

Now, if you want to provide me with advice about what I should do, and bandy arround "high horses", "you don't know everything", "you didn't solve this problem" and other such slippery nonsense then that will only rub me the wrong way. I provided my time to answer any question you directed at me, I also provided the solution to your "mounting sshfs via fstab", I can quite easily not respond to you in any further way .. and this would be your loss not mine.

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