- How to Connect WiFi from Terminal on Ubuntu 16.04
- Method 1: Using iwconfig command
- Method 2: Using wpasupplicant
- Using wpa_cli
- Работаем с Wi-Fi сетями из терминала в Linux. Просто и удобно!
- How to Connect Wi-Fi from Linux Terminal Using Nmcli Command
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- How to Connect to WiFi from the Terminal in Ubuntu Linux
- Connect to WiFi from terminal in Ubuntu
- Step 1: Identify your wireless network interface name
- Step 2: Edit the Netplan configuration file with the wifi interface details
- Possible troubleshooting
How to Connect WiFi from Terminal on Ubuntu 16.04
WiFi is nowadays the most popular way of getting an internet connection, be it at the office, home, restaurants e.t.c. This tutorial is intended to help those who would like to connect WiFi from the terminal on Ubuntu 16.04. It doesn’t matter whether you’re using the Desktop edition or the server edition of Ubuntu.
The only requirements are:
- Working wireless card
- Internet connection to install some packages
- Interactive shell session
There are two common ways you can connect Wireless network from the terminal. These are:
- Using iwconfig command
- Using wpasupplicant method
Method 1: Using iwconfig command
You can configure your Ubuntu to connect to WiFi by following steps given below. If you don’t know the name of your wifi device, use:
Open the terminal and type ifconfig interface and press Enter.
Byt default, this command just turns your wireless card on. If your wireless card has a different name, replace wlan0 with a correct name. Now that the card is on, you can connect to your WiFi network by specifying its ESSID name:
Replace with the actual name of your access point, and password with the actual security key for the wireless network. If your wireless network does not require a security key, do not enter a key password. Just use:
For the ASCII password, use:
Now confirm that you are connected. You can as well manually request an IPv4 address using.
Then try to check your ip and try to ping outside.
Method 2: Using wpasupplicant
wpa_supplicant is a cross-platform supplicant with support for WEP, WPA, and WPA2 (IEEE 802.11i / RSN (Robust Secure Network)). It is suitable for desktops, laptops, and embedded systems. For this method, you first need to install wpasupplicant package which includes the main program wpa_supplicant, the passphrase tool wpa_passphrase, and the text front-end wpa_cli
This package will provide a wpa_supplicant command which we’ll use to manage our Wireless network. The file to configure is /etc/wpa_supplicant.conf.
You can as well generate a basic configuration from cli:
Now rescan for available devices:
Make sure you can see the wireless network you intend to connect to. Now start wpa_supplicant with:
Commonly used arguments are:
-B — Fork into the background.
-c filename — Path to a configuration file.
-i interface — Interface to listen on.
-D driver — Optionally specify the driver to be used. For a list of supported drivers see the output of wpa_supplicant -h.
nl80211 is the current standard, but not all wireless chip’s modules support it.
Using wpa_cli
At this point run:
This will present an interactive prompt (>), which has tab completion and descriptions of completed commands. Some important commands to note when working on wpa_cli include:
- Scan for available access points
- List available Access points
To associate with MYSSID, add the network, set the credentials and enable it:
For access points with no authentication, use:
Finally, save this network in the configuration file:
To get a DHCP lease, first release whatever leases you’re still holding onto (as root):
And request a new address
You should now have a working internet connection through an access point which you connected from cli. This method is suitable for minimal installation of Ubuntu Distributions or Servers with Wireless card. These methods are easy to script, with more effort you can write a cron job which connects to it at reboot. Thank you for reading our guide on how to connect WiFi from the terminal on Ubuntu 16.04. If you encounter any issues, let us know through the comment section.
Источник
Работаем с Wi-Fi сетями из терминала в Linux. Просто и удобно!
Доброго времени суток всем юзерам! 🙂 Я думаю ни для кого не секрет, что при работе с ОС Linux, часто приходится работать в терминале. Терминал вещь очень хорошая если умело работать с ним и сегодня попробуем поработать с сетями Wi-Fi из под терминала 🙂
Итак, что нам нужно? Руки, голова, Wi-Fi-сети и конечно ваш любимый дистрибутив Linux 🙂
Для начала нам нужно определить, какие интерфейсы в компьютере работают с Wi-Fi сетями:
после чего вы увидите что то похожее на это:
Как мы видим по скриншоту выше, интерфейс называется wlan0.
Теперь давайте убедимся, что интерфейс wlan0 поднят и работает:
После того, как интерфейс поднят и работает, давайте просканируем сети Wi-Fi командой:
sudo iw dev wlan0 scan | less
должно выйти похожее на это:
Конечно названия сети (SSID) будет отличаться от той, что на скриншоте. Тут мы можем получить достаточную информацию о сетях Wi-Fi, такую как:
- Название (SSID);
- Тип безопасности (WEP, WPA/WPA2);
- Уровень сигнала и тд.
К примеру, если сеть не имеет пароля и соответственно открыта, то для подключения к ней используйте команду:
sudo iw dev wlan0 connect [SSID]
Если же сеть имеет тип безопасности WEP, то для подключения вводим команду (нужно знать пароль от сети):
sudo iw dev wlan0 connect [SSID] key 0:[Пароль от сети]
Для работы с зашифрованными сетями я рекомендую другой принцип работы, о нем ниже.
В данном случае нам понадобится утилита wpa_supplicant, она установлена не во всех дистрибутивах по-умолчанию. К примеру в openSUSE и Ubuntu она есть + есть к ней и GUI. GUI не установлен, ну и не надо 🙂
Устанавливаем эту утилиту, если ее у вас еще нету в системе и редактируем файл конфига wpa_supplicant:
sudo vi /etc/wpa_supplicant/wpa_supplicant.conf
Рекомендую добавлять это в конец файла, а также закоментируйте другие настройки в файле, которые вы не используете.
После того как файл отредактирован, сохраняем его и перезапускаем его командой в терминале:
sudo wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
Теперь как вы подключены к желаемой сети, вам нужно получить IP-адрес, для этого выполняем команду:
Если вы все правильно сделали, то вы уже online + получили IP-адрес через DHCP, для проверки введите команду:
Будет что то похожее на:
Вот и все 🙂 Конечно, все тоже самое можно проделать и при помощи NetworkManager к примеру, но терминал есть терминал 🙂
Источник
How to Connect Wi-Fi from Linux Terminal Using Nmcli Command
There are several command-line tools for managing a wireless network interface in Linux systems. A number of these can be used to simply view the wireless network interface status (whether it is up or down, or if it is connected to any network), such as iw, iwlist, ip, ifconfig and others.
And some are used to connect to a wireless network, and these include: nmcli, is a command-line tool used to create, show, edit, delete, enable, and disable network connections, as well as control and display network device status.
First start by checking the name of your network device using the following command. From the output of this command, the device name/interface is wlp1s0 as shown.
Next, check the Wi-Fi device connection status using the following command.
From the output above the device is not connected to any network, run the following command to scan available Wi-Fi networks.
Considering the output of the above command, the network device/interface is DOWN, you can turn it On (UP) with the ip command as shown.
If you get the following error, that means your Wifi is hard blocked on Laptop or Computer.
To remove or unblock you need to run the following command to solve the error.
Then try to turn ON the network device once more, and it should work this time around.
If you know the ESSID of the Wi-Fi network you wish to connect to, move to the next step, otherwise issue the command below to scan available Wi-Fi networks again.
And lastly, connect to the wi-fi network using following command, where Hackernet (Wi-Fi network SSID) and localhost22 (password/pre-shared key).
Once connected, verify your connectivity by doing a ping to an external machine and analyze the output of the ping as shown.
That’s It! I hope this article helped you to setup your Wi-Fi network from the Linux command line. As always, if you found this article useful, share your thoughts in the comment section below.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
How to Connect to WiFi from the Terminal in Ubuntu Linux
Last updated August 31, 2021 By Abhishek Prakash 28 Comments
In this tutorial, you’ll learn how to connect to wireless network from the terminal in Ubuntu. This is particularly helpful if you are using Ubuntu server where you don’t have access to the regular desktop environment.
I primarily use desktop Linux on my home computers. I also have multiple Linux servers for hosting It’s FOSS and related websites and open source software like Nextcloud, Discourse, Ghost, Rocket Chat etc.
I use Linode for quickly deploying Linux servers in cloud in minutes. But recently, I installed Ubuntu server on my Raspberry Pi. This is the first time I installed a server on a physical device and I had to do extra stuff to connect Ubuntu server to WiFi via command line.
In this tutorial, I’ll show the steps to connect to WiFi using terminal in Ubuntu Linux. You should
- not be afraid of using terminal to edit files
- know the wifi access point name (SSID) and the password
Connect to WiFi from terminal in Ubuntu
It is easy when you are using Ubuntu desktop because you have the GUI to easily do that. It’s not the same when you are using Ubuntu server and restricted to the command line.
Ubuntu uses Netplan utility for easily configuring networking. In Netplan, you create YAML file with the description of network interface and with the help of the netplan command line tool, you generate all the required configuration.
Let’s see how to connect to wireless networking from the terminal using Netplan.
Step 1: Identify your wireless network interface name
There are several ways to identify your network interface name. You can use the ip command, the deprecated ipconfig command or check this file:
This should give you all the available networking interface (Ethernet, wifi and loopback). The wireless network interface name starts with ‘w’ and it is usually named similar to wlanX, wlpxyz.
Take a note of this interface name. You’ll use it in the next step.
Step 2: Edit the Netplan configuration file with the wifi interface details
The Netplan configuration file resides in /etc/netplan directory. If you check the contents of this directory, you should see files like 01-network-manager-all.yml or 50-cloud-init.yaml.
If it is Ubuntu server, you should have cloud-init file. For desktops, it should be network-manager file. This is one of the several ways Ubuntu desktop differs from Ubuntu server.
The Network Manager on the Linux desktop allows you to choose a wireless network. You may hard code the wifi access point in its configuration. This could help you in some cases (like suspend) where connection drops automatically.
Whichever file it is, open it for editing. I hope you are a tad bit familiar with Nano editor because Ubuntu comes pre-installed with it.
YAML files are very sensitive about spaces, indention and alignment. Don’t use tabs, use 4 (or 2, whichever is already used in the YAML file) spaces instead where you see an indention.
Basically, you’ll have to add the following lines with the access point name (SSID) and its password (usually) in quotes:
Again, keep the alignment as I have shown or else YAML file won’t be parsed and it will throw an error.
Your complete configuration file may look like this:
I find it strange that despite the message that changes will not persist across an instance reboot, it still works.
Anyway, generate the configuration using this command:
And now apply this:
If you are lucky, you should have network connected. Try to ping a website or run apt update command.
However, things may not go as smooth and you may see some errors. Try some extra steps if that’s the case.
Possible troubleshooting
It is possible that when you use the netplan apply command, you see an error in the output that reads something like this:
It is possible that wpa_supplicant service is not running. Run this command:
Run netplan apply once again. If it fixes the issue well and good. Otherwise, shutdown your Ubuntu system using:
Start your Ubuntu system again, log in and generate and apply netplan once again:
It may show warning (instead of error) now. It is warning and not an error. I checked the running systemd services and found that netplan-wpa-wlan0.service was already running. Probably it showed the warning because it was already running and ‘netplan apply’ updated the config file (even without any changes).
It is not crtical and you may check that the internet is probably working already by running apt update.
I hope you were able to connect to wifi using the command line in Ubuntu with the help of this tutorial. If you are still facing trouble with it, do let me know in the comment section.
Like what you read? Please share it with others.
Источник