LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-29-2015, 04:46 AM   #1
ario
Member
 
Registered: Nov 2010
Posts: 65

Rep: Reputation: 2
Returning wifi and dhclient after suspend


One of the problems I got with all of the Linux distro's was network manager software in them. Sometimes network manager just can't get you connected to the same wifi after you suspended your laptop and all you can see is a turning circle. So I wrote a shell script which I tried and is very successful in getting things done on wifi. If you're experiencing similar problem, reading through that can give you a hint how to solve your problem as well.
First of all I do everything manually because I'm tired of Network Managers at the time. So I developed a shell script for creating new wifi connections:
Code:
#!/bin/bash
if [ $# -lt 2 ]; then
        echo "syntax: wifi-new <ssid> <passphrase>"
        exit 1
fi
mkdir -p /etc/wpa_supplicant
wpa_passphrase $1 $2 > /etc/wpa_supplicant/$1.conf
echo "/root/wifi-connect $1.conf" > "/root/wifi-connect-"$1
So this script creates a wpa_supplicant config file in some folder in /etc. This is what network manager applets show you as a "Connection". Of course you should run these scripts as root.
Next I created below script to reconnect wifi after a suspend. This is after hours of hiting my head to the wall for why the wifi is not getting connected. The idea is to shutdown everything about wifi and then returning them back up. Even kernel module of wifi driver will be removed from the kernel (in my case brcmsmac) and then returned back! If you are experiencing the same problem of wifi not getting connected after suspend, then trust me. This is the necessary step network manager applets lack! So here you are the script:
Code:
echo "Shutting down previous wifi stuff..."
dhclient -r wlp2s0b1
pkill wpa_supplicant
ip link set wlp2s0b1 down
sleep 1
echo "Removing wifi driver module from kernel..."
modprobe -r brcmsmac
sleep 1
echo "Returning wifi driver module to kernel..."
modprobe brcmsmac
sleep 1
echo "Restarting wifi..."
ip link set wlp2s0b1 up
sleep 1
echo "Connecting to access point..."
wpa_supplicant -B -i wlp2s0b1 -c /etc/wpa_supplicant/$1
sleep 1
echo "Trying to get an IP..."
dhclient -v wlp2s0b1
ping -c 3 -w 3 www.google.com && echo "Successfully connected to wifi access point." && exit 0
echo "Couldn't make it work. Sorry I give up :-("
exit 1
So you just give it name of the wifi config file you created with previous script (Just filename. Not full path) and it turns everything off, sleeps for some seconds and then return them back up.
Things you should modify in above script are:
brcmsmac which is the driver kernel module of my wifi card. Yours might be different.
wlp2s0b1 which is the ugly name my linux gave to my wifi card (I don't get it what was the problem with easier names like wlan0?). Again yours might be different.
This should work 100 of time and you may now start a happy life. But remember:
If in future even this script faced problem, check if if these two processes are running frozen in background and kill them with -9 signal:
pkill -9 dhclient
pkill -9 wpa_supplicant
Sometimes you may also restart your access point. Access points are also computers after all.

Last edited by ario; 08-29-2015 at 04:52 AM. Reason: Some more descriptions and correcting script
 
  


Reply

Tags
dhclient, wifi, wpa_supplicant



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
reason for multiple dhclient leases in /var/lib/dhclient/dhclient.leases psycroptic Linux - Networking 1 04-23-2014 09:24 AM
dhclient issues slackware 14 can not connec wifi ZGNULINUX Slackware 2 04-19-2014 10:26 AM
xcfe not returning from suspend daemon_byte Linux - Laptop and Netbook 1 10-10-2012 12:08 AM
RF devices disabled after returning from suspend to disk nowatson Linux - Hardware 9 02-25-2010 03:12 AM
wifi doesnt get up after suspend jimqode Linux - Wireless Networking 0 04-03-2005 03:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration