CentOS Wireless: Fix when it breaks!

Hi All – if you have ditched NetworkManager (as I have) and you are still running into wireless LAN access problems…check out this script!

I am in quite a rush so no time to explain the script…but check out the commands (and the order of the commands) and Enjoy 🙂

You must already have wpa_supplicant configured properly for these commands to work.

# 20150217, ABr: Updated to have extensive additional code for wireless update

if ip a show wlan0 | grep --quiet -e "inet [0-9]\+\." 2>/dev/null; then
  echo "Looks like you already have a wireless IP. Is there a problem?"

if [ $l_process -eq 1 ]; then

  # first, bring everything down
  sudo service network stop

  # next, unblock wifi
  sudo rfkill unblock wifi

  # bring up the network
  sudo service network start

  # do we have an IP?
  if ip a show wlan0 | grep --quiet -e "inet [0-9]\+\." 2>/dev/null; then
    echo "Wireless IP network found; we win."
    echo "No IP network found, bouncing wifi..."
    sudo ifdown wlan0
    # wait to give wifi time to initialize
    sleep 3
    sudo ifup wlan0

    # final check
    if ip a | grep --quiet -e "inet 192" 2>/dev/null; then
      echo "IP network found; victory!"
      echo "IP network not created, going for Round 2."

if [ $l_fixed -eq 0 ]; then
  echo "So the wireless thinks it won't work, eh?"
  echo "Time for the heavy artillery."
  echo "Firing all salvos!"
  echo "  Stop the network (again)..."
  service network stop >/dev/null 2>&1
  echo "  Killing all wpa_supplicant instances..."
  l_wpas=$(ps -efa | grep wpa | grep -v grep | sed -e 's# \+# #g' | cut -d' ' -f 2)
  for i in $l_wpas; do
    kill -9 $i
  echo "  Starting the network..."
  service network start >/dev/null 2>&1
  echo "  Force wireless down..."
  ifdown wlan0
  echo "  Unblock wireless..."
  rfkill unblock all
  echo "  Forcing the wireless card up..."
  ifconfig wlan0 up
  echo "  Forcing wpa_supplicant to start..."
  wpa_supplicant -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf  -Dwext &
  echo "  Forcing IP address..."
  ifup wlan0
  if ip a | grep --quiet -e "inet 192" 2>/dev/null; then
    echo "IP network found; victory!"
    echo "No IP network, track down Andy again."


Team-oriented systems mentor with deep knowledge of numerous software methodologies, technologies, languages, and operating systems. Excited about turning emerging technology into working production-ready systems. Focused on moving software teams to a higher level of world-class application development. Specialties:Software analysis and development...Product management through the entire lifecycle...Discrete product integration specialist!

Leave a Reply

Your email address will not be published. Required fields are marked *