Ad-hoc networking

From ArchWiki
Revision as of 18:39, 11 January 2012 by Skydiver (Talk | contribs) (stub)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Ad-hoc networking#)

You can setup ad-hoc networking to make two computers communicate or share an internet connection. The following scripts serve as an example. You will have to change the interface names for this to work on your system.

On the server

The server script works for a wireless card with an atheros driver. To make it work with a different card is trivial. More info there: https://help.ubuntu.com/community/WifiDocs/Adhoc. If you just want to connect two computers with no sharing of internet connection, you can leave out the iptables bit in the server script.

#!/bin/bash
####### this part should change or simply be removed depending on the network card
#recreates the ath0 interface in ad hoc mode
modprobe -r ath_pci
modprobe ath_pci autocreate=adhoc
wlanconfig ath0 destroy
wlanconfig ath create wlandev wifi0 wlanmode adhoc
#######

#starts the ad hoc server
ifconfig ath0 down
iwconfig ath0 mode ad-hoc
iwconfig ath0 channel 4
iwconfig ath0 essid 'mine'
ifconfig ath0 10.0.0.1 up

#forwards the ad hoc network to the router
iptables -A FORWARD -i ath0 -o eth0 -s 10.0.0.0/24 -m state --state NEW -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE
sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Here is a WPA Supplicant config file WPA based adhoc network.

ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=wheel
ap_scan=2
network={
   ssid="my-wifi"
   mode=1
   frequency=2412
   proto=WPA
   key_mgmt=NONE
   pairwise=NONE
   group=TKIP
   psk="s0m3k3y$"
}

On the client

Run the following on the client. If you want multiple clients, you will have to change the IP address to be unique.

#!/bin/bash
iwconfig eth1 essid mine
iwconfig eth1 mode Ad-Hoc
ifconfig eth1 10.0.0.2 up
route add default gw 10.0.0.1

To share an internet connection, you need to tell the clients about the DNS servers. See the /etc/resolv.conf file on the server.