Useful Linux Wireless Commands

  • Upload
    puoj

  • View
    67

  • Download
    3

Embed Size (px)

DESCRIPTION

Useful Linux Wireless Commands

Citation preview

  • NOTE: NOT ALL CARDS/FIRMWARE SUPPORT ALL OF THE COMMANDS LISTED BELOW. 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 characters, 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) Connecting to an OPEN / WEP WLAN (Manual IP Setup) Note: replace [interface] with your interface name as required (e.g. eth1, wlan0, ath0 etc.) It may be necessary to run some packet capture software (e.g. Ethereal) to determine the IP addresses of both the Default Gateway and DNS servers. iwconfig [interface] mode managed key [WEP key] (128 bit WEP use 26 hex characters, 64 bit WEP uses 10) iwconfig [interface] essid "[ESSID]" ifconfig [interface] [IP address] netmask [subnetmask] route add default gw [IP of default gateway] (Configure your default gateway; usually the IP of the Access Point) echo nameserver [IP address of DNS server] >> /etc/resolve.conf (Configure your DNS server) 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 access 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 checking) iwconfig [interface] essid your ssid_here (configure ESSID for network) iwconfig [interface] key 1111-1111-1111-1111 (set 128 bit WEP key) iwconfig [interface] key 11111111 (set 64 bit WEP key) iwconfig [interface] key s:mykey (set key as an ASCII string) iwconfig [interface] key off (disable WEP key) iwconfig [interface] key open (sets open mode, no authentication is used and card may accept non-encrypted sessions) iwconfig [interface] channel [channel no.] (set a channel 1-14) iwconfig [interface] channel auto (automatic channel selection) iwconfig [interface] freq 2.422G (channels can also be specified in GHz) iwconfig [interface] ap 11:11:11:11:11:11 (Force card to register AP address) iwconfig [interface] rate 11M (card will use the rate specified) iwconfig [interface] rate auto (select automatic rate) iwconfig [interface] rate auto 5.5M (card will use the rate specified and any rate below as required)

  • 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 subnet-mask details) ifconfig [interface] hw ether [MAC] (Change the wireless cards MAC address, specify 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 following 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 network interface that is not displayed by iwconfig. iwlist [interface] scan (Give the list of Access Points and Ad-Hoc cells in range (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 device). iwlist [interface] retry (List the transmit retry limits and retry lifetime on the device). iwlist [interface] ap (Give the list of Access Points in range, and optionally the 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 than 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 mode 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, athx) wlanconfig athx create wlandev wifi0 wlanmode ap (Create an Access Point VAP, athx) 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 new 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)

    lshwThis command lists detailed hardware information.

    sudo lshw

    We can limit the the output to specific devices by adding options to the command. The following option "-businfo" lists information about any SCSI, IDE, IDE devices and their bus addresses along with the class of each device.

    sudo lshw -businfo

    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 networking devices.

    sudo lshw -C network

    *-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 (EXPERIMENTAL) 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 assigned 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 characters (other then 0) here denoting its place in the pci bus.The logical name (see example above) is assigned if the driver has been recognised. If there is none, the problem is either the card or the driver. Also, wmaster0 is a generic driver used by the kernel, and if this is the logical name assigned 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. lspciThis command lists information about devices on the pci bus. Adding the -v option results in more detailed output:

  • lspci -v

    You can limit the output by piping the output with grep

    lspci -v | grep Ethernet

    0000:03:00.0 Ethernet controller: Atheros Communications, Inc. AR5212 802.11abg NIC (rev 01) '''Subsystem: D-Link System Inc D-link DWL-G650 (Rev B5)''' Wireless cardbus adapter Flags: bus master, medium devsel, latency 168, IRQ 11 Memory at 10800000 (32-bit, non-prefetchable) [size=64K] Capabilities: [44] Power Management version 2Adding the -n option to lspci makes the output include the numerical PCI vendor and device ID's.

    sudo lspci -n

    0000:03:00.0 0200: '''168c:0013''' (rev 01)2.2.1. Key Points

    This command shows the revision of the card (in above example the revision of the card is B5 not 01).Using the -n option you can find the PCI ID (168C:0013) of the card and find the correct driver to use with ndiswrapper. ndiswrapper list.

    2.3. lsusbThis command lists information about devices on the USB bus.

    sudo lsusb -v

    $ lsusbBus 005 Device 001: ID 0000:0000Bus 001 Device 001: ID 0000:0000Bus 004 Device 002: ID 2001:3700 D-Link Corp. [hex] DWL-122 802.11bBus 004 Device 001: ID 0000:0000Bus 003 Device 001: ID 0000:0000Bus 002 Device 001: ID 0000:00002.4. lsmodThis 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.

    lsmod | grep ath

    ath_pci 78908 0ath_rate_sample 16776 1 ath_pciwlan 141532 4 wlan_wep,ath_pci,ath_rate_sampleath_hal 148432 3 ath_pci,ath_rate_sample2.5. modprobemodprobe 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 module for the device. This command is only needed to manually run a module

    To start a module run this command:

    sudo modprobe

    To stop and remove a module run this command:

    sudo modprobe -r

    2.6. rfkill listThis 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 software status, try

    rfkill list

    2.7. iwconfigThis command prints information about a wireless interface and allows you to configure the network interface from the command line.

    sudo iwconfig

    * eth0 no wireless extensions.

    * ath0 IEEE 802.11g ESSID:"XXXXX" Mode- Managed '''Frequency- 2.437 GHz''' '''Access Point- 00:17:16:1D: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

  • Tx excessive retries:0 Invalid misc:0 Missed beacon:02.7.1. Key Points

    This example shows the interface of ath0. If you do not see anything like this sample 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/associated 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 gui. Most drivers are set up as auto so it changes to the corresponding channel of the ap you're trying to connect to. But if you must make the change then this is the command to change it.

    sudo iwconfig channel

    or

    sudo iwconfig freq

    Channel/Frequency Chart

    Ch 1

    2.412

    Ch 2

    2.417

    Ch 3

    2.422

    Ch 4

    2.427

    Ch 5

    2.432

    Ch 6

    2.437

    Ch 7

    2.442

    Ch 8

    2.447

  • 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. ipThis command is similar to iwconfig with the following differences.

    It is a more general networking command. It works with any interface whether wireless or wired.Its configuration options and output show different networking references or set different settings.

    ip addr

    2: ath0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:11:95:50:be:62 brd ff:ff:ff:ff:ff:ff inet 192.168.1.11/24 scope global ath0 inet6 fe80::211:95ff:fe50:be62/64 scope link valid_lft forever preferred_lft forever2.8.1. Key Points

    The benefit with iproute2 on a wireless device is it shows if you have an IP address assigned to the device which is noted next to inet addr. iwconfig may show you're connected to your router but you still have no internet connection without an IP address assigned to the device.2.9. iwlistThis command will give you more detailed information from the wireless interface such as a scan of all available routers with in range.

    sudo iwlist scan

  • 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=1002.9.1. Key Points

    If you get a completed scan like the example above, your device and driver are probably working properly.Some devices, such as orinoco cards, do not support scanning so this command may not work for you.2.10. dhclientdhclient deals with DHCP if your router is running as a DHCP server.

    sudo dhclient

    If you are associated with your router try running this command to get IP and other information to set up connection.

    2.11. pingping is a good troubleshooting command to track down where the connection problem may be. Ping works like SONAR by sending an echo request to a server, waiting for it to respond and recording the time taken for the response to arrive.

    ping your local loopback device. The -c 4 option means that 4 echo requests will be sent. 127.0.0.1 is the IP address for the local loopback device; a special address that is actually your own computer. This is identical to pinging yourself.

    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 IP address assigned to the device

    ping -c 4

  • ping your router

    ping -c 4

    ping an external site using its IP address

    ping -c 4 216.239.57.99

    ping an external website using its common name.

    ping -c 4 www.google.com

    If you can ping an external site with its IP address but not the common name then there is a DNS nameserver problem. Identifying Your DeviceManufacturers and retailers often rebrand hardware to sell under their own brand. Because of this, some seemingly different devices can be internally identical and thence use identical drivers. Even if devices are not identical, there is a limited number of wireless chips that manufacturers can use. As a result, many drivers will work for multiple devices with little or no alteration.

    For this section, it will be useful to have

    Your deviceThe packaging and contents for your deviceA driver disc - even if it only contains Windows drivers.An alternate working internet connection for downloading software and drivers.Initially, note down the following:

    ManufacturerComplete model numberAny version numbers that may be printed on the device or its packaging. These can be crucial, so look carefully.Anything on the driver disc that identifies either the device itself or the components it uses. Wireless implementation chips are often operated by firmware, a type of software written specifically for that chip.2. Check for Device Recognition

    Check that Ubuntu can see and identify your device.

    Open a terminal window and type:lshw -C networkThis command lists network hardware.Check that the results correspond to the information you gathered above.

    *-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 (EXPERIMENTAL)''' ip=192.168.1.12 multicast=yes wireless=IEEE 802.11g resources: iomemory:10800000-1080ffff irq:11If no wireless devices are listed, the next step will depend on the type of interface your device uses.If a wireless device shows up then continue to the Device Drivers page

    3. PCI DevicesPCI devices should be fairly straightforward to identify. When a device is discovered, Ubuntu checks the device's PCI ID against the PCI ID Database and determines the manufacturer, model number and version (if applicable).

    Open a terminal window and enter the following command:sudo lspci -nnThe following command is specific to wireless chipsets:lspci -nn | grep 02804. USB DevicesLike PCI devices, USB devices are identified by their USB ID, a unique number assigned to each device type.

    For USB devices, use lsusb.

    5. CardBus and PCMCIA DevicesStartup 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/messagesInsert 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 CardSome 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.optsthe information you add should look like this, with your own data substituted.

  • card ""Atheros Communications, Inc.", "AR5001-0000-0000", "Wireless LAN" manfid 0x0271, 0x0012 function: 6 (network) bind "ath_pci"After making this change run this command:

    sudo kill -HUP `cat /var/run/cardmgr.pid`Now run lshw to see if the card is recognized and loaded properly.

    Most cards requiring this step will be older devices. You should not have to do this with any cards made in the past few years, but there can be exceptions.

    Notice the bind line which states what driver should be allocated to the device. You will need to find what driver your device uses. More on that in the next step.

    5.2. Problem with bridge in PCI bus line

    On several, especially new systems the Yenta bridge is not on the root PCI bridge, but behind a PCI-to-PCI bridge. On some x86 or x86_64 systems, these bridges aren't corrreclty set up by the BIOS, which may cause CardBus and even PCMCIA devices not to show up in lspci or in pccardctl ident correctly. If you suspect that this may be the cause, issue this command:

    lspci -v | grep subordinateIts result may be like this:

    Bus: primary=00, secondary=02, subordinate=04, sec-latency=64 Bus: primary=02, secondary=03, subordinate=06, sec-latency=176 Bus: primary=02, secondary=07, subordinate=0a, sec-latency=176Let's decode the first line: bus 0 (primary) is bridged to busses 2 (secondary) to 4 (subordinate) by a bridge. The second and the third line state that bus 2 is bridged to busses 3-6, and 7-10. However, the CPU (which itself is connected to bus 0 through the root bridge) needs to be able to access all these busses. If you try to walk the tree to bus 7, for example, you see that the CPU can't get there, as bus 0 is only bridged to busses 2 to 4.

    If this is the case, or you find a message stating "try pci=assign-busses" in the dmesg log, append the following to the kernel boot line:

    pci=assign-busses5.2.1. System locks upon card insertionWhen a card is first inserted, the system attempts to read the card's memory. This can sometimes cause your system to lock-up. Try this to see if it helps:

    Open the file /etc/pcmcia/config.opts

    gksudo gedit /etc/pcmcia/config.optsFind the following section:

    include memory 0xc0000-0xfffff include memory 0xa0000000-0xa0ffffff include memory 0x60000000-0x60ffffffChange it to look like this: include memory 0xd0000-0xdffff

  • include memory 0xc0000-0xcffff include memory 0xc8000-0xcffff include memory 0xd8000-0xdffff Files/etc/network/interfacesThis file stores networking interface settings.

    Network Manager cannot manage any interfaces that are named in this file. Network Manager has been the default way of managing network connections since Ubuntu 8.10 (Intrepid Ibex)

    If you are not currently using Network Manager and would like to, delete or comment out (with a # at the start of each line) your interfaces except for the two lines referring to lo (this is an internal loopback). Since Ubuntu 8.10, this file will look similar to this:

    # The loopback network interface auto lo iface lo inet loopbackDo not use an auto stanza if you are using a PCMCIA deivce that you want to start automatically at boot-time. Add map to the /etc/interfaces file. Your file should contain something similar to:

    #echo connects ath0 when device is hotplugged. using echo instead of grep allows any device to be brought up when hotplugged. Note this could cause a problem if a device is active and another one that is mapped is plugged in. mapping hotplug script echo map ath0Check your routers settings to ensure it can accept another connection.If you are running Ubuntu 8.04 (Hardy Heron) or earlier, you should have something similar to this:

    # The loopback network interface auto lo iface lo inet loopback

    # This is a list of hotpluggable network interfaces. # They will be activated automatically by the hotplug subsystem. # With lines # out these don't work. If they were removed this would hotplug only eth0 when cable is plugged in with active network #mapping hotplug # script grep # map eth0

    #echo connects ath0 when device is hotplugged. using echo instead of grep allows any device to be brought up when hotplugged. Note this could cause a problem if a device is active and another one that is mapped is plugged in. mapping hotplug script echo map ath0

    #interface of ath0 device with wep setting (not all these lines are required but show you options that may be needed) iface inet dhcp wireless-essid xxxx wireless-key xxxxx wireless-key xxxx-xxxx-xx (in certain situations a - is needed after every 4 c

  • 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 add this line)

    auto Other Resources

    An /etc/network/interfaces sample - Part of LinuxPlanet's Connecting to a Wireless 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.confThis file stores Domain Name Server (DNS) settings including nameserver addresses, 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/modulesThis file lists some of the modules that will be loaded into the kernel at boot-time. If a driver won't load at boot, you can add it to this list so that it does.

    /etc/modprobe/To enable specific configuration options for a driver create an appropriate config 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 longer need 11n_disable and 11n_disable50 options. Theses options may actually cause the driver to fail to load. Check the /etc/modprobe.d/ folder for config files that contain option reference to your driver, for example

    options iwlagn 11n_disable=1 11n_disable50=1These options can be found in config.conf or [drivername].conf file eg. intel_11n_disable.conf or awlagn.conf.

    /etc/modprobe.d/blacklistIf 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 driver is used. Note: this method will not work unless the diver is a LKM (loadable kernel module) If driver/module was compiled into the base kernel, it will still load if blacklisted. About iw

    iw is a new nl80211 based CLI configuration utility for wireless devices. It supports 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 documentation 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 >= libnl1libnl-dev >= libnl-dev-1pkg-configUsing iw requires you to have libnl, the first working version is 1.0 pre8 as this release introduced genl, Generic Netlink, which nl80211 relies on. Most distributions are shipping 1.1 these days. If your distribution's libnl is a wrong version then you'll have to download and compile libnl yourself for now (http://git.kernel.org/?p=libs/netlink/libnl.git;a=summary).

    Help

    Just enter

    iw helpon 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 information (2.4 GHz, and 5 GHz), and 802.11n information:

    iw listScanning

    iw dev wlan0 scanListening to events

    Just use

    iw eventWhen debugging, it can be useful to see the auth/assoc/deauth/disassoc frames, use

    iw event -fand sometimes timing information is also useful:

    iw event -tGetting link status

    To determine if you are connected to an AP or not and if you are the last TX rate used you can use the command below.

    Example output when associated to a legacy (non-802.11n) AP:

    iw dev wlan0 linkConnected 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/sExample output when associated to an 802.11n AP:

    iw dev wlan0 linkConnected 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 GIExample output when not connected to an AP:

    iw dev wlan0 linkNot 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 encryptionUses WEP for encryptionIf you need to connect to an AP with WPA or WPA2 encryption requirements then you 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 encryptionUses WEP for encryptionIt 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 automatically try to reconnect you when you get disconnected.

    If you do choose to deal with disconnects yourself you can use iw connect as follows.

    To connect to an AP that has encryption disabled, where its SSID is foo:

    iw wlan0 connect fooSuppose you have two APs with the SSID foo, and you know the one you want to connect to is on the frequency 2432, you can specify the frequency to use:

    iw wlan0 connect foo 2432To connect to an AP that uses WEP, you can use:

    iw wlan0 connect foo keys 0:abcde d:1:0011223344Getting station statistics

    To get station statistic information such as the amount of tx/rx bytes, the last

  • TX bitrate (including MCS rate) you can do:

    $ iw dev wlan1 station dumpStation 12:34:56:78:9a:bc (on wlan0) inactive time: 304 ms rx bytes: 18816 rx packets: 75 tx bytes: 5386 tx packets: 21 signal: -29 dBm tx bitrate: 54.0 MBit/sGetting station statistics against a peer

    If you want to get specific statistics against a peer you station is communicating with you can use the following:

    sudo iw dev wlan1 station get In the case of a STA the above would be the MAC address of your AP.

    Modifying transmit bitrates

    You can set preference for transmitting using only certain legacy bitrates. For example:

    iw wlan0 set bitrates legacy-2.4 12 18 24Setting preference for transmitting using MCS rates is not yet supported.

    Setting TX power

    You can set the txpower by using either the device interface name of the respective phy.

    iw dev set txpower []iw phy set txpower []Power save

    To enable power save by default you can use:

    sudo iw dev wlan0 set power_save onFor mac80211 drivers this means Dynamic Power Save gets enabled.

    To query the current power save settings you can use:

    iw dev wlan0 get power_saveAdding interfaces with iw

    There are several modes supported. The modes supported are:

    monitormanaged [also station]wdsmesh [also mp]ibss [also adhoc]

  • To see a description of these please read our modes documentation.

    For example to add a monitor interface:

    iw phy phy0 interface add moni0 type monitorwhere you can replace monitor by anything else and moni0 by the interface name, and need to replace phy0 by the PHY name for your hardware (usually phy0 will be correct unless you hotplugged or reloaded any modules.) If your udev is configured incorrectly, the newly created virtual interface may be renamed by it right away, use ip link to list all interfaces.

    Note that in case you want to monitor 802.11n you will need to specify channel width (20 or 20/40MHz) and in case of 20/40MHz if the upper or lower channel is being used. To do so you would use:

    iw dev set freq [HT20|HT40+|HT40-]or

    iw phy set freq [HT20|HT40+|HT40-]You can also specify channel instead of frequency:

    iw phy set channel [HT20|HT40+|HT40-]iw dev set channel [HT20|HT40+|HT40-]To create a new managed mode interface you would use:

    iw phy phy0 interface add wlan10 type managedNote that the interface is automatically put into AP mode when using hostapd.

    Modifying monitor interface flags

    You can customize the type of monitor interface you create. This can be very useful for debugging purposes on end user systems. For example suppose you want to help a user you can take advantage of the fact that a monitor interface in mac80211 uses radiotap to pass up to userspace additional data. Say we want to help a user fish out data without affecting the device's performance by setting it it to a full monitor interface an monitor interface with no additional monitor flags can be created as follows:

    iw dev wlan0 interface add fish0 type monitor flags noneYou can then request the user to use tcpdump on a session:

    tcpdump -i fish0 -s 65000 -p -U -w /tmp/fishing.dumpThe nice thing about these type of alternative monitor interfaces is you can further extend radiotap even with vendor extensions to add more data to radiotap to help debug device specific features.

    Keep in mind this requires drivers to honor mac80211's flag requests strictly, so drivers like ath5k and ath9k which still enable flags based on operation mode need to be fixed to take advantage of this.

    Monitor flags possible

    The following are flags you can specify:

  • nonefcsfailplcpfailcontrolotherbsscookDeleting interfaces with iw

    The command line is:

    iw dev moni0 delWhere "moni0" was the virtual interface interface that was created with the first 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 alpha2Where "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 regulatory domain, to do so just add a "COUNTRY=US" entry into your configuration for 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 mymeshMesh Point interfaces, by default, are configured on Channel 1. Mesh Point operation begins when the interface is brought up. In the default configuration, Mesh Point interfaces will automatically detect and attempt to create Peer Links with other Mesh Points (peers) having the same mesh ID. Use the station list and station statistics to see the peer list and Peer Link status.

    After sending traffic (ex: pinging another mesh node), you may wish to see a list of Mesh Paths:

    iw dev mesh0 mpath dump

  • Please see the open80211s.org HOWTO for further details on Mesh Point related commands and their output, as well as more examples. iw also provides commands for advanced Mesh Point configuration. These are documented in the Advanced Tinkering 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 wdsiw dev wds0 set peer In order for this to work the driver must implement the cfg80211 callback set_wds_peer(). mac80211 implements this callback, so the respective mac80211 driver would just need to support WDS type interfaces. What WDS will do is replace the first address on the 802.11 header with the peer address when TXing frames. Instead of using WDS though you may want to consider using 4-address mode described below if you have control over the software running on the AP and respective clients/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, containing both source and destination MAC addresses.

    Linux wireless has support for 4-address mode for AP and STAs but each driver needs 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 isolating 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 destination for all traffic on its interface, regardless of the destination MAC address in the packet headers. The advantage of this mode compared to regular WDS mode 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 onWhen the client side interface is included in a bridge, add -b when running wpa_supplicant.

    In hostapd you can enable this with the flag on hostapd.conf:

    wds_sta=1