28

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.

5
  • Have you tried disabling/enabling the whole wireless networking through nm? (cannot remember if 11.04 has this feature, though).
    – enzotib
    Jul 27, 2011 at 13:41
  • Network Manager? It used to allow to disable Networking or Wireless Networking in the menu you obtain clicking on its icon.
    – enzotib
    Jul 27, 2011 at 13:44
  • Yeah I got it ,You mean to untick "enable wireless" from the network manager?
    – Binarylife
    Jul 27, 2011 at 13:44
  • Yeah, I mean this
    – enzotib
    Jul 27, 2011 at 13:45
  • Yeah,it didn't work also.
    – Binarylife
    Jul 27, 2011 at 13:46

4 Answers 4

24

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
10
  • So sudo dhclient will obtain a new IP Address?
    – Binarylife
    Jul 27, 2011 at 13:48
  • @Binarylife yes, that should get you a new IP address. If it doesnt, the router's DHCP may be at fault, and not your wifi card.
    – Thomas Ward
    Jul 27, 2011 at 13:52
  • @The Evil Phoenix: Okay, I'll try it when I get the issue again, thanks.
    – Binarylife
    Jul 27, 2011 at 13:57
  • If it doesn't work, the messages that it will output can be useful for debugging. Jul 27, 2011 at 16:08
  • 2
    IMHO this answer will not work, as both mentioned commands refer to listed devices in /etc/network/interfaces. In a normal Ubuntu install, only 'loopback' is listed there.
    – minimec
    Jul 28, 2011 at 14:06
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...

1
  • Thanks for your answer, I'll try it also. By the way I am using Siemens ADSL sl2-141router.
    – Binarylife
    Jul 28, 2011 at 16:22
3
nmcli radio wifi off
nmcli radio wifi on

works for me :-)

1
1

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
1
  • Both; rfkill & nmcli helped me out.
    – voices
    Jan 10, 2016 at 22:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .