Useful Linux Wireless Commands
Useful Linux Wireless Commands
Note: To connect your Linux machine to a WLAN using WPA, WPA2 or 802.1X you will
need to use WPA Supplicant
Connecting to an OPEN / WEP WLAN (DHCP)
Note: replace [interface] with your interface name as required (e.g. eth1, wlan0
, ath0 etc.)
iwconfig [interface] mode managed key [WEP key] (128 bit WEP use 26 hex characte
rs, 64 bit WEP uses 10)
iwconfig [Interface] essid "[ESSID]" (Specify ESSID for the WLAN)
dhclient [interface] (to receive an IP address, netmask, DNS server and default
gateway from the Access Point)
ping www.bbc.co.uk (if you receive a reply you have access)
iwconfig Commands:
Note: replace [interface] with your interface name as required (e.g. eth1, wlan0
, ath0 etc.)
iwconfig [interface] mode master (set the card to act as an access point mode)
iwconfig [interface] mode managed (set card to client mode on a network with an
access point)
iwconfig [interface] mode ad-hoc (set card to peer to peer networking or no acce
ss point mode)
iwconfig [interface] mode monitor (set card to RFMON mode our favourite)
iwconfig [interface] essid any (with some cards you may disable the ESSID che
cking)
iwconfig [interface] essid
your ssid_here
ifconfig Commands:
Note: replace [interface] with your interface name as required (e.g. eth1, wlan0
, ath0 etc.)
ifconfig [interface] up (bring up specified interface)
ifconfig [interface] down (take down specified interface)
ifconfig [interface] [IP address] netmask [subnet-mask] (manually set IP and sub
net-mask details)
ifconfig [interface] hw ether [MAC] (Change the wireless cards MAC address, spec
ify in format 11:11:11:11:11:11)
iwpriv Commands:
Note: replace [interface] with your interface name as required (e.g. eth1, wlan0
, ath0 etc.)
iwpriv [interface] hostapd 1 (used to set card mode to hostapd e.g. for void11)
When the monitor mode patch is installed as per the Wireless Build HOWTO the fol
lowing commands may be used to set the card into monitor mode.
iwpriv [interface] monitor [A] [B]
[A]
0 = disable monitor mode
1 = enable monitor mode with Prism2 header
2 = enable monitor mode with no Prism2
[B]
Channel to monitor (1-14)
iwlist Commands:
Note: replace [interface] with your interface name as required (e.g. eth1, wlan0
, ath0 etc.)
iwlist is used to display some large chunk of information from a wireless networ
k interface that is not displayed by iwconfig.
iwlist [interface] scan (Give the list of Access Points and Ad-Hoc cells in rang
e (ESSID, Quality, Frequency, Mode etc.) Note: In tests only worked with Atheros
cards).
iwlist [interface] channel (Give the list of available frequencies in the device
and the number of channels).
iwlist [interface] rate (List the bit-rates supported by the device).
iwlist [interface] key (List the encryption key sizes supported and display all
the encryption keys available in the device).
iwlist [interface] power (List the various Power Management attributes and modes
of the device).
iwlist [interface] txpower (List the various Transmit Power available on the dev
ice).
iwlist [interface] retry (List the transmit retry limits and retry lifetime on t
he device).
iwlist [interface] ap (Give the list of Access Points in range, and optionally t
he quality of link to them. Deprecated in favour of scan)
iwlist [interface] peers (Give the list of Peers associated/registered with this
card).
iwlist [interface] event (List the wireless events supported by this card).
Madwifi-ng Commands:
MADWiFi supports virtual access points (VAPS), which means you can create more t
han one wireless device per wireless card (the host wireless card = wifi0).
By default, a sta mode VAP is created by, which is MadWifi talk for a 'managed m
ode wireless interface'.
Note: replace athx with your interface name as required (e.g. ath0, ath1)
wlanconfig athx destroy (Destroy VAP, athx)
wlanconfig athx create wlandev wifi0 wlanmode sta (Create a managed mode VAP, at
hx)
wlanconfig athx create wlandev wifi0 wlanmode ap (Create an Access Point VAP, at
hx)
wlanconfig athx create wlandev wifi0 wlanmode adhoc (Create an Ad-Hoc VAP, athx)
wlanconfig athx create wlandev wifi0 wlanmode monitor (Create a Monitor mode VAP
, athx)
Changing modes:
ifconfig athx down (Take the VAP down)
wlanconfig athx destroy (Destroy the VAP, athx)
wlanconfig athx create wlandev wifi0 wlanmode [sta|adhoc|ap|monitor] (Create a n
ew sta, adhoc, ap or monitor VAP)
Scan for Access Points (requires both steps):
modprobe wlan_scan_sta (To insert the scanning module)
wlanconfig athx list scan (To list the APs)
lshw
This command lists detailed hardware information.
sudo lshw
We can limit the the output to specific devices by adding options to the comman
d. The following option "-businfo" lists information about any SCSI, IDE, IDE de
vices and their bus addresses along with the class of each device.
BusInfo
Device
Class
Description
pci@00:1f.5
multimedia
82801CA/CAM AC'97 Audio Controller
pci@00:1f.6
communication
82801CA/CAM AC'97 Modem Controller
pci@03:00.0
ath0
network
AR5212 802.11abg NIC
You can then use the "-C network" option to limit output so it only shows netwo
rking devices.
*-network
description: Wireless interface
product: AR5212 802.11abg NIC
vendor: Atheros Communications, Inc.
physical id: 1
bus info: pci@03:00.0
logical name: ath0
version: 01
serial: 00:11:95:50:be:62
width: 32 bits
clock: 33MHz
capabilities: bus_master cap_list ethernet physical wireless
configuration: broadcast=yes driver=ath_pci driverversion=0.9.6.0 (EXPERI
MENTAL) ip=192.168.1.12 multicast=yes wireless=IEEE 802.11g
resources: iomemory:10800000-1080ffff irq:11
2.1.1. Key Points
The configuration line will tell you if there is a driver loaded for your device
, except devices using orinoco drivers.
If you do not see a driver listed here, then there is not one loaded and assigne
d to the device, and it will not show up in iwconfig output or the nework-admin
gui.
The businfo option can show if devices are recognized and memory is readable but
the device is not physically on the bus. This is rare but it has been seen. It
may seem cryptic but your output will vary greatly and there needs to be some ch
aracters (other then 0) here denoting its place in the pci bus.
The logical name (see example above) is assigned if the driver has been recognis
ed. If there is none, the problem is either the card or the driver. Also, wmaste
r0 is a generic driver used by the kernel, and if this is the logical name assig
ned there is usually a problem with the driver also.
TODO: What does it mean when it shows *-network UNCLAIMED, and no configuration
line is present?
2.2. lspci
This command lists information about devices on the pci bus. Adding the -v optio
n results in more detailed output:
lspci -v
You can limit the output by piping the output with grep
sudo lspci -n
sudo lsusb -v
$ lsusb
Bus 005 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000
Bus 004 Device 002: ID 2001:3700 D-Link Corp. [hex] DWL-122 802.11b
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
2.4. lsmod
This command lists kernel modules that are loaded and running.
sudo lsmod
When the command lshw was run, you saw the name of the driver allocated to the
device. See example above. You can pipe this command through grep to limit the o
utput.
ath_pci
78908 0
ath_rate_sample
16776 1 ath_pci
wlan
141532 4 wlan_wep,ath_pci,ath_rate_sample
ath_hal
148432 3 ath_pci,ath_rate_sample
2.5. modprobe
modprobe runs or stops a module from running. Most wireless drivers in Ubuntu 5.
10 (Breezy Badger) are in a module form. The following commands remove or add a
module.
When a recognized device loads, the kernel automatically loads the correct modu
le for the device. This command is only needed to manually run a module
To start a module run this command:
sudo modprobe <module>
To stop and remove a module run this command:
sudo modprobe -r <module>
2.6. rfkill list
This command prints information detailing whether there are software or hardware
blocks on your rf devices. To get a list of devices and their hardware and soft
ware status, try
rfkill list
2.7. iwconfig
This command prints information about a wireless interface and allows you to con
figure the network interface from the command line.
sudo iwconfig
* eth0
* ath0
no wireless extensions.
IEEE 802.11g ESSID:"XXXXX"
Mode- Managed '''Frequency- 2.437 GHz''' '''Access Point- 00:17:16:1
D:FC:DE'''
Bit Rate-36 Mb/s Tx-Power-18 dBm Sensitivity=0/3
Retry- off RTS thr:off Fragment thr- off
Encryption key:xxxx-xxxx-xx Security mode:restricted
Power Management off
Link Quality=50/94 Signal level=-45 dBm Noise level=-95 dBm
Rx invalid nwid:10911 Rx invalid crypt:0 Rx invalid frag:0
Missed beacon:0
This example shows the interface of ath0. If you do not see anything like this s
ample then you do not have a working driver.
The interface may not be named "ath0". It could say "wlan1". You may need to use
the correct interface name to configure WICD or other wireless manager.
Access Point: If you see all zeros here or nothing then you are not connected/as
sociated to your router. When you are connected it will show the mac address of
the router here.
Frequency more commonly known as channel. If you can not connect to your router
ensure frequency is correct.
You can not set the channel(currently with breezy or earlier) via the network g
ui. Most drivers are set up as auto so it changes to the corresponding channel o
f the ap you're trying to connect to. But if you must make the change then this
is the command to change it.
Ch 9
2.452
Ch 10
2.457
Ch 11
2.462
Ch 12
2.467
Non US Channels
Ch 13
2.472
Ch 14
2.484
2.8. ip
This command is similar to iwconfig with the following differences.
It is a more general networking command. It works with any interface whether wir
eless or wired.
Its configuration options and output show different networking references or set
different settings.
ip addr
ath0
Scan completed :
Cell 01 - Address: 00:13:46:1D:BC;0E
ESSID:"xxx"
Mode: Master
Frequency: 2.437 GHz (Channel 6)
Quality=49/94 Signal level=-46 dBm Noise level=-95 dBm
Encryption key:on
Bit Rate:1 Mb/s
Bit Rate:2 Mb/s
Bit Rate:5 Mb/s
Bit Rate:6 Mb/s
Bit Rate:9 Mb/s
Bit Rate;11 Mb/s
Bit Rate;12 Mb/s
Bit Rate;18 Mb/s
Bit Rate;24 Mb/s
Bit Rate;36 Mb/s
Bit Rate;48 Mb/s
Bit Rate;54 Mb/s
Extra bcn_int=100
2.9.1. Key Points
If you get a completed scan like the example above, your device and driver are p
robably working properly.
Some devices, such as orinoco cards, do not support scanning so this command may
not work for you.
2.10. dhclient
dhclient deals with DHCP if your router is running as a DHCP server.
ping -c 4 127.0.0.1
If this doesn't work then there is a problem in the TCP/IP stack somewhere.
If your device is assigned an IP address, ping that. use iproute2 to find the I
P address assigned to the device
ping -c 4 <192.168.1.11>
width: 32 bits
clock: 33MHz
capabilities: bus_master cap_list ethernet physical wireless
configuration: broadcast=yes '''driver=ath_pci driverversion=0.9.6.0 (EXP
ERIMENTAL)''' ip=192.168.1.12 multicast=yes wireless=IEEE 802.11g
resources: iomemory:10800000-1080ffff irq:11
If no wireless devices are listed, the next step will depend on the type of inte
rface your device uses.
If a wireless device shows up then continue to the Device Drivers page
3. PCI Devices
PCI devices should be fairly straightforward to identify. When a device is disco
vered, Ubuntu checks the device's PCI ID against the PCI ID Database and determi
nes the manufacturer, model number and version (if applicable).
Open a terminal window and enter the following command:
sudo lspci -nn
The following command is specific to wireless chipsets:
lspci -nn | grep 0280
4. USB Devices
Like PCI devices, USB devices are identified by their USB ID, a unique number as
signed to each device type.
For USB devices, use lsusb.
5. CardBus and PCMCIA Devices
Startup your computer without the wireless adapter plugged in.
Login when/if prompted.
When the desktop loads, open a terminal window and type the following command:
sudo tail -f /var/log/messages
Insert your wireless adapter into an available slot.
Repeat the command above and note the difference between the two.
If the above does not work, see the next section.
5.1. Manual Installation of a PCMCIA/CardBus Card
5.1.1. Non-recognized Card
Some devices are not recognized by the OS upon insertion.
If card doesn't show up (in lshw) try these steps:
Run the following command. Hopefully you'll get some output about the device.
sudo pccardctl ident
Socket 0:
product info: "Atheros Communications, Inc.", "AR5001-0000-0000", "Wireless
LAN Reference Card", "00"
manfid: 0x0271, 0x0012
function: 6 (network)
If you get no output then the memory on the card cannot be read.
Now we need to open a configuration file and add this information to it:
gksudo gedit /etc/pcmcia/config.opts
the information you add should look like this, with your own data substituted.
memory 0xc0000-0xfffff
memory 0xa0000000-0xa0ffffff
memory 0x60000000-0x60ffffff
to look like this:
memory 0xd0000-0xdffff
haracters to work)
wireless-key1 xxxx (add a number after key to specify key number to use.)
wireless-defaultkey 1 (specifies which key is default)
wireless-key s:xxx (add s: in front of key if ascii form)
wireless-key XXXXXXXXXX open|restricted (if using shared/restricted setting ad
d this line)
auto <ath0>
Other Resources
An /etc/network/interfaces sample - Part of LinuxPlanet's Connecting to a Wirele
ss LAN with Linux, a tutorial by Carla Schroder.
This file has a manual page. Type man interfaces in a terminal to view it.
/usr/share/doc/ifupdown/examples/network-interfaces.gz. You can read through it
with the cat command and then adding | less to the end of the command.
/etc/resolv.conf
This file stores Domain Name Server (DNS) settings including nameserver addresse
s, local domain names/search server addresses and some other advanced settings.
This file has a manual page. Type man resolv.conf in a terminal to view it.
/etc/modules
This file lists some of the modules that will be loaded into the kernel at boottime. If a driver won't load at boot, you can add it to this list so that it doe
s.
/etc/modprobe/
To enable specific configuration options for a driver create an appropriate conf
ig file in this folder eg. config.conf or [drivername].conf and add the options
you want to set in this file.
notes
With the release of Ubuntu 11.10 and kernel 3.x.x some wireless drivers now no l
onger need 11n_disable and 11n_disable50 options. Theses options may actually ca
use the driver to fail to load. Check the /etc/modprobe.d/ folder for config fil
es that contain option reference to your driver, for example
options iwlagn 11n_disable=1 11n_disable50=1
These options can be found in config.conf or [drivername].conf file eg. intel_11
n_disable.conf or awlagn.conf.
/etc/modprobe.d/blacklist
If you don't want a driver to load at boot you add it to this list. Usually this
is used if you have a driver conflict and/or you want to make sure a specific d
river is used. Note: this method will not work unless the diver is a LKM (loadab
le kernel module) If driver/module was compiled into the base kernel, it will st
ill load if blacklisted.
About iw
iw is a new nl80211 based CLI configuration utility for wireless devices. It sup
ports almost all new drivers that have been added to the kernel recently.
iw is still under development. Features are added 'as we go'. The only documenta
tion that exists for iw is this page. Please help expand it.
There is a page listing use cases with iwconfig and iw: replacing iwconfig.
Getting iw
Release tarballs of iw are available from http://linuxwireless.org/download/iw/.
Alternatively, you can download iw from git: http://git.sipsolutions.net/iw.git,
the web interface can also create tarballs for arbitrary revisions.
Build requirements
libnl >= libnl1
libnl-dev >= libnl-dev-1
pkg-config
Using iw requires you to have libnl, the first working version is 1.0
is release introduced genl, Generic Netlink, which nl80211 relies on.
ibutions are shipping 1.1 these days. If your distribution's libnl is
rsion then you'll have to download and compile libnl yourself for now
t.kernel.org/?p=libs/netlink/libnl.git;a=summary).
pre8 as th
Most distr
a wrong ve
(http://gi
Help
Just enter
iw help
on your command line and it will print out the commands it supports.
Getting device capabilities
Use the following to get device capabilities for all devices, such as band infor
mation (2.4 GHz, and 5 GHz), and 802.11n information:
iw list
Scanning
iw dev wlan0 scan
Listening to events
Just use
iw event
When debugging, it can be useful to see the auth/assoc/deauth/disassoc frames, u
se
iw event -f
and sometimes timing information is also useful:
iw event -t
Getting link status
To determine if you are connected to an AP or not and if you are the last TX rat
e used you can use the command below.
Example output when associated to a legacy (non-802.11n) AP:
iw dev wlan0 link
Connected to 04:21:b0:e8:c8:8b (on wlan0)
SSID: attwifi
freq: 2437
RX: 2272 bytes (18 packets)
TX: 232 bytes (3 packets)
signal: -57 dBm
tx bitrate: 36.0 MBit/s
Example output when associated to an 802.11n AP:
iw dev wlan0 link
Connected to 68:7f:74:3b:b0:01 (on wlan0)
SSID: tesla-5g-bcm
freq: 5745
RX: 30206 bytes (201 packets)
TX: 4084 bytes (23 packets)
signal: -31 dBm
tx bitrate: 300.0 MBit/s MCS 15 40Mhz short GI
Example output when not connected to an AP:
iw dev wlan0 link
Not connected.
This would happen if you are not connected to an AP. To connect to an AP you can
use iw connect if the connection requires:
No encryption
Uses WEP for encryption
If you need to connect to an AP with WPA or WPA2 encryption requirements then yo
u must use wpa_supplicant.
Establishing a basic connection
You can use iw to connect to an AP directly if and only if the AP has:
No encryption
Uses WEP for encryption
It however should be noted that if you disconnect from the AP, which can happen
quite frequently on a busy environment, you will need to reissue the command. If
you do not want to do this you can just use wpa_supplicant which will automatic
ally try to reconnect you when you get disconnected.
If you do choose to deal with disconnects yourself you can use iw connect as fol
lows.
To connect to an AP that has encryption disabled, where its SSID is foo:
iw wlan0 connect foo
Suppose you have two APs with the SSID foo, and you know the one you want to con
nect to is on the frequency 2432, you can specify the frequency to use:
iw wlan0 connect foo 2432
To connect to an AP that uses WEP, you can use:
iw wlan0 connect foo keys 0:abcde d:1:0011223344
Getting station statistics
To get station statistic information such as the amount of tx/rx bytes, the last
none
fcsfail
plcpfail
control
otherbss
cook
Deleting interfaces with iw
The command line is:
iw dev moni0 del
Where "moni0" was the virtual interface interface that was created with the firs
t command
Virtual vif support
There is a dedicated section for virtual vif support, see the iw vif page.
Setting frequency with iw
The command line is:
iw dev wlan0 set freq 2412 [HT20|HT40+|HT40-]
Setting channel with iw
The command line is:
iw dev wlan0 set channel 1 [HT20|HT40+|HT40-]
Updating your regulatory domain
The command line is:
iw reg set alpha2
Where "alpha2" is the ISO/IEC 3166 alpha2 country code. The information used and
set comes from our regulatory infrastructure.
You can also use the latest wpa_supplicant (as of 0.6.7) now to change your regu
latory domain, to do so just add a "COUNTRY=US" entry into your configuration fo
r example.
Creating and inspecting Mesh Point interfaces with iw
You may add a mesh interface to drivers that support Mesh Point operation. Mesh
Point interfaces have a mesh_id parameter which may be up to 32 bytes long. For
example, to add an interface "mesh0" to device phy0 with mesh_id "mymesh",
iw phy phy0 interface add mesh0 type mp mesh_id mymesh
Mesh Point interfaces, by default, are configured on Channel 1. Mesh Point opera
tion begins when the interface is brought up. In the default configuration, Mesh
Point interfaces will automatically detect and attempt to create Peer Links wit
h other Mesh Points (peers) having the same mesh ID. Use the station list and st
ation statistics to see the peer list and Peer Link status.
After sending traffic (ex: pinging another mesh node), you may wish to see a lis
t of Mesh Paths:
iw dev mesh0 mpath dump
Please see the open80211s.org HOWTO for further details on Mesh Point related co
mmands and their output, as well as more examples. iw also provides commands for
advanced Mesh Point configuration. These are documented in the Advanced Tinkeri
ng section of the open80211s HOWTO.
Setting up a WDS peer
To create a WDS peer you will first need to create an interface of WDS type, and
then set the peer:
iw phy phy0 interface add wds0 type wds
iw dev wds0 set peer <MAC address>
In order for this to work the driver must implement the cfg80211 callback set_wd
s_peer(). mac80211 implements this callback, so the respective mac80211 driver w
ould just need to support WDS type interfaces. What WDS will do is replace the f
irst address on the 802.11 header with the peer address when TXing frames. Inste
ad of using WDS though you may want to consider using 4-address mode described b
elow if you have control over the software running on the AP and respective clie
nts/peers connected.
Using 4-address for AP and client mode
In some situations it might be useful to run a network with an Access Point and
multiple clients, but with each client bridged to a network behind it. For this
to work, both the client and the AP need to transmit 4-address frames, containin
g both source and destination MAC addresses.
Linux wireless has support for 4-address mode for AP and STAs but each driver ne
eds to define this capability explicitly. All mac80211 drivers support 4-address
mode if AP or STA modes of operation are supported respectively.
On the AP side you can enable 4-address frames for individual clients by isolati
ng them in separate AP VLANs which are configured in 4-address mode. Such an AP
VLAN will be limited to one client only, and this client will be used as the des
tination for all traffic on its interface, regardless of the destination MAC add
ress in the packet headers. The advantage of this mode compared to regular WDS m
ode is that it's easier to configure and does not require a static list of peer
MAC addresses on any side.
To enable 4-address mode when creating an interface you should add 4addr on, for
example:
iw phy phy0 interface add moni0 type managed 4addr on
When the client side interface is included in a bridge, add -b <bridge_interface
> when running wpa_supplicant.
In hostapd you can enable this with the flag on hostapd.conf:
wds_sta=1