# network needs to be restarted manually after suspend

## HyperQuantum

When my laptop goes into suspend (to RAM), and it remains in that state for a couple of hours, then I don't have an internet connection anymore when I reactivate it. I have to restart the network connection manually before I can use my webbrowser again:

```
# /etc/init.d/net.wlan0 restart
```

I suspect that the connection stops working because the DHCP lease expires (or something), but why isn't it automatically renewed when the laptop comes back on?

----------

## Hu

 *HyperQuantum wrote:*   

> I suspect that the connection stops working because the DHCP lease expires (or something), but why isn't it automatically renewed when the laptop comes back on?

 Reactivating the network might be the wrong thing to do if you come back up on battery in a wireless-free zone, or you do not want to expose yourself to the local network (perhaps you just wanted to read local files), or various other reasons.  If you always want to enable the wireless card on resume, you should tell your suspend script to bring the interface down on suspend and bring it up on resume.

----------

## Joseph K.

I have the exact same question, because my old laptop would automatically connect to a network that was configured in wpa_supplicant.conf, but my new laptop does not.  At first I suspected that it was because I had disabled wireless extensions on the new laptop, but even after enabling it the behaviour is the same.  Any ideas on why that might be?

In order to effect the reconnect behaviour I had a look at the commands available to wpa_cli, but I think it's not suitable for stopping and starting the network, so it's a choice between ifconfig up/down and net.wlan0 stop/start.  I'm going to go for ifconfig up/down because it seems like the simplest command to achieve the desired effect.

----------

## RNHavens

robert@foomanchu ~ $ grep net.wlan0 -C3 /etc/hibernate/common.conf

### services

 RestartServices alsasound 

 RestartServices net.wlan0

# StopServices alsasound

# StartServices aumix

----------

## Joseph K.

Hmmm, I guess you must be using a different power management package, RNHavens, because I don't have that /etc/hibernate directory.

After a bit of experimenting, I found that enabling WE support in the kernel was causing wpa_supplicant to crash on resume.  Now that I have disabled it again, wpa_supplicant does assume that it is still connected to the same wireless network when I resume, which is a security risk, but not a serious one.  Anyway, since I use the laptop at many locations, I found it was better to stop the network script on suspend and start it again on resume anyway, because it would not automatically realize that it was in a new location.  ifconfig up/down didn't quite cut it.

However, I am still curious as to why it is not stopping/starting automagically like my old laptop did.  Cheers.

----------

## mr.sande

I'v had this happen too.

I solved it by adding a little script to /etc/pm/sleep.d/. You have to make it executable in order to make it work.

There should also be a /hibernate.d/ in /etc/pm/ if you want your system to do the same when hibernating.

```
quark sleep.d # cat 50wifi 

#!/bin/bash

case $1 in

   suspend)

      echo "Stopping wifi"

      /etc/init.d/net.wlan0 stop > /dev/null

      ;;

   resume)

      echo "Starting wifi"

      /etc/init.d/net.wlan0 start > /dev/null

      ;;

esac

```

I guess it depends on how your setup suspends, I'm using pm-utils in Gnome.

----------

## Dagger

Alternatively you can use NetworkManager. It will handle everything for you. It understands Gentoo configuration files, so switch should be really easy.

If you don't like ppp dependency, you can test 0.9beta1 from my overlay - it should be merged to portage once 0.9.0 is released.

----------

## Rion

NetworkManager doesn't work in the same way (I have to restart NetworkManager each time after resume).

and even hack with sleep.d (restarting  Networkmanager there) doesn't work.

I didn't try nm-0.9 though.

I have switched from nm to manually configured wpa_supplicant and net.wlan0 with sleep.d hack.

----------

## eugen_mihailescu

 *mr.sande wrote:*   

> I'v had this happen too.
> 
> I solved it by adding a little script to /etc/pm/sleep.d/. You have to make it executable in order to make it work.
> 
> There should also be a /hibernate.d/ in /etc/pm/ if you want your system to do the same when hibernating.
> ...

 

It works for me too. Thank you!

----------

## eccerr0r

I've been a NetworkManager-0.8 user with Gnome, and it handles suspend/resume fine.  I do have to make sure that I mark in nm-applet which networks it should auto-reconnect to, naturally I don't want it automatically connecting to any network it's near - just my home network.

Granted, if it was on a particular access point on sleep/hibernate and it's still near that access point on resume, it will not reconnect to that access point unless I specify auto-reconnect in that profile...

----------

## kimmie

Could be a kernel problem... there have been issues with some wireless drivers in recentish kernels. This was happening on my laptop (iwlagn) until 3.0.6 (I think, might have been 2.6.39, memory fades). Anyway 3.0.6 reconnects properly for me after resume. My router hands out leases for a few days, so it's very unlikely a lease would be need renewing after a resume.

Vaguely related: on 3.1.6 iwlagn doesn't work for me at all... apparently iwlagn and iwlwifi are getting merged and it should be sorted in 3.2.

----------

