Manage Wifi connections in the command line

Source: Internet
Author: User

Manage Wifi connections in the command line

Whenever you want to install a new Linux distribution system, it is generally recommended that you connect to the Internet through a wired connection. There are two main reasons for this: first, your wireless network adapter may be installed incorrectly and cannot be used; second, if you install the system from the command line, managing WiFi is terrible. I always try to avoid handling WiFi in the command line. But the Linux world should be fearless. If you do not know how to perform this operation, you need to continue learning. This is the only reason for writing this article. So I forced myself to learn how to manage WiFi connections in the command line.

There are of course many ways to set the connection to WiFi through the command line, but in this article, it is also a suggestion, I use the most basic method: that is, use the programs and tools included in the "Default package" in any released version. Or I prefer to use this method. The obvious advantage of using this method is that this operation can be reused on any machine with a Linux system. The downside is that it is relatively complicated.

First, I assume that you have installed the driver for the wireless network card correctly. There is no such premise, and everything in the future will be like a mirror. If your machine is not correctly installed, check the Wikipedia and documentation for your released version.

Use the command line to set Raspberry Pi's Wi-Fi network

How to Create a Wi-Fi hotspot in Ubuntu

Solution to the Wifi (Wireless) Problem in ArchLinux

Android Wifi Ralink RT3070 development record

Create Wifi hotspot shared Internet access for Ubuntu laptop

How to Use BackTrack to crack WEP keys in Wi-Fi networks

Then you can use the following command to check which interface supports wireless connection:

  1. $ Iwconfig

Generally, wireless interfaces are called wlan0. Of course there are exceptions, but we will always use the generic name in this tutorial.

Just in case, make sure that the interface service is started:

  1. $ Sudo ip link set wlan0 up

Once you confirm that the wireless interface is working, you can use the following command to scan nearby wireless networks:

  1. $ Sudo iw dev wlan0 scan | less

Based on the scan results, you can get the network name (its SSID), its information strength, and which security encryption is used (for example: WEP, WPA/WPA2 ). From this point on, it will be divided into two routes: Good, easy, and slightly complex.

If the network you want to connect is not encrypted, you can use the following command to connect directly:

  1. $ Sudo iw dev wlan0 connect [network SSID]

If the network is encrypted with WEP, it is also very easy:

  1. $ Sudo iw dev wlan0 connect [network SSID] key 0: [WEP key]

However, if the network uses the WPA or WPA2 protocol, it will be difficult to handle the problem. In this case, you must use wpaSupplicant tool, which does not exist by default. Then you need to modify/etc/wpaAdd the following lines to the supplicant/wpa_supplicant.conf file:

  1. Network = {
  2. Ssid = "[network ssid]"
  3. Psk = "[Password]"
  4. Priority = 1
  5. }

I suggest you add it at the end of the file and make sure that other configurations are commented out. Note that both the SSID and password strings are case sensitive. Technically, you can also regard the Access Point name as the SSID. If you use the wpa_supplicant tool, an appropriate SSID will be used to replace this name.

Once the configuration file is modified, run the following command in the background:

  1. $ Sudo wpa_supplicant-I wlan0-c/etc/wpa_supplicant/wpa_supplicant.conf

Finally, you must obtain the IP address whether connected to an open network or an encrypted security network. Use the following command:

  1. $ Sudo dhcpcd wlan0

If everything goes well, you should have obtained a new local IP through DHCP, which is automatically completed in the background. If you want to check whether the connection is connected, you can run the following command again:

  1. $ Iwconfig

Finally, I think it is necessary to repeat the first check operation multiple times. You will never know when your graphic user interface is down or when you cannot access wireless connections, so now you are ready to use commands to detect it. Also, as mentioned above, there are many ways to manage wireless connections (such as NetworkManager, wicd, netcfg, and wifi. I stick to the most basic method, but in some cases, you may not have the tools I use, so you have to download them before. On the other hand, there are many advanced applications that are indeed not included in the "Default package" and using them will greatly simplify the operation process. But it is generally recommended that you start from the basics.

Do you have other methods to manage WiFi connections from the command line? Please let us know in the comment.

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.