29

Well ,when I turn the Router off and then I turn it on again while running Ubuntu , it doesn't obtain an IP address automatically :

enter image description here

I click on disconnect , but it remains like above.

It works only if I log out and switch to another session and then back the default one.

So How do I reset the network adapter using a terminal command, or any another suggestions?

Edit: I've tried using sudo dhclient , but it didn't work.

Binarylife
  • 16,442

4 Answers4

26

If you really want to reset the network adapter you usually need to unload and reload the kernel module that it uses.

If you just want to reconfigure it you can usually do:

sudo /etc/init.d/network-manager restart

But if you just want a new dhcp lease (that's the technical name for obtain a new IP from the router), you just need to use:

sudo dhclient -v eth1
Javier Rivera
  • 35,153
9

This sound like a network-manager problem to me.

I would try the following: (in a gnome-terminal)

  1. 'Softblock' your wireless device with rfkill block wifi
  2. rfkill list will show you if you were successful.
  3. killall nm-applet You kill the network-manager process (panel icon will be gone).
  4. rfkill unblock wifi Enable wifi again.
  5. nm-applet Load a new network-manager session.

Maybe simply killing/loading nm-applet will do. Also note, that you don't need to use 'sudo' for this.

I do know that some router and wifi devices do not 'like' each other very well. This is often a problem of a somehow 'beta' wifi linux-driver...

Jorge Castro
  • 71,754
minimec
  • 806
3
nmcli radio wifi off
nmcli radio wifi on

works for me :-)

Pilot6
  • 90,100
  • 91
  • 213
  • 324
2

I wrote a script to try various methods to reset the wifi when it dropped the connection or was otherwise non-responsive (it is called every 2 minutes in a cron):

  #!/bin/sh
  # program to check wifi and reset if not running
  IPTEST=192.168.1.1
  iwconfig=/sbin/iwconfig
  rfkill=/usr/sbin/rfkill
  DEVICE=`$iwconfig | egrep 802 | awk ' {print $1}'`

  if ping -c 1 $IPTEST >/dev/null 2>&1 ; then
    #echo $IPTEST ok
    exit 0
  else
    # Failed, try to reset wifi - sometimes works ok
    (
    date
    echo "Apagando wifi...."
    nmcli nm wifi off
    sleep 3
    echo Iniciando wifi....
    nmcli nm wifi on
    sleep 10
    if ping -c 1 $IPTEST >/dev/null 2>&1 ; then
        #echo $IPTEST ok
        exit 0
    else
        # try another way
        echo "Apagando wifi $iwconfig ...."
        $iwconfig
        $iwconfig $DEVICE txpower off
        sleep 3
        echo Iniciando wifi....
        $iwconfig $DEVICE txpower auto
    fi
    sleep 10
    if ping -c 1 $IPTEST >/dev/null 2>&1 ; then
        #echo $IPTEST ok
        exit 0
    else
        # try another way
        echo "Apagando wifi $rfkill ...."
        $rfkill list
        $rfkill block wifi
        sleep 3
        echo Iniciando wifi....
        $rfkill unblock wifi
    fi
    #echo Cerrar esta ventana cuando sale el estado
    #sleep 3
    #iftop -i $DEVICE
    )  >> $HOME/wificheck.log 2>&1
  fi
  exit 0
Mr Ed
  • 141
  • 2