Access Point from WiFi Stick

belkinBefore going to vacation I realized that I only have computer which is connected directly to internet and no WiFi at all available at the location of my vacation. At home I have an old Belkin WiFi stick which I thought to through away several times and kept forgetting. I felt that this stick would be useful for connecting my smartphone via WiFi at my vacation location. Well, I simply didnt know how to do it. But this time I decided to investigate the possibility. To make things short – I made it and apparently all process is not difficult at all.

Before continue I must describe my circumstances – old PC with Linux Mint 15 (Ubuntu based), old Belkin WiFi stick like the one on photograph, ppp connection via cable. Belkin device has default address wlan0 and ppp connection is ppp0
1. I installed DHCP server and hostapd on computer with command:
sudo apt-get update && apt-get install dhcp3-server hostapd

2. I created a file, in my home folder, called hostapd.conf with following content:
interface=wlan0
driver=nl80211
ssid=dontMessWithVincentValentine

hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=KeePGuessinG
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

3. I have setup DHCP server by editing file /etc/dhcp/dhcpd.conf
ddns-update-style none;
ignore client-updates;
authoritative;
option local-wpad code 252 = text;

subnet
10.0.0.0 netmask 255.255.255.0 {
# — default gateway
option routers
10.0.0.1;
# — Netmask
option subnet-mask
255.255.255.0;
# — Broadcast Address
option broadcast-address
10.0.0.255;
# — Domain name servers, tells the clients which DNS servers to use.
option domain-name-servers
10.0.0.1, 8.8.8.8, 8.8.4.4;
option time-offset
0;
range 10.0.0.3 10.0.0.13;
default-lease-time 1209600;
max-lease-time 1814400;
}
DO NOT FORGET TO BACKUP ORIGINAL FILE – do: sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak before editing it’s content.

4. Created a script to start access point:
#!/bin/bash
#Initial wifi interface configuration
ifconfig wlan0 up 10.0.0.1 netmask 255.255.255.0
sleep 2
###########Start DHCP, comment out / add relevant section##########
#Thanks to Panji
#Doesn’t try to run dhcpd when already running
if [ “$(ps -e | grep dhcpd)” == “” ]; then
dhcpd wlan0 &
fi
###########
#Enable NAT
iptables –flush
iptables –table nat –flush
iptables –delete-chain
iptables –table nat –delete-chain
iptables –table nat –append POSTROUTING –out-interface ppp0 -j MASQUERADE
iptables –append FORWARD –in-interface wlan0 -j ACCEPT

#Thanks to lorenzo
#Uncomment the line below if facing problems while sharing PPPoE, see lorenzo’s comment for more details
#iptables -I FORWARD -p tcp –tcp-flags SYN,RST SYN -j TCPMSS –clamp-mss-to-pmtu

sysctl -w net.ipv4.ip_forward=1
#start hostapd
hostapd -B /home/myuser/hostapd.conf 1>/dev/null

I have named this file startap and made it executable by sudo chmod +x startap

After starting this file you should see your wifi access point on your smartphone. Remember that this script must be run with super user permissions – sudo …

5. Last optional thing was I made this script to run on startup of my computer: I copied my file to /etc/init.d folder, then I run the following command: sudo update-rc.d startap defaults

After restart my access point was there.

Materials taken from http://nims11.wordpress.com/2012/04/27/hostapd-the-linux-way-to-create-virtual-wifi-access-point/

Bookmark and Share
Here can be your banner, contact me about conditions.