Some background: sometimes my wi-fi connection suddenly goes down so I type sudo ifconfig wlan0 and check for the word RUNNING. The corresponding line looks like:


When the connection goes down there's no RUNNING setting; I can't connect to anything but the interface is still up.

I'm thinking of writing a script to periodically check for the RUNNING state. To extract that string, using awk would be something like: sudo ifconfig wlan0 | awk '/RUNNING/ {print $3}'.

Is there another way such as checking the filesystem instead of parsing ifconfig's output?

I'm using Debian Wheezy.


More information:

OK, just did some research and cleared up some conceptual confusion.

The UP and RUNNING flags are different. The first means the interface "is currently initialized" [1], i.e. "the system allocated the resources for the interface" [2]--it doesn't say anything about packet transmission.

The RUNNING flag actually indicates that packets are being sent and received. Apparently this flag disappears if e.g. the ethernet cable is unplugged.

[1] https://docs.oracle.com/cd/E19253-01/816-4554/ipconfig-141/index.html

[2] https://stackoverflow.com/questions/11679514/what-is-the-difference-between-iff-up-and-iff-running

I don't know what is going on with my (or any) wireless connection, but the result is the same: the interface remains up (the wi-fi led light remains on in my laptop) while the connection is completely lost.

  • 1
    Did you try to check in /proc/net/* ? BTW: to run ifconfig you do not need to be root, you should find it in /sbin/. In /proc/net/dev you can read the packages received and sent... the error... If you do not receive it is down... – Hastur Apr 1 '15 at 16:46
  • 1
    Does the contents of /sys/class/net/wlan0/operstate change from up to down? – Mark Plotnick Apr 1 '15 at 17:29
  • Hello @Hastur. Yes, i skimmed through /proc/net/ but found nothing relatively explicit about RUNNING. Actually, i don't know how or where ifconfig looks for that setting... – undostres Apr 1 '15 at 17:31
  • @MarkPlotnick, hello. I don't know yet because the connection has been stable so far. Will look into it. Thanks. – undostres Apr 1 '15 at 17:38
  • Try tree /sys/class/net/wlan0 too...and search... – Hastur Apr 1 '15 at 17:39

Instead of using commands like ifconfig -s or netstat -i one can check the following files to monitor a wi-fi connection status:

/sys/class/net/wlan0/flags indicates wheter the device is on or off. It tells nothing about packet transmission so it's not really useful to check if your connection is working or not. It's contents/values are 0x1003 (on) and 0x1002 (off).

/sys/class/net/wlan0/operstate indicates if the connection is operational (packets are being sent and received). This file is equivalent to the RUNNING flag displayed by ifconfig. It's values are up and down.

/sys/class/net/wlan0/carrier works just like /sys/class/net/wlan0/operstate. It's values are 1 (up) and 0 (down). The file is empty if the device is turned off.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.