The iwconfig command in Linux: configure WiFi interfaces

Introduction

In Linux systems, wireless connections can be managed using various tools. One of the most classic and still useful isiwconfig, which allows to inspect and modify the parameters of a WiFi interface from the terminal.

What is iwconfig?

iwconfig is part of the set of utility wireless-tools and works with the wireless extension of the kernel. Its main function is to show or change the mode, ESSID, frequency, transmission rate and other attributes of wireless interfaces.

Basic syntax

The general form is:

iwconfig [interface] [parameters]

If the interface name is omitted, iwconfig shows the status of all the wireless interfaces detected.

Show interface information

To see the current data on a card, for example wlan0, just run:

iwconfig wlan0

The output includes mode (Managed, Ad-Hoc, Master), ESSID, access point (MAC), frequency, signal level and bit rate.

Change the operating mode

WiFi interfaces can work in several ways. The most common are:

  • Managed: is connected to an access point or router.
  • Ad-Hoc: creates a point-to-point network without AP.
  • Master: acts as an access point (requires compatible driver and hardware).

To change the mode to Managed it is used:

iwconfig wlan0 mode Managed

Similarly, for Ad-Hoc:

iwconfig wlan0 mode Ad-Hoc

Set ESSID and key

The ESSID identifies the WiFi network. To assign it:

iwconfig wlan0 esSid MiRed

If the network is hidden, the parameter should be addedessid offbefore scanning or usingiwlist scanto find out.

As for safety, iwconfig supports WEP keys using the parameterkey:

iwconfig wlan0 key s: miclave123

The prefixs:indicates that the key is provided in ASCII format; otherwise hexadecimal is assumed. Note that WEP is considered unsafe and it is recommended to use WPA / WPA2 with tools such as wpa _ supplicant.

Adjust the transmission power

Some adapters allow to modify output power to save energy or reduce interference:

iwconfig wlan0 txpower 15dBm

The value can be expressed in dBm or mW (using the suffix)mW). Not all drivers support this adjustment.

Configure channel and rate

The channel determines the frequency used. To set it:

iwconfig wlan0 channel 6

Similarly, the transmission rate may be limited:

iwconfig wlan0 rate 54M

These settings are useful in environments with a lot of interference or when it is sought to maximize the reach.

Save the changes persistently

The changes made with iwconfig are volatile and are lost when the interface or system is restarted. To last, commands can be added to a start script, for example in/etc/network/interfaces(in ifupdown-based systems) or useNetworkManagerwith their own configurations.

A simple example of script:

#! / bin / bash iwconfig wlan0 esSid MiRed iwconfig wlan0 key s: miclave123 iwconfig wlan0 mode Managed

Keep it as/usr/local/bin/wifi-setup.sh, grant execution permission and add it to the start-up applications of your desktop environment orcronwith@reboot.

Limitations and alternatives

Although iwconfig is powerful and simple, it has some limitations:

  • It does not manage WPA / WPA2 authentication; it requires wpa _ supplicant.
  • It does not scan networks itself; it is usediwlist scanornmcli.
  • Some modern drivers prefer the interfacenl80211and the tooliw.

In practice, many administrators combine iwconfig for quick mode, power or channel settings, and use wpa _ supplicant or NetworkManager for secure authentication.

Conclusion

iwconfig remains a valuable tool for those who need to control basic aspects of a WiFi interface from the Linux command line. Its clear syntax and its availability in most distributions makes it ideal for tests, configuration scripts and situations where a quick adjustment is required without loading complex graphic environments.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish