0.netplan:

netplan generate

netplan apply

  1. wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

Connect to Wi-Fi From Terminal on Debian 11/10 with WPA Supplicant

Last Updated: November 8th, 2022 Xiao Guoan (Admin) 31 Comments Debian

This tutorial is going to show you how to connect to Wi-Fi network from the command line on Debian 11/10 server and desktop using wpa_supplicant, which is an implementation of the supplicant component for the WPA protocol. A supplicant in wireless LAN is client software installed on end-user’s computer that needs to be authenticated in order to join a network.

Please note that you will need to install the wpa_supplicant software before connecting to Wi-Fi, so you need to connect to Wired Ethernet first, which is done for just one time. If you don’t like this method, please don’t be mad at me. Maybe someday Debian will ship wpa_supplicant out of the box.

Step 1: Find The Name of Your Wireless Interface And Wireless Network

Run iwconfig command to find the name of your wireless interface.

iwconfig

wlan0 is a common name for a wireless network interface on Linux systems. On systemd-based Linux distros, you might have a wireless interface named wlp4s0.

debian server connect to wifi terminal

As you can see, the wireless interface isn’t associated with any access point right now. Then run the following command to bring up the wireless interface.

sudo ip link set dev wlp4s0 up

If you encounter the following error,

RTNETLINK answers: Operation not possible due to RF-kill

you need to unblock Wi-Fi with the following command.

sudo rfkill unblock wifi

Next, find your wireless network name by scanning nearby networks with the command below. Replace wlp4s0 with your own wireless interface name. ESSID is the network name identifier.

sudo iwlist wlp4s0 scan | grep ESSID

debian connect to wifi command line wpa supplicant

Step 2: Connect to Wi-Fi Network With WPA_Supplicant

Now install wpa_supplicant on Debian 11/10 from the default software repository.

sudo apt install wpasupplicant

We need to create a file named wpa_supplicant.conf using the wpa_passphrase utility. wpa_supplicant.conf is the configuration file describing all networks that the user wants the computer to connect to. Run the following command to create this file. Replace ESSID (network name) and Wi-Fi passphrase with your own.

wpa_passphrase your-ESSID your-wifi-passphrase | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf

debian wpa_passphrase

If your ESSID contains whitespace such as (linuxbabe WiFi), you need to wrap the ESSID with double-quotes ("linuxbabe WiFi") in the above command.

The output of wpa_passphrase command will be piped to tee, and then written to the /etc/wpa_supplicant/wpa_supplicant.conf file. Now use the following command to connect your wireless card to the wireless access point.

sudo wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlp4s0

The following output indicates your wireless card is successfully connected to an access point.

Successfully initialized wpa_supplicant

wlp4s0: SME: Trying to authenticate with c5:4a:21:53:ac:eb (SSID='CMCC-11802' freq=2437 MHz)

wlp4s0: Trying to associate with c5:4a:21:53:ac:eb (SSID='CMCC-11802' freq=2437 MHz)

wlp4s0: Associated with c5:4a:21:53:ac:eb

wlp4s0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0

wlp4s0: WPA: Key negotiation completed with c5:4a:21:53:ac:eb [PTK=CCMP GTK=CCMP]

wlp4s0: CTRL-EVENT-CONNECTED - Connection to c5:4a:21:53:ac:eb completed [id=0 id_str=]

Note that if you are using Debian desktop edition, then you need to stop Network Manager with the following command, otherwise it will cause a connection problem when using wpa_supplicant.

sudo systemctl stop NetworkManager

And disable NetworkManager auto-start at boot time by executing the following command.

sudo systemctl disable NetworkManager-wait-online NetworkManager-dispatcher NetworkManager

By default, wpa_supplicant runs in the foreground. If the connection is completed, then open up another terminal window and run

iwconfig

You can see that the wireless interface is now associated with an access point.

enable wifi on debian using terminal command

You can press CTRL+C to stop the current wpa_supplicant process and run it in the background by adding the -B flag.

sudo wpa_supplicant -B -c /etc/wpa_supplicant.conf -i wlp4s0

Although we’re authenticated and connected to a wireless network, we don’t have an IP address yet. To obtain a private IP address from DHCP server, use the following command:

sudo dhclient wlp4s0

Now your wireless interface has a private IP address, which can be shown with:

ip addr show wlp4s0

debian dhclient obtain private ip address

Now you can access the Internet. To release the private IP address, run

sudo dhclient wlp4s0 -r

Connecting to Hidden Wireless Network

If your wireless router doesn’t broadcast ESSID, then you need to add the following line in /etc/wpa_supplicant/wpa_supplicant.conf file.

scan_ssid=1

Like below:

network={

ssid="LinuxBabe.Com Network"

#psk="12345qwert"

psk=68add4c5fee7dc3d0dac810f89b805d6d147c01e281f07f475a3e0195

scan_ssid=1

}

Step 3: Auto-Connect At System Boot Time

To automatically connect to wireless network at boot time, we need to edit the wpa_supplicant.service file. It’s a good idea to copy the file from /lib/systemd/system/ directory to /etc/systemd/system/ directory, then edit the file content, because we don’t want a newer version of wpa_supplicant to override our modifications.

sudo cp /lib/systemd/system/wpa_supplicant.service /etc/systemd/system/wpa_supplicant.service

Edit the file with a command-line text editor, such as Nano.

sudo nano /etc/systemd/system/wpa_supplicant.service

Find the following line.

ExecStart=/sbin/wpa_supplicant -u -s -O /run/wpa_supplicant

Change it to the following. Here we added the configuration file and the wireless interface name to the ExecStart command.

ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlp4s0

It’s recommended to always try to restart wpa_supplicant when failure is detected. Add the following right below the ExecStart line.

Restart=always

Save and close the file. (To save a file in Nano text editor, press Ctrl+O, then press Enter to confirm. To exit, press Ctrl+X.) Then reload systemd.

sudo systemctl daemon-reload

Enable wpa_supplicant service to start at boot time.

sudo systemctl enable wpa_supplicant.service

We also need to start dhclient at boot time to obtain a private IP address from DHCP server. This can be achieved by creating a systemd service unit for dhclient.

sudo nano /etc/systemd/system/dhclient.service

Put the following text into the file.

[Unit]

Description= DHCP Client

Before=network.target

After=wpa_supplicant.service

[Service]

Type=forking

ExecStart=/sbin/dhclient wlp4s0 -v

ExecStop=/sbin/dhclient wlp4s0 -r

Restart=always

[Install]

WantedBy=multi-user.target

Save and close the file. Then enable this service.

sudo systemctl enable dhclient.service

How to Obtain a Static IP Address

If you want to obtain a static IP address, then you need to disable dhclient.service.

sudo systemctl disable dhclient.service

Create a network config file.

sudo nano /etc/systemd/network/static.network

Add the following lines.

[Match]

Name=wlp4s0

[Network]

Address=192.168.1.8/24

Gateway=192.168.1.1

Save and close the file. Then create a .link file for the wireless interface.

sudo nano /etc/systemd/network/10-wifi.link

Add the following lines in this file. You need to use your own MAC address and wireless interface name. This is to prevent the system from changing the wireless interface name.

[Match]

MACAddress=a8:4b:05:2b:e8:54

[Link]

NamePolicy=

Name=wlp4s0

Save and close the file. Then disable the networking.service and enable systemd-networkd.service, which will take care of networking.

sudo systemctl disable networking

sudo systemctl enable systemd-networkd

You can now restart systemd-networkd to see if your configuration works.

sudo systemctl restart systemd-networkd

Another way to obtain a static IP address is by logging into your router’s management interface and assigning a static IP to the MAC address of your wireless card, if your router supports this feature.

Recommended Reading:

How to Use Systemd on Linux – Manage Services, Run Levels and Logs

Multiple Wi-Fi Networks

The /etc/wpa_supplicant.conf configuration file can include multiple Wi-Fi networks. wpa_supplicant automatically selects the best network based on the order of network blocks in the configuration file, network security level, and signal strength.

To add a second Wi-Fi network, run:

wpa_passphrase your-ESSID your-wifi-passphrase | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf

Note that you need to use the -a option with the tee command, which will append, instead of deleting the original content, the new Wifi-network to the file.

Wi-Fi Security

Do not use WPA2 TKIP or WPA2 TKIP+AES as the encryption method in your Wi-Fi router. TKIP is not considered secure anymore. You can use WPA2-AES as the encryption method.

Wrapping Up

I hope this tutorial helped you connect Debian 11/10 to Wi-Fi network from the command line with WPA Supplicant. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks

OS-Ubuntu-Server-Connect to Wi-Fi using "netplan" From Terminal on Debian 11/10 with WPA Supplicant的更多相关文章

  1. PowerEdge R430 机架式服务器安装( Ubuntu server 14.04.1 、PHP5.5.9、PHP-redis2.8、Phalcon3.1)

    未解决问题:换成静态路由的话,怎么就 apt-get udpate 出现错误信息! 解决办法:么有设置网关 一.Ubuntu 系统下载地址: https://certification.ubuntu. ...

  2. 在ubuntu server中安装和配置docker

    经过一段时间针对不同版本的学习,现在总结当前最新的安装配置过程(应该也是比较简单的) 如果不清楚什么是docker,请参考 https://www.docker.com/ 准备工作 建议在安装之前运行 ...

  3. ubuntu server安装kvm

    参考资料: 1. https://help.ubuntu.com/community/KVM 2.http://wiki.ubuntu.org.cn/Kvm%E6%95%99%E7%A8%8B 3.h ...

  4. Ubuntu Server 14.04 集成

    方便工作出差显示项目整合了下平时常用软件: OS: Ubuntu Server 14.04 VM:VMware Workstation 12.1.0 (不同版本好像会不兼容) 已经安装软件: 1. s ...

  5. 在Ubuntu Server下配置LAMP环境

    1. 下载Ubuntu Server,地址https://www.ubuntu.com/download/server 2. 在虚拟机上安装Ubuntu Server.根据安装引导过程一步步安装,跟在 ...

  6. 阿里云的ubuntu server 12.04 下安装jdk和tomcat

    因为想自己在做个简单粗暴的小游戏,弄到朋友圈去,买了个阿里云服务,当时选的的ubuntu sever 12.04的os,恰巧朋友又委托一个小项目,所以先尝试搭建下环境. 首先,用putty或者SSH ...

  7. ubuntu server samba服务器配置

    ubuntu server samba服务器配置 samba可以实现不同操作系统电脑之间的文件共享服务 如:mac os,linux,unix,windows,等 一:安装samba服务器 ubunt ...

  8. Ubuntu server搭建vsftpd小记

    Ubuntu server中搭建vsftpd小记 <h1> 在Ubuntu server中安装vsftpd</h1> sudo apt-get install vsftpd & ...

  9. [原创]在HP DL380 G7服务器上部署基于Ubuntu Server 16.04 和 VirtualBox的云平台

    对于一线开发人员来说,一提到虚拟机平台,往往会让人联想到在价格昂贵的服务器上部署VMware vSphere之类软件来实现. 笔者作为一个资深码农,也是一直梦寐着在自己家中打造一个真正的家庭私有云,秒 ...

  10. 在ubuntu server上搭建Hadoop

    1. Java安装: Because everything work with java. $ sudo apt-get install openjdk-7-jdk 安装之后,可以查看java的版本信 ...

随机推荐

  1. MCP云托管最优解,揭秘国内最大MCP中文社区背后的运行时

    作者:封崇 近期,中国第一AI开源社区魔搭(ModelScope)推出全新MCP广场,上架千余款热门的 MCP 服务.从当下火热的高德地图.网页抓取再到独家的支付宝,开发者/机构可以查看近1500种M ...

  2. Dpanel:Star2k,短短时间就被大家称为GitHub开源神器!轻量化Docker面板,还在等什么

    Dpanel:Star2k,短短时间就被大家称为GitHub开源神器!轻量化Docker面板,还在等什么 如今的软件开发和运维领域,Docker容器技术已经成为一种主流的解决方案,它允许开发者和系统管 ...

  3. 代码随想录第十四天 | Leecode 103. 二叉树的层序遍历、226. 翻转二叉树、101. 对称二叉树、104. 二叉树的最大深度、111. 二叉树的最小深度

    写在前面 今天补一下昨天没有写的层序遍历,层序遍历有整整十道题,打算只在博客详细写一道,后续的题目就自己在Leecode上刷一刷得了,不准备全部写下来(计划是只在博客给出每一道题目的链接).除此之外还 ...

  4. 【记录】OJ|区间DP|石子合并(环形)

    1. 题干 描述 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出一个算法,计算出将N堆石子 ...

  5. MySQL之"数据库中没有就创建,有就修改"ON DUPLICATE KEY UPDATE

    一.场景 当你想存入一条数据到扩展表中(主表下附表),但这个扩展表并非一定会创建,就会让其工程逻辑复杂化 (也就是说:有可能创建主表数据的同时不会创建扩展表数据,这样就会照成你想修改的时候,扩展表本身 ...

  6. RAG越来越不准?你可能忽略了“元数据”的力量

    你是否也有这样的困扰? 问大模型一个很具体的问题:"请告诉我A软件的安装方法." 结果它却信誓旦旦地告诉了你B软件的安装步骤. 在这个过程中,你可能已经花了大量时间解析和清洗上千份 ...

  7. 用户空间的系统调用是如何链接到内核空间的系统调用的——MIT6.S081学习记录

    用户态的sysinfo(),首先系统会从user/user.h里找到声明,随后由链接到 usys.S 中的汇编代码来实现的.usys.S是通过usys.pl生成的.usys.S 文件定义了所有系统调用 ...

  8. Java面试题:浅谈Spring Bean的生命周期

    摘要:如果熟悉Spring 中 Bean的生命周期,可以加深对Spring的认知,故综述一下Bean的生命周期. 前言   Spring中Bean的生命周期是找工作的时候会被问到的高频面试题,主要用于 ...

  9. 腾讯云对象存储工具类和demo

    使用 package com.ruoyi; import java.io.File; public class mytest { private static String secretId = &q ...

  10. java springboot图片上传和访问

    上传 @RequestMapping("/uploadImg") public Result uploadImg(HttpServletRequest request, Multi ...