# Automatic Wired/Wireless

## rkfsm

OK - From what I have read in the forums, ifplugd won't switch off the wireless and start wired automagically (and vice versa) despite advertisements to the contrary.

So.. Is there a package that will do this?

RK

----------

## maxime1986

man ifplugd

```
-r | --run= EXEC

              Specify program to execute when link status changes (default: /etc/ifplugd/ifplugd.action)
```

By default ifplugd will not start wireless when you unplug wire ... but you can tweak it to do it.

----------

## Randy Andy

rkfsm

Depending on the DE you are using, networkmanager with the its frontend can do it for you.

But installation and configuration could be more complicated as you can imagine when reading this wiki.

http://en.gentoo-wiki.com/wiki/NetworkManager

But if you get it working, its great.

Andy.

----------

## tuber

ifplugd may not do it on its own, but you can use the preup()/postdown() functions in /etc/conf.d/net to achieve the desired functionality. I use the following with netplugd (though I would expect ifplugd should work fine):

```
preup() {

# bring down wireless interface if wired is available

        if [[ ${IFACE} == "eth0" ]]

        then

                /etc/init.d/net.wlan0 stop

        fi

        # Return 0 always

        return 0

}

postdown() {

# bring up wireless interface if wired is not available

        if [[ ${IFACE} == "eth0" ]]

        then

                /etc/init.d/net.wlan0 start

        fi

        # Return 0 always

        return 0

}
```

----------

## lmiphay

 *tuber wrote:*   

> ifplugd may not do it on its own, but you can use the preup()/postdown() functions in /etc/conf.d/net

 

I have been playing around with this, and this appears to do the job mostly for me (wired eth0/static IP/ifplugd, wireless wlan0/wpa_supplicant/DHCP):

```

...

modules_wlan0=( "wpa_supplicant" "!plug" )

preup() {

  if [ "${IFACE}" == "wlan0" ] ; then

    ifplugstatus --quiet eth0

    if [ $? -eq 2 ] ; then

      return 1

    fi

  elif [ "${IFACE}" == "eth0" ] ; then

    if [ -h /var/lib/init.d/started/net.wlan0 ] ; then

      /etc/init.d/net.wlan0 --quiet pause

    fi

  fi

  return 0

}

postdown() {

  if [ "${IFACE}" == "eth0" ] ; then

    ifplugstatus --quiet wlan0

    if [ $? -eq 2 ] ; then

      runlev=`/sbin/runlevel`

      # only start if init state is normal (not on reboot, switch to single user mode... etc)

      if [ "$runlev" == "N 3" ] ; then

        /etc/init.d/net.wlan0 --quiet start

      fi

    fi

  fi

  return 0

}

```

----------

## Ant P.

 *rkfsm wrote:*   

> So.. Is there a package that will do this?

 

Wicd will, though it's not particularly flexible; if you plug the wired connection in it'll break any existing wireless connection.

----------

