How to Set Up a WiFi Network in Arch Linux Terminal
If you're using another Linux distribution than the Arch CLI, you might not be used to setting up WiFi in the terminal. Although the whole process is a bit simple, I'm going to talk about it anyway. In this article, I will walk newbies through a step-by-step setup wizard to connect your Arch Linux to your WiFi network.
There are many programs in Linux to setup wireless connection, we can use ip
and iw
to configure internet connection, but it is a bit complicated for newbies. So we will use netctl
command, which is a command-line based tool for setting up and managing network connections through configuration files.
Note: All settings require root privileges, or you can do it with sudo
commands.
search the web
Run the following command to see your network interfaces:
iwconfig
Run the following command to enable your network interface, if not enabled:
iplinkset interface up
Run the command below to search for available WiFi networks. Scroll down to view.
iwlist interface scan |less
Note: The interface in the command is iwconfig
the actual network interface obtained before.
After scanning, if you do not use the interface, you can run the following command to close:
iplinksetinterface down
Configure Wi-Fi using netctl:
Before using the netctl
setup connection, you must first check the compatibility of your network card under Linux.
Run the command:
lspci -k
This command is used to check whether the kernel has loaded your wireless card driver. The output must be like this:
If the kernel doesn't load the driver, you'll have to use a wired connection to install it. Here is the official wiki page for Linux Wireless Networking: https://wireless.wiki.kernel.org/ .
If your wireless card is compatible with Linux, you can use it netctl configuration
.
netctl
Use a configuration file, which is a file that contains connection information. There are two easy and hard ways to create this file.
简单方式 – Wifi-menu
如果你想用 wifi-menu
,必须安装 dialog
。
- 运行命令:
wifi-menu
-
选择你的网络
wifi-menu to setup wifi in arch
-
输入正确的密码并等待
wifi-menu setup wifi password in arch
如果没有连接失败的信息,你可以用下面的命令确认下:
ping-c 3 www.google.com
哇!如果你看到正在 ping,意味着网络设置成功。你现在已经在 Arch Linux 下连上 WiFi 了。如果有任何问题,可以倒回去重来。也许漏了什么。
困难方式
比起上面的 wifi-menu
命令,这种方式会难一点点,所以我叫做困难方式。在上面的命令里,网络配置会自动生成。而在困难方式里,我们将手动修改配置文件。不过不要担心,也没那么难。那我们开始吧!
-
首先第一件事,你必须要知道网络接口的名字,通常会是
wlan0
或wlp2s0
,但是也有很多例外。要确认你自己的网络接口,输入iwconfig
命令并记下来。scan wifi networks in arch linux cli
-
运行命令:
cd/etc/netctl/examples
在这个目录里,有很多不同的配置文件例子。
-
拷贝将用到的配置文件例子到
/etc/netctl/your_profile
cp/etc/netctl/examples/wireless-wpa /etc/netctl/your_profile
-
你可以用这个命令来查看配置文件内容:
cat /etc/netctl/your_profile
view network profile in arch linux
-
用
vi
或者nano
编辑你的配置文件的下面几个部分:nano/etc/netctl/your_profile
- `Interface`:比如说 `wlan0` - `ESSID`:你的无线网络名字 - `key`:你的无线网络密码
注意:
如果你不知道怎么用 nano
,打开文件后,编辑要修改的地方,完了按 ctrl+o
,然后回车,然后按ctrl+x
。
edit network profile in arch
运行 netctl
-
运行命令:
cd/etc/netctl
ls
你一定会看到
wifi-menu
生成的配置文件,比如wlan0-SSID
;或者你选择了困难方式,你一定会看到你自己创建的配置文件。 -
运行命令启动连接配置:
netctl start your_profile
。 -
用下面的命令测试连接:
ping-c 3 www.google.com
输出看上去像这样:
check internet connection in arch linux
-
最后,你必须运行下面的命令:
netctl enable your_profile
。netctl enable your_profile
这样将创建并激活一个 systemd 服务,然后开机时自动启动。然后欢呼吧!你在你的 Arch Linux 里配置好 wifi 网络啦。
其他工具
你还可以使用其他程序来设置无线连接:
iw:
-
iw dev wlan0 link
– 状态 -
iw dev wlan0 scan
– 搜索网络 -
iw dev wlan0 connect your_essid
– 连接到开放网络 -
iw dev wlan0 connect your_essid key your_key
- 使用 16 进制密钥连接到 WEP 加密的网络
wpa_supplicant
Wicd
NetworkManager