Prerequisites
Wireless tools needed – iw, hostapd, wpa_supplicant, iwconfig
other tools – ifconfig, iptables, udhcpd
check whether all the above mentioned are installed, if not install before proceed further
Aim : To setup a wireless hotspot to share your internet connection you already have on a wireless interface
Here the hotspot and ur existing connection are going to be on the same single wireless interface card
step 1
Check whether ur wireless interface has the capability to act as access point, run the command
$ iw list
Under Supported interface modes, AP represents access point mode
step 2
check whether ur wireless interface driver is already build with nl80211 support
Run the following command to check that
$ lsmod | grep ath
ath9k 118238 0 mac80211 294370 2 ath9k,rtl8187 ath9k_common 13851 1ath9k ath9k_hw 323077 2ath9k,ath9k_common ath3k 12713 0 ath 23773 2 ath9k,ath9k_hw cfg80211 178528 4 ath9k,rtl8187,mac80211,ath If cfg80211 is ter in the output, it means u can use nl80211 driver Mine is Atheros wireless adapter, so i am searching for ath driver If urs broadcom, grep for bcm or b43 Having checked till here, if u r impatient go to last step where i have provided shell script to do the remaining automatically
step 3
shutdown NetworkManager services which is used by gnome network manager applet “nm-applet” or
in kde, network manager plasma
in ubuntu/kubuntu/debian
$sudo service network-manager stop
step 4
create two virtual interface for ur existing wireless interface
$ sudo iw phy phy0 interface add new0 type station
$ sudo iw phy phy0 interface add new1 type __ap
here new0 and new1 are the new interfaces v have jst created
Change the MAC address for any one interface.
say
$sudo ifconfig new1 ether hw 12:34:a3:4f:5g:4e
check whether its created successfully, run the following command
$ ifconfig -a
it should show new0, new1
step 5
We are gonna setup access point @ new1 interface
Use the following minimal hostapd configuration file for that
#hostapd.conf #change wlan0 to your wireless device interface=new1 driver=nl80211 ssid=alfi-linux channel=7 hw_mode=g wme_enabled=1 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=3 wpa_passphrase=******** wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP I have located it under /etc/hostapd.conf wpa_passphrase represents password, ssid represents ur wireless hotspot name Give ur own value This is a wpa2 personal encryption example Run the following command to start the wireless hotspot $ sudo hostapd /etc/hostapd.conf step 6 set a static ip address to interface new1 $ sudo ifconfig new1 192.168.27.1 up step 7 set up a dhcp server to provide ip address, dns, gateway details automatically to the clients we are gonna use udhcpd service to setup our dhcp server edit the file /etc/udhcpd.conf start 192.168.27.2 end 192.168.27.254 interface new1 since i set ip 192.168.27.1 for my new1, i am gonna use 192.168.27.0 subnet, so start and end should be within that range opt dns 192.168.x.x option subnet 255.255.255.0 opt router 192.168.27.1 option domain urorgonizaion.edu DNS is ur organizations DNS ip router is ur wlan0 ip domain is ur organizations domain Having configured ur conf file, its time to start our udhcp server $ service udhcpd start or $ /etc/init.d/udhcpd start Check whether ur clients are able to see this hotspot, and able to connect step 8 I am gonna connect to my existing wireless infrastructure network thro my new0 interface our network is a wpa2 enterprise infrastructure network so i am going to use wpa_supplicant tool to connect if urs is wep encryption, use iwconfig tool if urs wpa2 personal, use wpa_supplicant, refer man wpa_supplicant.conf page for help here is my sample conf file ctrl_interface=/var/run/wpa_supplicant network={ ssid="kcc-wifi" key_mgmt=WPA-EAP eap=PEAP identity="****" password="***********" phase1="peaplabel=0" phase2="auth=MSCHAPV2" } i located my file under /etc/wpa_supplicant.conf use wpa_supplicant to connect $ sudo wpa_supplicant -i new0 -c /etc/wpa_supplicant.conf step 9 set up ip address statically or use dhcp client to get ipaddress dynamically $ sudo udhcpc -i new0 this command will pull ip address, dns, gateway info for ur machine step 10 Enable IP forwarding & NAT(Network Address Translation) as root user # echo "1" > /proc/sys/net/ipv4/ip_forward Next, use iptables to do NAT(Network Address Translation) $ iptables --table nat --append POSTROUTING --out-interface new0 -j MASQUERADE $ iptables --append FORWARD --in-interface new1 -j ACCEPT here new0 is connected to internet new1 is our wireless hotspot access point So in my case, i have internet connection in my new0 interface thats been shared thro new1 interface step 11 Shell Script to automate the above steps #1 hostapd.conf file, download and put it under /etc/ and change ssid & wpa_passphrase value #2 hotspotsetup.sh , download and execute like this $ bash hotspotsetup.sh as root user
Thanks for this howto 🙂
Just wanted to leave a note though: this is not gonna work with Ralink chipsets.
More info in rt2x00 maillist:
http://rt2x00.serialmonkey.com/pipermail/users_rt2x00.serialmonkey.com/2010-June/001495.html
http://rt2x00.serialmonkey.com/pipermail/users_rt2x00.serialmonkey.com/2010-July/001663.html
http://rt2x00.serialmonkey.com/pipermail/users_rt2x00.serialmonkey.com/2011-December/004329.html
Thanks bro for ur valuable comment.
I’ve tried your tutorial and it goes well. But when I’m trying to connect to it, the device tells me that my wpa pre-shared key is invalid. Do you know what the problem is? It occurs in every device
Thanks for wonderful solution. However I have slightly different requirement. My internet connection is modem based i.e it has dynamic IP hence my wifi is idle which I want to use as broadcaster so that other devices like phone, tablet can connect to it and use internet from it.
If you specify changes in steps for this requirement then I will be thankful.
Moreover I have Fedora 14 system and I am not able to find “udhcpd” utility anywhere. Can you help where can I find it?
use dnsmasq
Hello, i liked your tutorial but i am not able to use the virtual wifi to connect to Wifi network and do ad-hoc mode simultaneously. I have the Pandaboard ES which has WLINK 6.0 chipset. How do i find out that the chipset allows us to do both modes.
Thanks.
plz help me “Could not set interface new0 flags: No buffer space available”