# help with wireless[solved]

## tinnny

the problem:i can not get eth0 and wlan0 work together,when i add net.eth0 and net.wlan0 initscript to default run level,i can't ping through wlan0(pull out the network cable).But when i only add net.wan0 to default run level,I can ping(pull out  the network cable).

how can i get them work together?just like when the wireless network is disconnected,i can use the wired network.Also when the wired network is disconnected,i can use the wireless network.i don't want to restart my laptop or stop and start some initscript

i am not a native english speaker,there may be something wrong in expression,but i want replies.Thank you

/etc/conf.d/net

```
# 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 :]!).

dns_domain_lo="tinnny.org"

config_eth0="192.168.1.110 netmask 255.255.255.0 brd 192.168.1.255"

routes_eth0="default via 192.168.1.1"

dns_servers="202.102.152.3 202.102.154.3"

# wireless

modules="wpa_supplicant"

wpa_supplicant_wlan0="-Dwext"

config_wlan0="192.168.1.111 netmask 255.255.255.0 brd 192.168.1.255"

routes_wlan0="default via 192.168.1.1"

```

/etc/wpa_suppliant/wpa_suppliant.conf

```
ctrl_interface=/var/run/wpa_supplicant

ctrl_interface_group=wheel

ap_scan=1

update_config=0

network={

        ssid="NETWORK-1"

        key_mgmt=WPA-PSK

        psk="201009jwcs"

        priority=5

        scan_ssid=1

}

```

Last edited by tinnny on Mon Mar 12, 2012 3:34 pm; edited 1 time in total

----------

## Splink

So you want your wireless network to be the primary one and the eth0 to be the backup?

In networking, you cannot have 2 interfaces on the same subnet from the same machine/host accessing the same gateway to send/receive traffic, it has to be either one or the other while they are both online. 

The way I do this is add wlan0 to rc.d and then remove net.eth0 fully. If I have a problem with the wifi network then I start net.eth0 manually.

You may want to add additional configuration to your /etc/conf.d/net file to set the config for net.eth0 to have a value of "metric 2" at the end of your configuration line. 

If you do a ifconfig from your console, you will see all network intrerfaces as metric 1 by default. Lowering this metric setting, de-prioritises the interface. Maybe this may help you.

----------

## BillWho

Splink,

This is how I handle the two interfaces in /etc/conf.d/net.  

metric_wlan0="0"

metric_eth0="1"

sleep_scan_wlan0="6"

config_eth0="192.168.1.103/24 brd 192.168.1.255"

routes_eth0="default via 192.168.1.1"

#

modules="wpa_supplicant"

wpa_supplicant_wlan0="-Dwext -c/etc/wpa_supplicant/wpa_supplicant.conf"

wpa_timeout_wlan0=60

config_wlan0="192.168.1.103/24 brd 192.168.1.255"

routes_wlan0="default via 192.168.1.1"

#

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} == "wla0" ]; then

    if ethtool "${IFACE}" | grep -q 'Link detected: no'; then

      ewarn "No link detected on ${IFACE}"

      return 1

    fi

  fi

return 0

}

You'll have to emerge sys-apps/net-tools sys-apps/ethtool and sys-apps/ifplugd and set rc_depend_strict="NO" in /etc/rc.conf 

I gleaned this info from /usr/share/doc/openrc-0.9.9.3/net.example.bz2

Good luck    :Wink: 

----------

## Splink

 *BillWho wrote:*   

> Splink,
> 
> This is how I handle the two interfaces in /etc/conf.d/net.  
> 
> metric_wlan0="0"
> ...

 

Indeed do it that way  :Smile:  Thats what I do.. but wireless never fails on me at all, and I usually use eth0 to do management of switches  :Smile: 

----------

## tinnny

BillWho,

how do you deal with the initscript?add net.eth0 and net.waln0?

----------

## BillWho

tinnny,

symlink net.eth0 and net.wlan0 as so:

root@gentoo-ws490 init.d # ls -l net.*

lrwxrwxrwx 1 root root     6 Mar 26  2011 net.eth0 -> net.lo

-rwxr-xr-x 1 root root 16852 Mar 11 23:28 net.lo

lrwxrwxrwx 1 root root     6 Mar  2 00:22 net.wlan0 -> net.lo

Add net.eth0,  net.wlan0 to the default runlevel and net.lo to boot

root@gentoo-ws490 ssh # rc-update show|grep "net\."

             net.eth0 |      default                                  

               net.lo | boot                                          

            net.wlan0 |      default                                  

That should do it    :Wink: 

PS: Splink, sorry I meant to address my reply to tinnny - posted before I finished my first cup of coffee    :Sad: 

----------

## tinnny

i followed BillWho's idea,but i have no additional configuration in /etc/conf.d/net.But it really works,by reading the rc.log,i found maybe it's sys-apps/ifplugd that help me(you can see it by "man ifplugd").

i try to unmerge net-tools and ethtools.It's terrible.I had to use boot CD to repair it.Maybe when i get enough script knowledge,i can understand the preup(),

thanks for both of you

----------

## BillWho

tinnny,

You would have to add the preup function to /etc/conf.d net - it's called from net.lo. Also I have a typo in the function. The wireless lines should read:

Always save your original file in case there's a problem after you make modifications.

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

    if ethtool "${IFACE}" | grep -q 'Link detected: no'; then

      ewarn "No link detected on ${IFACE}"

      return 1

    fi

  fi

I've recently been working this...   :Sad: 

----------

## tinnny

BillWho，

Ok, I will try and give you some feedback,   :Smile:  but i really do not know ${IFACE} stand for,is it some variable defined in .bashrc? When I use your preup() method,I can not setup eth0 and wlan0.

/etc/conf.d/net

```
 1 # This blank configuration will automatically use DHCP for any net.*

 2 # scripts in /etc/init.d.  To create a more complete configuration,

 3 # please review /usr/share/doc/openrc*/net.example* and save your configuration

 4 # in /etc/conf.d/net (this file :]!).

 5 dns_domain_lo="tinnny.org"

 6 config_eth0="192.168.1.110 netmask 255.255.255.0 brd 192.168.1.255"

 7 routes_eth0="default via 192.168.1.1"

 8 dns_servers="202.102.152.3 202.102.154.3"

 9 metric_eth0="1"

10 # wireless

11 modules="wpa_supplicant"

12 wpa_supplicant_wlan0="-Dwext"

13 config_wlan0="192.168.1.111 netmask 255.255.255.0 brd 192.168.1.255"

14 routes_wlan0="default via 192.168.1.1"

15 metric_wlan0="0"

16 # 

17 preup()

18 

19 {

20 

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

22 if mii-tool "${IFACE}" 2> /dev/null | grep -q 'no link'; then

23 ewarn "No link detected on ${IFACE}"

24 return 1

25 fi

26 fi

27 

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

29 if ethtool "${IFACE}" | grep -q 'Link detected: no'; then

30 ewarn "No link detected on ${IFACE}"

31 return 1

32 fi

33 fi

34 return 0

35 }

```

rc.log

```
rc default logging started at Tue Mar 13 00:15:50 2012

* Starting D-BUS system messagebus ...

[ ok ]

* Bringing up interface eth0

*   Running preup ...

*     No link detected on eth0

* ERROR: net.eth0 failed to start

* Bringing up interface wlan0

*   Running preup ...

*     No link detected on wlan0

* ERROR: net.wlan0 failed to start

* Mounting network filesystems ...

[ ok ]

* Starting syslog-ng ...

[ ok ]

* Doing udev cleanups

* Starting vixie-cron ...

[ ok ]

* Starting local

[ ok ]

rc default logging stopped at Tue Mar 13 00:15:53 2012
```

Last edited by tinnny on Mon Mar 12, 2012 4:37 pm; edited 2 times in total

----------

## BillWho

tinnny,

${IFACE} will evaluate to eth0 and lo and wlan0 when called from net.lo. If you setup the symlinks to net.lo as illustrated in my previous post then the interfaces will be OK in preup.

If you installed the packages in the aforementioned post then you can test them as so:

gentoo ~ # mii-tool eth0

eth0: no link

gentoo ~ # ethtool wlan0

Settings for wlan0:

	Link detected: yes

As you can see I'm on wireless now. 

What happens in /etc/conf.d/net is if eth0 is detected then it will configure it otherwise it returns 1 which indicates that it should not be configured because there's no link i.e. the cable isn't plugged in. The same holds for wireless, if the dongle isn't detected then it won't be configured.

----------

## tinnny

and  i run mii-tool and ethtool wlan0 when i have a internet connection.

mii-tool eth0

```
SIOCGMIIREG on eth0 failed: Input/output error

SIOCGMIIREG on eth0 failed: Input/output error

eth0: negotiated 100baseTx-FD flow-control, link ok
```

ethtool wlan0

```
Settings for wlan0:

        Link detected: yes

```

----------

## BillWho

tinnny,

Maybe I'm missing something here with your intent concerning the two interfaces. Only one will be connected. With preup when I have the wireless active and no cable connected to the  ethernet card, eth0 doesn't get configured i.e. there's no IP address assigned. If you're trying to bring both up, I don't think that's possible - not even with bonding as far as I know.

eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

        ether 00:11:11:43:a7:71  txqueuelen 1000  (Ethernet)

        RX packets 0  bytes 0 (0.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 0  bytes 0 (0.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.1.103  netmask 255.255.255.0  broadcast 192.168.1.255

        inet6 fe80::5604:a6ff:fedd:66cf  prefixlen 64  scopeid 0x20<link>

        ether 54:04:a6:dd:66:cf  txqueuelen 1000  (Ethernet)

        RX packets 85477  bytes 26642780 (25.4 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 98151  bytes 12612515 (12.0 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I don't know what's causing the SIOCGMIIREG on eth0 failed: Input/output error.

----------

## BillWho

tinnny,

My apologies. I found another problem with the wireless section in /etc/conf.d/net. I changed it to check for the device rather than a link.  

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

     if ! echo $(lsusb | grep "Ralink" &> /dev/null);then

      ewarn "No wireless device detected on ${IFACE}"

      return 1

    fi

  fi

Sorry if this caused any inconvenience.   :Crying or Very sad: 

----------

## tinnny

BillWho,

i think there is no link on eth0 when net.eth0 start,why not start net.eth0 first and if it fails,then start net.waln0,but i can not write the scrip so far,meybe severval days later.thank you for letting me learn a lot  :Very Happy: 

----------

