You are not logged in.

#1 2009-03-01 06:30:38

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

netcfg: if ethernet connect success, skip wireless. [SOLVED]

I've read a bunch of threads on netcfg, and I'm not finding the answer that I'm looking for. As the title tries to say, I want netcfg to attempt to connect to ethernet first. If it's successful, then skip the wireless profile. If it's not successful, then try wireless. The profiles are fine, I just need to know the setup. What simple thing am I missing?

Offline

#2 2009-03-01 08:07:42

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

That's what I'd like to see with netcfg too - it can't handle priorities apart from its own (internal) priority setting afaik. Since your ethernet connection usually is the fastest in comparison to the wireless ones, shouldn't it skip the wireless ones automatically?

Offline

#3 2009-03-01 09:05:44

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

netcfg is a dumb network connector. It just connects to things. It doesnt enforce any policies.

It is however flexible and reusable, and it would be trivial to implement a tool that does what you'd like.

Last edited by iphitus (2009-03-01 09:10:06)

Offline

#4 2009-03-01 09:45:33

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

I would love to see this abiility in netcfg2, because I often switch between ethernet with static ip and wireless with dhcp. That's why I'm using wicd right at the moment, which is really good, but I still like netcfg2 better.

Offline

#5 2009-03-01 10:41:59

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

You should be able to realize this sort of functionality with properly configured ifplugd.  You can use it do define actions that depend of the status of various network interfaces -- so basically you can set it to run netcfg to configure wifi interface when ethernet cable is not connected, and to disable wifi and configure ethernet connection when the ethernet cable is plugged in.

I don't use it with netcfg, I use a different script to connect to wifi networks, but it should work without problems.

Offline

#6 2009-03-01 15:22:30

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

Thanks for the responses. ifplugd looks pretty cool. I'll check it out. Thanks fwojciec.

I need to start learning more about networking. It's by far my greatest weakness in system configuration.

Offline

#7 2009-03-01 18:06:12

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

@skottish: Could you please show us, what you've done, as soon as you got this? I think I'll try it as well, but trust me, I'm a total dumb-ass in networking wink

Offline

#8 2009-03-06 21:24:27

Venator85
Member
From: Italy
Registered: 2007-10-18
Posts: 62

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

Hi, I came across this need as well and I patched netcfg like this: http://pastebin.com/f1c83c27c
Just apply the patch and modify /etc/rc.conf like this:

NETWORKS=(wired)
AUTO_NETWORKS=(auto-wireless wlan0)
...
DAEMONS=(... @net-profiles ...)

where 'wired' is your wired profile and wlan0 is your wifi card's interface.
Happy hacking wink

Offline

#9 2009-03-06 21:32:19

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

I had totally forgotten about this thread.

I initially marked the thread as solved because of fwojciec's post. It seemed that scripting around ifplug was a simple and elegant solution.

But, my last remaining braincell started to function. The person that has this computer only uses it at her work to connect through ethernet. The only time the machine connects through wireless is when it's with me, and that's only for upgrades and repairs. So basically I used netcfg to try both interfaces. One works and one fails.

[SOLVED]=hacked!

Offline

#10 2009-03-07 04:08:41

cwjiof
Member
From: Taichung, TW
Registered: 2008-01-27
Posts: 131

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

I found it's hard to use ifplugd with netcfg2. And Venator85's solution seems more applicable.

However, I'm wondering how to hack the ifplugd.

Offline

#11 2009-03-07 07:41:52

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

I can post my solution, but as I said I don't use netcfg, so it can't be copied verbatim.  Here is my custom version of ifplugd.action script (/etc/ifplugd/ifplugd.custom.action):

#!/bin/sh
#
# custom ifplugd.action script

#!/bin/sh
#
# custom ifplugd.action script

case "$2" in
  up)
    if [ -f /var/run/daemons/wpa_auto ]; then
      /etc/rc.d/wpa_auto stop
      ifconfig $1 up
      dhcpcd $1
    fi
  ;;
  down)
    if [ -f /var/run/dhcpcd-$1.pid ]; then
      dhcpcd -qx $1
      ifconfig $1 down
    fi
    if [ ! -f /var/run/daemons/wpa_auto ]; then
      /etc/rc.d/wpa_auto start
    else
      /etc/rc.d/wpa_auto reset
    fi
  ;;
  *)
    echo "Wrong arguments" > /dev/stderr
    exit 1
  ;;
esac  

exit 0

This is my ifplugd.conf:

NET_IFS="eth0"
ARGS="-fwI -u0 -d10 --run=/etc/ifplugd/ifplugd.custom.action"

I start the ifplugd daemon after the wifi networking script in rc.conf...

Now that I think about it, this might be an important difference between the script I use (wpa_auto) and netcfg -- wpa_auto doesn't fail if no wifi network is available, it simply waits in the background and monitors wifi environment until one of the networks defined in wpa_supplicant.conf becomes available to connect to it.  So the configuration with netcfg would have to be a bit more creative...

Offline

#12 2009-07-27 18:05:36

sgrenier
Member
From: Sherbrooke, Quebec, Canada
Registered: 2008-04-01
Posts: 2

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

@Venator85: Thanks for your solution. That's work perfectly here.
nice piece of hack.

Offline

#13 2009-10-21 11:21:01

aapzak
Member
Registered: 2007-04-13
Posts: 8

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

This solution isn't working perfect anymore. The kernel change in rfkill ruined this solution for me.

When I boot up my laptop with the hardware rfkill switch to 'no radio' (I have to do this @ work) wpa_auto won't start. And when wpa_auto isn't running, case $2 won't bring up eth0 for me.

I'm going to look into this but if anyone else has the right changes for the ifplugd action script, feel free to beat me to fixing this smile

Offline

#14 2009-10-21 13:19:02

aapzak
Member
Registered: 2007-04-13
Posts: 8

Re: netcfg: if ethernet connect success, skip wireless. [SOLVED]

OK, I just added some checks.

In my case wpa_auto isn't running when I startup with the hardware switch set to 'no radio'. So I extracted the ifconfig and dhcpcd from that check:

case "$2" in
    up)
        # Bring down wpa_auto daemon, if running
        if [ -f /var/run/daemons/wpa_auto ]; then
            /etc/rc.d/wpa_auto stop
        fi

        # Bring up $1, if down
        if [ "$IFPLUG_CURRENT" -ne "up" ]; then
            ifconfig $1 up
        fi

        # Trigger dhcpcd $1, if not already running
        if [ ! -f /var/run/dhcpcd-$1.pid ]; then
            dhcpcd $1
        fi
    ;;

Last edited by aapzak (2009-10-21 13:19:44)

Offline

Board footer

Powered by FluxBB