Tuesday, February 24, 2009

Creating an ad-hoc wi-fi network on Linux

A simple how-to on ad-hoc networking.

First of all the basics, ad-hoc networks are not are slightly different from regular networks. In its simplest form an ad-hoc network possesses no DHCP server i.e. each computer has a static I.P. address and to talk to another computer it simply attempts to contact the other I.P address. No need of a switch in the middle to act as a mediator.

Now for a computer to be on the same ad-hoc network the following must be set:
  1. Wifi mode should be in ad-hoc
  2. The Essidof the network should be the same (duh ?)
  3. They should be on the same channel
a quick setup would involve the following 3 lines:

ifconfig wlan0 down
iwconfig wlan0 mode ad-hoc essid testing channel 5
ifconfig wlan0 192.168.10.10 up


Here "wlan0" is my wireless card, replace it what you have ( Type in "iwconfig" if you are certain what it might be ). The essid is named "testing", type anything creative here ( its the name of the wireless network and is visible by all so dont be too creative ). The channel# can be anything that wont be affected by local interference ( eg a local wifi router ). Lastly bring up the wifi card and choose an I.P address for it.

Do the same thing on the other computers except change the I.P address ( for eg make the next computer 192.168.10.11 ) and this way your ad-hoc network can grow.

P.S. make sure the computers are on the same cell. Type "iwconfig" and see the entry under "Cell". It should be the same for all computers on the network.

In the case that the computer misbehaves and doesnt connect to the network, destroy the network manager:
killall NetworkManager

No comments: