My Experience/Excitement/Fun/Fight with Linux

Just another WordPress.com site

Archive for the month “November, 2011”

Connectify for Linux with Single wireless interface

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
Advertisements

Connectify for Linux

Connectify allows a PC to create wireless hotspot. So using this we can share existing wired/wireless internet through a wireless interface.

How to do that in Linux? with single wireless interface/with two wireless interface card

First Rule, we are gonna stick together with the command line tools, so v have to switch off the NetworkManager service, kill nm-applet also

Do everything with root user

ubuntu/debian  users

$ service network-manager stop 

or

Fedora/Redhat users

$ service NetworkManager stop

First with 2 wireless interface cards

We will be using existing wireless tools in Linux.

Here is the Logic behind this

You have internet connection @ one wireless card which is a Station(Managed) node

The other wireless interface card is going to act as a Access Point(Master) node

Steps:

To setup the access point we need hostapd package, either install it from your distribution repository or build from the source code

hostapd uses nl80211 driver, to check whether your card was already build with this capability run the following command

Mine is Atheros Wireless Network Adapter, so i am searching of “ath” driver module

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

As u see from the above output, my ath9k driver is build with cfg80211 capability,
tat means we can use nl80211 api
If yours is broadcom, probably u should grep for bcm or b43
If yours is not build with cfg80211 capability, try installing the extra kernel modules, i.e kernel wireless backport modules
Now we have to create hostapd configuration file
here is sample hostapd.conf file content
 
#change wlan0 to your wireless device
interface=wlan0
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

this example conf file uses wpa2 personal encryption, replace ssid, wpa_passphrase with your desired value
next to start hostapd service, run the following

$ hostapd /path/to/the/above/conf/file
Using interface wlan0 with hwaddr 00:1e:2a:xx:xx:xx and ssid 'alf-linux'

You will see some message like above if it was successful
Next we have to set ip address for our wlan0 interface, i am gonna use 192.168.27.1 static ip
 
$ ifconfig wlan0 192.168.27.1 up

Next step, we have to set up dhcp server which listens on wlan0 interface
i am gonna use udhcpd server for that, so install from ur distro repo

To enable udhcp server, edit the file /etc/default/udhcpd
     #DHCPD_ENABLED="no"
comment this line to enable the server,

edit the file /etc/udhcpd.conf
start 192.168.27.2
end 192.168.27.254 

since i set ip 192.168.27.1 for my wlan0, 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

Hope u know how to connect with existing network for ur other interface using command line
Next we have to enable ip forwarding
 
$ echo "1" > /proc/sys/net/ipv4/ip_forward

Next, use iptables to do NAT(Network Address Translation)
 
$ iptables --table nat --append POSTROUTING --out-interface wlan1 -j MASQUERADE
$ iptables --append FORWARD --in-interface wlan0 -j ACCEPT

here wlan1 is connected to internet
wlan0 is our access point
=======================================================================================================================
wlan1 - use it for connecting to a existing wireless network
my existing wireless infrastructure in our college campus uses wpa2 enterprise encryption
use wpa_supplicant to connect to existing wireless access point
here is my wpa_supplicant.conf content

ctrl_interface=/var/run/wpa_supplicant
network={ 
ssid="kcc-wifi" 
key_mgmt=WPA-EAP 
eap=PEAP identity="****" 
password="***********" 
phase1="peaplabel=0" 
phase2="auth=MSCHAPV2" 
}
 
$ wpa_supplicant -i wlan1 -c /etc/wpa_supplicant.conf

To pull ip address, i am using udhcpc client,
 
$ udhcpc -i wlan1

So in my case, i have internet connection in my wlan1 interface
thats been shared thro wlan0 interface
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The same thing can be done with single wireless interface card.
create a virtual interface for ur existing wireless interface using iw command
remaining are same.

Post Navigation