Some days ago, I was looking for a quick way to connect two computers with a wireless link but without an access point. This job can be done in two ways:
– setting your wifi device to master mode (making, in fact, your computer like a real access point)
– setting your wifi device to ad-hoc mode (it’s a less scalable and low performance solution – allow wireless devices to communicate with each other in a peer-to-peer fashion)

Using the “master mode” solution will be perfect, but not all wireless drivers support this mode (actually I’m using my D-Link DWL G122 usb dongle and I have no master mode support with my current drivers; well, it’s possible getting the master mode using the next generation drivers, but it’s needed also the kernel >= 2.6.22-rc1 and it’s not my case).

To check if you have the master mode support is easy: of course, you need to have your wifi device already working, then use the iwconfig command to set the master mode: iwconfig wlan0 mode master (replace wlan0 with your wifi device). If you get no errors, probably you are lucky and you have a master mode capable device.

My goal is to bring up a temporary wireless link between the two PC, so using the ad-hoc mode will be fine (…and with my hardware and the short time available, it’s my only solution 🙂 ). Anyway, other bad news are coming: my current open source drivers are not working well in ad-hoc mode: the link is unstable and if I increase the distance between the two PC (more than one meter!!!) the link collapse. Damn!
Also with the Ralink drivers, no way to get a better result. Great! 🙁
My last idea: I will try the ndiswrapper way. Maybe, using the windows drivers, can make my day.

My DWL G122 is revision C1, so to find the correct windows driver I must to go to the D-Link UK web site. After unzipping the downloaded archive I must install the driver into ndiswrapper subsystem.

[source: js] [root@linuxbox ~]# ndiswrapper -i Dr71WU.inf
[root@linuxbox ~]# ndiswrapper -l
dr71wu : driver installed
device (07D1:3C03) present (alternate driver: rt73)
[/source]

This is a temporary solution, so I will keep the open source driver installed. I will not remove any reference to rt73 into /etc/modprobe.conf. I will unload the rt73 module by hand before loading ndiswrapper. In this way, I will not compromise the functionality of this Linux box and, with a reboot, I can restore the previous configuration status.

[source: js] /sbin/rmmod rt73
/sbin/modprobe ndiswrapper
/sbin/ifconfig wmaster0 up
/sbin/ifconfig wmaster0 192.168.111.1 netmask 255.255.255.0
/sbin/iwconfig wmaster0 mode ad-hoc
/sbin/iwconfig wmaster0 key 6572747975
/sbin/iwconfig wmaster0 channel auto
/sbin/iwconfig wmaster0 essid ADHOC
[/source]

Notes: wmaster0 is my wifi interface, this name can vary, so you must use yours. I have set up a private network with the address 192.168.111.0/24, again, you must use yours (also for the WEP key and the essid, the same rule). I have set up a WEP link: I know it’s not very secure, but it’s easy to implement and remember, this is a temporary link.

The other side of my link was my Mac laptop with the Airport wifi interface. I can found the new wireless network under the Computer-to-Computer Networks section. When prompted for the security key to join, I have entered the WEP key with the $ symbol on beginning ($6572747975 – this is an Mac-only requirement, as I know).

Finally I set up my laptop wireless device with the IP address 192.168.111.2 so I can ping the Linux box from my laptop.
The evolution of this setup, can be sharing the internet connection from the Linux box to the laptop…

Final notes:

– when you are working with devices under Linux, usually, you must be root to do this kind of jobs. Feel free to use a root shell, the su – way or the sudo way. 🙂

18 Comments

koushik · July 7, 2007 at 18:16

hi..
As I have seen ur website,It is based on D-Linnk card. I am doing a project which require Ad-Hoc network in linux.I have 2 mac mini’s with Fedora Core 7 (FC7) and I have installed MadWi-Fi drivers for it. But I am unable to connect them through in Ad-Hoc mode. As I have followed all ur instruction I was not able to communicate.
can u please help us…..

from
Koushik.C
IIIT-Hyderabad,
A.P , India

DARKGuy · August 15, 2007 at 02:02

You ROCK!! totally saved my day, now I can work using Linux and share my internet connection through the wireless card, great thanks man! keep it up :D!

Paolo · August 16, 2007 at 16:56

Thank you too mate, I appreciate 😉

Mirco · September 30, 2007 at 09:34

I also have D-Link DWL G122 rev C1 🙂
Thanks for your post: I known that I need an other Wirerless device… I’m also traing to configure my home server as WiFi router with removable USB HW.

Valerio · January 28, 2008 at 01:06

Hi, I’m a newbbie!!, thanks you now I can work using linux througt the wireless card, but I’d like to use D-Link DWL G122 rev C1 as master mode… , I have found this http://rt2x00.serialmonkey.com/phpBB2/viewtopic.php?p=26009&sid=4a579e5e1e1d0a6eddd04d9f54303fb7 !
What do you think about, on debian etch server ?
thanks a lot

Dmitri · March 25, 2008 at 19:58

Quick question. In Windows Vista, you can go to the “Connect To” menu and create an ad-hoc peer-to-peer connection. I’m assuming a Linux machine can see this wireless connection and connect.

Is there a way for Linux (Ubuntu 7.1) to wirelessly broadcast a similar ad-hoc connection so that a Windows machine can connect to it? I need the Linux machine to host.

Thanks to any replies!

Paolo · March 26, 2008 at 13:09

Hi Dmitri,
if you have the wireless device correctly detected by your distribution, using the commands from the second “box of code” (from the line 3 included, indeed) you can create your ad-hoc network and see it from any wifi capable device (so, also from Vista! 🙂 )

Last note: you have also to change the wireless device name, used into the example, to suit your system configuration…

Mariano · April 15, 2008 at 20:36

Great Info!

My topology looks something like this:

internet -> [eth0 – desktop Linux – wlan0] -> laptop Vista

I’m able to browse through Internet from my linux box, I also can make an ad hoc wireless connection between the Desktop and the Laptop.

But I can’t share internet. Could you give me a hand? I stuck on this….

Thanks,

Paolo · April 16, 2008 at 13:02

Hello Mariano,
you have to setup something like a firewall on your linux box (NAT and packet forwarding). The last time I have done this, I have used the “quick and dirty way” 🙂 with Firestarter. This piece of software has also a wizard to share an internet connection… 🙂
You can also play with iptables via the terminal, but, I guess, Firestarter will be more easy to set up.

Cheers.

Ian Page-Echols · October 6, 2008 at 00:05

You probably already know this, but if a Mac OS X machine is the one with the connection, there’s a much easier way to share the connection. In 10.5, go to the Sharing Preference Pane, click on the Internet Sharing option, select the drop down after “Share your connection from” (for example, airport) and select where you are getting your internet from, then click the check box below for which interface you want to send the internet connection to (for example, ethernet).

If you also turn on file sharing on the Mac, you can get to your files as well as surf using the second computer.

(In File Sharing, hit the options button to turn on SMB if you are using Windows, and sometimes that makes it easier in Linux as well)

Ian

p.s. – You can do this in 10.4 as well, but I don’t have a 10.4 machine in front of me right now.

Chanux · November 7, 2008 at 02:44

Was looking for this for some time. Thanx alot. great work.

Hamsaaya · March 16, 2009 at 04:00

This may not be revelant but i figured i’d post this anyway. If you’re using ubuntu 8.10 you may be in for some issues with the network manager. For some unknown reason it stops functioning. You will need to manually set you’re resolv.conf with your ISP’s DNS servers. That file is located in /etc/network/resolv.conf

Naresh · April 10, 2009 at 14:58

Hi,
I have b43 wireless driver installed then how can i connect to a peer to peer network

Thomas · October 1, 2009 at 20:23

For all those trying to setup ad-hoc on two linux machines and not getting pings returned:

I had same issues.

You must ensure ip address assigned to each and then make sure you use sudo (or su) when calling the ping command – for some reason pings were not returned when calling it from normal user account.

Then should work no probs – don’t need to bother with managed just set both as ad-hoc.

Carla Araujo · March 12, 2010 at 05:38

cool blog!!!

name · May 4, 2010 at 16:36

best for you,

suryajith chillara · September 27, 2010 at 19:59

you could also use shorewall incase iptables seem a bit not easy to handle

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *