The aim of this document is to provide information about the steps needed to create and connect to ad hoc networks with a working wireless card. Identification of hardware and installation of drivers will not be covered, if you are unsure please look to the Supported Cards section first.

Management Software

There are several ways of managing your wireless connection.

Network Manager

Network Manager has the ability to connect to ad hoc networks through the simple to use nm-applet interface. Some wifi cards will not work with it automatically, see the supported cards section below.

Joining an ad hoc network

Click on the tray icon and you will see the ssid of the ad hoc network with the ad hoc icon next to it, click on it to connect.

Creating an ad hoc network

NetworkManager Method

Linux to Windows peers

Linux to Linux peers

tested on 10.04 Netbook Remix using the Broadcom B43 proprietary driver. Broadcom STA did not work properly

1. Right-mouse click the NetworkManager icon (top right)

2. Select "Edit Connections"

3. Click the "Wireless" tab

4. Click "Add" to edit a new wireless connection

5. On the wireless dialogue give the connection a name, e.g "Mochudi".

  • SSID: "Mochudi". The SSID will appear on the NetworkManager of your other Peers

  • Mode: Ad Hoc
  • BSSID: leave blank

  • MAC Address: leave blank

  • MTU: leave as automatic

6. Click "Apply"

7. Click "Close"

If fixed IP addresses are required edit the IPv4 Settings Tab before closing NetworkManager above: above then...

6a. Click "IPv4 Settings Tab"

  • Select Method "Manual"
  • Under Addresses click Add
  • Type your Address:
  • Type the Netmask:
  • Gateway: leave blank or

6b. Click "Apply"

7. Click "Close"

Do the above for each machine joining your fixed IP address Ad-Hoc network except assign a unique Address to each machine, so becomes for the second computer, for the third, etc.


If the SSID does not appear in NetworkManager try looking for it through "Connect to Hidden Wireless Network..." from the NetworkManager icon.

Wireless Extensions CLI tools Method

This process is often used as the fall back position if the gui tools fail to work. The following example uses eth1 for the wifi interface though this may be wlan0, ath0 or something else in your case.


Ensure that network manager has been stopped and then bring the interface down.

sudo service network-manager stop
sudo ip link set eth1 down


  1. Switch the card into ad hoc mode
    sudo iwconfig eth1 mode ad-hoc
  2. Set the channel/frequency that you want to use.
    sudo iwconfig eth1 channel 4
  3. Add the name (ssid) for the network you want to create/join. Use single quotes if there is a space in the name.
    sudo iwconfig eth1 essid 'name'
  4. Add a WEP encryption key
    sudo iwconfig eth1 key 1234567890


  1. Bring the interface back up
    sudo ip link set eth1 up
  2. Start dhclient to get an address
    sudo dhclient eth1
  3. If you want to do it manually, you will have to make up an IP address.
    sudo ip addr add dev eth1

You should now be connected to the ad hoc network. Use the iwconfig command to view the cell being used. This must match the same cell on the other PCs that you want to connect to.


Once you have two or more computers connected to the ad hoc network, all of them showing the same cell number and having different IP addresses, then try pinging one from the others.


If that doesn't work then try specifying the interface name along with the address.

ping -I eth1

If you have more than one interface with link-local addresses there can be some routing confusion, so I recommend that you bring down these unused interfaces while connected to non-DHCP networks. If the other interfaces are all on DHCP networks, such as in the case of InternetConnectionSharing this is not necessary.

sudo ifdown eth0

Example Interfaces File

Currently Network Manager does not support static address settings and Network-Admin does not support ad hoc networks. So instead we can configure the network in the /etc/network/interfaces file. The following is an example.

auto lo
iface lo inet loopback

auto eth1
iface eth1 inet static
wireless-mode ad-hoc
wireless-channel 4
wireless-essid 'name'
wireless-key 1234567890

Supported Cards

Instructions for wireless cards that support ad hoc networking, separated by chipset manufacturer. Please identify the chipset included in your card via the WirelessCardsSupported list.


The restricted Madwifi driver supports ad hoc mode through the creation of a new VAP. This document only covers the madwifi-ng driver as used in Ubuntu 6.10 (Edgy) and later. For madwifi-old as used in Ubuntu 6.06 (Dapper) and earlier, check the website for information.

You can create an ad hoc interface in either of the following two ways:


Usually when the driver module is loaded on boot it automatically creates an ath0 interface in managed (sta) mode. We can redo this procedure but create an ad hoc interface instead. This will not make a permanent change, it will default back to creating a managed mode interface on next boot or if you re-insert the driver without the option.

  1. Remove the ath_pci module with modprobe
    sudo modprobe -r ath_pci
  2. Now re-insert the module with the option of creating it in ad hoc mode.
    sudo modprobe ath_pci autocreate=adhoc


This process requires that you install the madwifi-tools package from the universe repository. In Ubuntu 6.10 (Edgy) there is a backports version available from Launchpad The main benefit of this package is that you can create multiple interfaces.

  1. Destroy the current managed mode interface
    sudo wlanconfig ath0 destroy 
  2. Create a new interface in ad hoc mode
    sudo wlanconfig ath create wlandev wifi0 wlanmode adhoc 


The b43 driver ( supports ad-hoc networking for many cards in the Broadcom 43xx family. The b43 driver was formerly known as the bcm43xx driver. If you find your card is not supported, you may want to try Ndiswrapper as a temporary solution until the b43 driver team figures out your card. However, there are a number of other things in this tutorial to try before switching to the ndiswrapper.


The Intel PRO/Wireless 3945abg cards using the restricted ipw3945 driver support ad hoc mode out of the box. The ipw2200 driver supports the Intel PRO/Wireless 2915 out-of-the-box as well. Other Intel cards should work too.

This section has not yet been written.


It is recommended that you use some form of encryption on all wireless networks. Currently this is easiest to achieve with WEP, even though WEP is no longer considered secure. "Unfortunately WPA is much harder to get working, though this is being worked on in wpa_supplicant."

To start WPA adhoc network, create wpa-adhoc.conf:

        ssid="test adhoc"

and start it:

wpa_supplicant -cwpa-adhoc.conf -iwlan0 -Dwext

here is part of documentation (wpasupplicant-0.6.9/wpa_supplicant/wpa_supplicant.conf):

# mode: IEEE 802.11 operation mode
# 0 = infrastructure (Managed) mode, i.e., associate with an AP (default)
# 1 = IBSS (ad-hoc, peer-to-peer)
# Note: IBSS can only be used with key_mgmt NONE (plaintext and static WEP)
# and key_mgmt=WPA-NONE (fixed group key TKIP/CCMP). In addition, ap_scan has
# to be set to 2 for IBSS. WPA-None requires following network block options:
# proto=WPA, key_mgmt=WPA-NONE, pairwise=NONE, group=TKIP (or CCMP, but not
# both), and psk must also be set.

you do not need to setup any thing before this steps.

WPA2 is currently not supported.

Alternatively, you could leave encryption disabled and establish a VPN between hosts, either using OpenVPN or even SSH


This is designed to self allocate IP addresses in a network where there are no DHCP servers. So it is valuable in ad hoc networks. To make use of it you have to start dhclient, once that fails avahi-autoip will kick in and give you an address in the link-local address space. This means that you will have an IP address in the - range. In combination with avahi's mdns stack you will be able to communicate with other PCs via the .local domain.

e.g. ping hostname.local

Real-life examples

1. Connecting with an Atheros card to a Windows peer to peer wireless network to utilise another machine's internet connection

This example is for beginners like me who want the technical solution to a simple real-world problem. It may not be the most elegant answer but it works.

Background: At my inlaws' house I recently set up a wireless peer to peer network between 2 Windows machines, one of which had an internet connection. To keep things simple the network that I set up on the host machine (the one with the internet connection) was 'open' and WEP-encrypted, and the properties of the internet connection were set to allow other machines to connect to the web through it. In return the father of the house kindly donated me a really old laptop, which of course I stripped down and stuck Ubuntu 7.04 on, and added a wireless card: a Netgear WG511T. For this Atheros card it is possible to use the Madwifi drivers or Ndiswrapper. I chose Madwifi.

Solution: Following the instructions in the rest of this document I wrote a simple script that I could run at the click of a button whenever I wanted to join the ad-hoc network, rather than have the card running in its default managed mode. Essentially all it does is turn off the default Network Manager, put the card into ad-hoc mode, specify what network to join, bring the card back up and get an IP address. The script is as follows, where the ad-hoc network name in my case is 'binky' and the password is '12345' - obviously you should replace these with your specific details:

  • /etc/dbus-1/event.d/25NetworkManager stop # stops the default network manager
    wlanconfig ath0 destroy # removes the current network card interface
    wlanconfig ath create wlandev wifi0 wlanmode adhoc # creates a new interface in ad-hoc mode
    iwconfig ath0 essid 'binky' # states the name of the network to join
    iwconfig ath0 key '12345' # states the password of the network to join
    ip link set ath0 up # brings the interface back up
    dhclient ath0 # gets an IP address, eventually from avahi-autoip

The last line gets me an IP address. Dhclient will look for a DHCP server and ask it for one. But in my ad-hoc network there is no DHCP server, which would normally be a problem. Luckily avahi-autoip comes with Ubuntu by default, and when Dhclient failed to find a server it kicked in and automatically self-assigned an IP address to me - see the avahi-autoip section above for more details.

I saved the script somewhere in my home area as and made sure it had permission to be executed:

  • chmod a+x

I need to run the script as sudo, which means in my case I type sudo /home/andy/scripts/

You should be able to use this as is (making suitable network name and password changes), and the nice thing about it for me is that the machine will remain in roaming managed mode most of the time, therefore able to connect to any Wifi hotspots that may be around, unless I run this script to connect to the inlaws' ad-hoc network.

WifiDocs/Adhoc (last edited 2011-05-23 03:29:45 by takashi)