Pages

Sunday, October 2, 2011

Make Your Ubuntu Box as your Personal WiFi Hotspot / Wifi Router



First of all, we have to be sure weather the wifi card supports host mode or master mode. While most of the wifi module support this , there is no guaranty that every card will have this feature.

To be sure, we can install iw package to check the wifi card does have master / host mode or not.

$ sudo apt-get install iw


Typing the above command in a terminal will install iw package. Now type the following in the terminal.

$ iw list

This shows the a full technical details of your wifi card. A sample output of the command is as follows.

Wiphy phy0
    Band 1:
        Capabilities: 0x11ce
            HT20/HT40
            SM Power Save disabled
            RX HT40 SGI
            TX STBC
            RX STBC 1-stream
            Max AMSDU length: 3839 bytes
            DSSS/CCK HT40
        Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
        Minimum RX AMPDU time spacing: 8 usec (0x06)
        HT TX/RX MCS rate indexes supported: 0-15
        Frequencies:
            * 2412 MHz [1] (15.0 dBm)
            * 2417 MHz [2] (15.0 dBm)
            * 2422 MHz [3] (15.0 dBm)
            * 2427 MHz [4] (15.0 dBm)
            * 2432 MHz [5] (15.0 dBm)
            * 2437 MHz [6] (15.0 dBm)
            * 2442 MHz [7] (15.0 dBm)
            * 2447 MHz [8] (15.0 dBm)
            * 2452 MHz [9] (15.0 dBm)
            * 2457 MHz [10] (15.0 dBm)
            * 2462 MHz [11] (15.0 dBm)
            * 2467 MHz [12] (15.0 dBm) (passive scanning)
            * 2472 MHz [13] (15.0 dBm) (passive scanning)
            * 2484 MHz [14] (15.0 dBm) (passive scanning)
        Bitrates (non-HT):
            * 1.0 Mbps
            * 2.0 Mbps (short preamble supported)
            * 5.5 Mbps (short preamble supported)
            * 11.0 Mbps (short preamble supported)
            * 6.0 Mbps
            * 9.0 Mbps
            * 12.0 Mbps
            * 18.0 Mbps
            * 24.0 Mbps
            * 36.0 Mbps
            * 48.0 Mbps
            * 54.0 Mbps
    max # scan SSIDs: 4
    max scan IEs length: 2257 bytes
    Coverage class: 0 (up to 0m)
    Supported Ciphers:
        * WEP40 (00-0f-ac:1)
        * WEP104 (00-0f-ac:5)
        * TKIP (00-0f-ac:2)
        * CCMP (00-0f-ac:4)
        * CMAC (00-0f-ac:6)
    Available Antennas: TX 0x3 RX 0x3
    Configured Antennas: TX 0x3 RX 0x3
    Supported interface modes:
         * IBSS
         * managed
         * AP
         * AP/VLAN
         * WDS
         * monitor
         * mesh point
         * P2P-client
         * P2P-GO
    software interface modes (can always be added):
         * AP/VLAN
         * monitor
    valid interface combinations:
         * #{ managed, WDS, P2P-client } <= 2048, #{ AP, mesh point, P2P-GO } <= 8,
           total <= 2048, #channels <= 1
    Supported commands:
         * new_interface
         * set_interface
         * new_key
         * new_beacon
         * new_station
         * new_mpath
         * set_mesh_params
         * set_bss
         * authenticate
         * associate
         * deauthenticate
         * disassociate
         * join_ibss
         * join_mesh
         * remain_on_channel
         * set_tx_bitrate_mask
         * action
         * frame_wait_cancel
         * set_wiphy_netns
         * set_channel
         * set_wds_peer

Now look at the section "Supported interface mode" . If the list contains AP or AP/VLAN , then your wifi card supports master mode or host mode and you can proceed with this guide.

Step 1:
We will use hostapd package to use the wifi card as router /access point.


$ sudo apt-get install hostapd

After installing hostapd, we have to create or edit the hostapd configuration file which is located at /etc/hostapd/hostapd.conf .

$ sudo gedit   /etc/hostapd/hostapd.conf

Comment out all the existing entries and add the following lines.

interface=wlan0
driver=nl80211
ssid=your_ssid_name
hw_mode=g
auth_algs=1
wpa=2
wpa_passphrase=your_pass_phrase
wpa_pairwise=TKIP CCMP
wpa_key_mgmt=WPA-PSK
channel=1
rsn_pairwise=CCMP

Step 2:
We need to install a dhcp server and configure it for wlan0. I have noticed the default dhcp server (dhcp3) has issue with hostapd. So I just uninstalled the default dhcp client and installed dnsmasq . This is really awesome application. dnsmasq works as a server as well as a client. It is also very easy to configure.

$ sudo apt-get purge dhcpd  
$ sudo apt-get install dnsmasq

Now we will edit the default dnsmasq parameters in /etc/default/dnsmasq .

$ sudo gedit /etc/default/dnsmasq

The file should only contain the following.


DNSMASQ_OPTS=" -conf-file=/etc/dnsmasq.conf"

Save it . Now we will create a config file  /etc/dnsmasq.conf so that it gives the ip address to clients which tries to connect to hosted wifi access point.

$ sudo gedit /etc/dnsmasq.conf

Comment out all the existing entries add the following at the end of the file .

interface=wlan0
dhcp-range=192.168.0.2,192.168.0.127,12h

Save it.

Step3:

We have now setted up every thing to make our ubuntu box as wifi access point / wifi router.

Now we will create an executable script  say /usr/bin/wifi_ap so that we can run it as a command.
Add the following lines in /usr/bin/wifi_ap .

#!/bin/bash
# broadcasting interface
BROADCAST="wlan0"
BROADCASTIP="192.168.0.1"

# receiving interface broadcast is connected to. 
# put the correct interface name here. It is the network interface  
# which is connected to internet and whose connection is going to be 
#shared over wifi. E.g  for internal 3g slot it is "hso0" , for ethernet it is
#"eth0", for ppp it is "ppp0"
#For me it is an internal 3g slot .

RECEIVE="hso0"

if [[ $1 == "-0" || $1 == "--start" ]]
   then
      ## start hostapd

      echo "Starting hostapd"
      echo "You can view the log at /var/log/hostapd.log"
      sleep 1
 
      # launch hostapd daemon
 
      hostapd -d /etc/hostapd/hostapd.conf > /var/log/hostapd.log &
      echo "hostapd started.."
 
      ## start dhcp server; We are making sure that currently dnsmasq is not 
      #running by any other application. So before starting dnsmasq, we are 
      #trying to stop any previous session.

      echo "Stopping previous dhcp session"
      /etc/init.d/dnsmasq stop
      killall -2 dnsmasq
 
      echo "Starting dnsmasq DHCP Server on wlan0"
 
      # set IP address

      ifconfig $BROADCAST $BROADCASTIP
      sleep 2

      # launch dnsmasq dhcp  daemon
      #echo "INTERFACES=$BROADCAST" > /etc/default/dhcp
 
      dnsmasq  --conf-file=/etc/dnsmasq.conf
      sleep 1
      echo "DHCP Server Started..."

elif [[ $1 == "-1" || $1 == "--stop" ]]
   then
      # send signal 2 to hostapd and dnsmasq
      echo "Stopping DHCP Server..."
      sleep 1
      /etc/init.d/dnsmasq stop
      echo "DHCP server stopped..."
      sleep 1
      echo "Killing hostapd, dnsmasq"
      killall -2 hostapd dnsmasq
      sleep 1
      echo "All process killed.."
elif [[ $1 == "-2" || $1 == "--ics" ]]
   then
      echo "Starting Internet connection sharing..."
      # create iptables rules
      iptables -A FORWARD -i $RECEIVE -o $BROADCAST -s 192.168.0.1/24 -m conntrack --ctstate NEW -j ACCEPT
      iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
      iptables -A POSTROUTING -t nat -j MASQUERADE
      # set kernel variable(s)
      echo 1 > /proc/sys/net/ipv4/conf/all/forwarding
      # edit kernel configuration
      cp /etc/sysctl.conf /etc/sysctl.conf.ap_ctl
      echo "net.ipv4.conf.default.forwarding=1" >> /etc/sysctl.conf
      echo "net.ipv4.conf.all.forwarding=1" >> /etc/sysctl.conf
      sleep 1
      echo "Internet connection is now shared over wifi..."
      echo ""

     # To stop internet sharing
  
 elif [[ $1 == "-3" || $1 == "--noics" ]]
   then
      echo "Stopping Internet connection sharing..."
      # remove iptables rules
      iptables -D FORWARD 1
      iptables -D FORWARD 1

      # set kernel variable(s)
      echo 0 > /proc/sys/net/ipv4/conf/all/forwarding

      # revert kernel configuration
      mv -i /etc/sysctl.conf.ap_ctl /etc/sysctl.conf

      # restart networking
      #/etc/init.d/networking restart
      sleep 1
      echo "Internet connection sharing stopped..."
 else
 echo $0
 echo "A tool to manage hostapd and dnsmasq DHCP server"
 echo "Usage:"
 echo "    -0 --start    Start hostapd and dhcpd3"
 echo "    -1 --stop    Stop hostapd and dhcpd3 with signal 2"
 echo "    -2 --ics    Activate internet connection sharing"
 echo "            between specified interfaces"
 echo "    -3 --noics    Undo internet connection sharing settings"
 fi

exit 0 

Save it.  Exit the text editor. Now run

$ sudo chmod a+x /usr/bin/wifi_ap

Now you can run this script as command. This script has 4 options i.e  start , stop , ics and noics .

To start the hostspot , you should run

$ sudo wifi_ap --start

To stop the hostspot ,  you can run

$ sudo wifi_ap --stop

To share internet  connection over the hostspot

$ sudo wifi_ap --ics

To stop sharing internet connection ,

$ sudo wifi_ap --noics.  

Hope you enjoy it.



Wednesday, July 13, 2011

Start Up Repair in windows 7

Most of us faced the Windows 7 typical problem of Star Up Error. And the Graphical Start up repair tools fails to repair the boot loader after a long try. Don't panic.We can easily solve this problem and avoid a fresh install. Follow the following steps.

  1. Get your Windows 7 installation disk. If your PC does not have a cd drive then get an 8GB USB Flash drive and follow the step no. 13.
  2. Insert the Windows 7 installation disk in th dvd drive.
  3. Boot from DVD.
  4. Now chose “Repaire your computer”
  5. Windows setup will automatically start repairing the start up problem.
  6. Wait until it fails.
  7. Open command prompt.
  8. Type “Y:” then Press “Enter”. (Y is your drive letter for dvd drive. Chage it according to your machine. If you are not sure about the drive letter then type “diskpart” and press “Enter”. Now type :
list disk ⏎ It will list the available harddisks.
select disk 0 ⏎
list volumes ⏎ It will list the volumes of the selected disk as well as your dvd drive. Now identify your dvd drive's drive letter.)

  1. Now type “ CD boot” and Press “Enter”.
  2. Type the following commands .
    Bootrec.exe /FixMbr ⏎
    Bootrec.exe /FixBoot ⏎
    Bootsect.exe /nt60 all /force ⏎
  3. Now you are done. You can now reboot into Windows.
  4. If you want to completely rebuild Windows 7 Configuration Data, then you should issue the following command:
        Bootrec.exe /RebuildBcd ⏎

This command scans all disks for installations that are compatible with Windows 7. Additionally, this option also allows select the installations that you want to add to the Boot Configuration Data store.

  1. Download WinToFlash from here.
  2. Download Magic Disk from  here
  3. Install Magic Disk and setup a virtual cd rom.
  4. Mount your Windows 7 installation Cd image in the virtual cd rom.
  5. Insert your 8GB USB Flash drive.
  6. Fire Up WinToFlash and follow the wizard.
  7. Select your virtual cd rom as windows installation source.
  8. Select your USB Flash Drive as destination and complete the wizard.
  9. Boot your pc from the USB Flash Drive.
  10. Go to Step 4.

Tuesday, July 12, 2011

ZTE MF112 7.6 3G MODEM ZCDRUN PROBLEM

Hi all,

Recently I bought a 3g modem ZTE MF112 and found strange problem. The card reader was not enable. The flash drive containing the modem driver will not be mounted. After a lot of search over the internet I found easy solution to this. What I deed as follows.

1. I downloaded the driver from http://mymobile.three.co.uk:8080/mbb/ZTE/MF112/main.html

2. I installed the driver (off cource on Windows! On my ubuntu natty it was just working out of the box !! ) and found an NEMA interface on COM6.

3. I downloaded Terra Term ( An SSH client. You can try Putty also..) from http://www.ayera.com/teraterm/

4. Run Tera Term .

5. Create an ssh connection through com port 6 ( NEMA Interface . You have to connect ZTE MF 112 .)

6. Now open notepad and write the following

AT+ZCDRUN=8 or AT+ZCDRUN=F

7. Copy the same .

8. Then paste the content on TERRA TERM console.

9. You will get a success message. And You are done!

10. Remove your ZTE MF112 and re insert . Viola you have the card reader working as well as the flash driver for driver auto install.