Перезапустить wifi в ubuntu

How can I restart my Wi-Fi connection from the command-line?

Occasionally, my Wi-Fi connection does no longer work for various reasons. Disabling and re-enabling Wi-Fi through the graphical interface of the network indicator does not resolve the problems in these cases. How can I completely restart my Wi-Fi connection from the command-line without having to restart my machine (which fixes these problems)?

4 Answers 4

nmcli is very useful command-line utility for interacting with Network Manager. Use this command in Ubuntu 16.04 LTS

nmcli radio wifi off && sleep 5 && nmcli radio wifi on 

For versions prior to 15.10 ( i.e. before transition to systemd ) the command would be slightly different:

nmcli nm wifi off && sleep 5 && nmcli nm wifi on 

Good thing about it — this doesn’t require root powers.

Restarting network manager itself is a good idea as well.

sudo systemctl restart NetworkManager 
sudo service network-manager restart 

And if we really wanted to, we could even automate it with a script that will restart your wifi.

#!/bin/bash # replace wlan0 with your device name # as given by ip addr or ifconfig while true do # keep checking if we have ip address wifi_info=$(ip -4 -o addr show wlan0 ) while [ -n "$wifi_info" ]; do wifi_info=$(ip -4 -o addr show wlan0 ) sleep 0.25 done # We get here only if IP address is lost # which means we're off-line # restart wifi nmcli radio wifi off && sleep 5 && nmcli radio wifi on done 

Источник

Перезапуск сети в Ubuntu

В Ubuntu и Debian инициализацией сетевых интерфейсов и настройкой сети занимается специальная сетевая служба — networking. Информация о конфигурации сетевых интерфейсов хранится в файле /etc/network/interfaces.

Если вы что-либо измените в этом файле, нужно будет перезапустить сеть, чтобы применить изменения. В этой статье мы рассмотрим как выполнить перезапуск сети Ubuntu 16.04.

Перезагрузка сети в Ubuntu

Можно, конечно, выполнить полную перезагрузку компьютера, но это не совсем удобно если можно просто перезапустить сеть Ubuntu. Для перезапуска сети используйте следующую команду:

sudo service networking restart

В современных дистрибутивах уже давным давно используется система инициализации Systemd, поэтому можно использовать команду systemctl вместо команды service:

sudo systemctl restart networking.service

Кроме того, можно перезапустить NetworkManager, это тоже помогает, если сеть настроена через него:

sudo systemctl restart NetworkManager

Перезапуск сети в NetworkManager

Чаще всего, для управления сетью в современных дистрибутивах используется программа Network Manager. Можно сразу же использовать ещё для наших целей. Просто отключите, а затем включите сеть обратно следующими командами:

sudo nmcli networking off

После отключения сети значок NetworkManager пропадёт с панели, а потом снова появится после включения. Аналогично, вы можете использовать NetworkManager в графическом интерфейсе. Кликните по его иконке, выберите нужное сетевое подключение и нажмите Выключить:

Читайте также:  Ноут через вай фай работает телефон нет

Затем включите его обратно.

Команды ifup и ifdown

Эти команды работают на более низком уровне, они управляют непосредственно самими сетевым интерфейсами. Для перезапуска сети мы можем отключить все интерфейсы, а затем включить обратно:

Вы не увидите никаких изменений в графическом интерфейсе, но когда сетевой интерфейс будет отключён, вы не будете иметь доступа к интернету.

Выводы

Как видите, не всегда обязательно перезагружать компьютер после изменений настроек, в большинстве случаев достаточно перезапустить только нужный сервис. Надеюсь, эта информация была вам полезной.

Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.

Источник

How to Restart Network in Ubuntu

Here are 6 ways you can restart the network in Ubuntu and other Linux distros. Also learn to refresh wireless network connection in Ubuntu Linux.

Restart the network in Ubuntu via the command line

If you are using the Ubuntu server edition, you are already in the terminal. If you are using the desktop edition, you can access the terminal using Ctrl + Alt + T keyboard shortcut in Ubuntu.

Now you have several commands to restart the network in Ubuntu. Some (or perhaps most) commands mentioned here should also be applicable for restarting the network in Debian and other Linux distributions.

1. Restarting the Network Manager Service

This is the easiest way to restart your network using the command line. It’s equivalent to the graphical way of doing it (restarts the Network-Manager service).

sudo systemctl restart NetworkManager.service

The network icon should disappear for a moment and then reappear.

2. nmcli

This is yet another tool for handling networks on a Linux machine. It is a pretty powerful tool that I find very practical. Many sysadmins prefer it since it is easy to use. This tool is a part of the NetworkManager package.

There are two steps to this method: turning the network off and then turning it back on.

sudo nmcli networking off

The network will shut down and the icon will disappear. To turn it back on:

You can check out the man page of nmcli for more options.

3. nmtui

This is another method often used by system administrators. It is a text menu (in a Terminal User Interface) for managing networks right in your terminal. It is also a part of the Network Manager tool.

This should open up the following menu:

The interface of nmtui

Note that in nmtui, you can select another option by using the up and down arrow keys.

Select Activate a connection:

Activate a connection

Press Enter. This should now open the connections menu.

The list of connections

Here, go ahead and select the network with a star (*) next to it. In my case, it’s MGEO72.

Select the interface highlighted with a star

Press Enter. This should deactivate your connection.

Connection deactivated

Select the connection you want to activate and press Enter. This should activate the desired connection.

Activate again by selecting desired connection

Press Tab twice to select the button, and exit from the main menu. This is how you can restart a connection with nmtui.

4. ifup & ifdown

These commands handle a network interface directly, changing its state to one in which it either can or can not transmit and receive data. It’s one of the must-know networking commands in Linux.

Читайте также:  How we can see wifi password

To shut down all network interfaces, use ifdown and then use ifup to turn all network interfaces back on.

A good practice would be to combine both of these commands:

sudo ifdown -a && sudo ifup -a

Note: This method will not make the network icon in your systray disappear, and yet you won’t be able to have a connection of any sort.

That’s it! You have successfully restarted your network.

Restart the network in Ubuntu graphically

This is, of course, the easiest way of restarting the network for Ubuntu desktop users. If this one doesn’t work, you can of course check the command line options mentioned in the previous section.

NM-applet is the system tray applet indicator for NetworkManager. That’s what we’re going to use to restart our network.

First of all, check out your top panel. You should find a network icon in your system tray (in my case, it is a Wi-Fi icon, since that’s what I use).

Go ahead and click on that icon (or the sound or battery icon). This will open up the menu. Select “Turn Off” here.

Restart network in Ubuntu

The network icon should now disappear from the top panel. This means the network has been successfully turned off.

Click again on your systray to reopen the menu. Select “Turn On”.

Restarting network in Ubuntu

Congratulations! You have now restarted your network.

Bonus Tip: Refresh the available network list

Suppose you are connected to a network already but you want to connect to another network. How do you refresh the WiFi to see what other networks are available? Let me show you that.

Ubuntu doesn’t have a ‘refresh wifi networks’ option directly. It’s sort of hidden.

You’ll have to open the setting menu again and this time, click on “Select Network”.

Refresh wifi network list in Ubuntu

Now, you won’t see the list of available wireless networks immediately. When you open the networks list, it takes around 5 seconds to refresh and show up other available wireless networks.

Select another wifi network in Ubuntu

And here, you can select the network of your choice and click «Connect». That’s it.

Wrapping Up

Restarting your network or connection is something that every Linux user has to go through at some point in their experience. These tools can come in handy for doing the same.

But, if you’re stranded with not finding any wireless interface to connect with (no Wi-fi hardware detected), you can refer to this article.

You can also check out some of the most important networking commands in Linux:

We hope that we have helped you with plenty of methods for handling such issues!

What do you use to restart/handle your network? Is there something we missed? Leave us a comment below.

Источник

How do I reset the network adapter using a terminal command?

enter image description here

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 : 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.

Читайте также:  Подключить вай фай фридом

Have you tried disabling/enabling the whole wireless networking through nm? (cannot remember if 11.04 has this feature, though).

Network Manager? It used to allow to disable Networking or Wireless Networking in the menu you obtain clicking on its icon.

4 Answers 4

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:

@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.

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.

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.

nmcli radio wifi off nmcli radio wifi on 

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 ' '` 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 

Источник

Оцените статью
Adblock
detector