Academia.eduAcademia.edu

Linux-wireless; hotspot, connecting to AP from cmd

Connect to an AP #linux #wireless #internet #command line 1. Make sure your WiFi hardware is detected and corresponding driver is loaded. The driver should be written in newer nl80211 than wext and shall support have mac80211. Start wpa_supplicant: wpa_supplicant ­Dnl80211 ­c /path/to/wpa_supplicant.conf ­i wlan0 ­B 1. wpa_cli > scan > scan_results > add_network ­ this will display an “id” > set_network id ssid “My­AP­Name” > set_network id psk “password” > all the auth, association, security protocols should be auto loaded from scan­results > enable_network id ­ This should be enough ­ The supplicant automatically start to authenticate and then the chain of association, security and final connection establishment processes get executed. 2. Now you have a physical layer connection with the AP 3. To have a managed network, you need dhcp_server running on the AP 4. Now, send a DHCPDISCOVER and initiate DHCP IP obtain process as a client. > dhcclient wlan0 SW AP https://wiki.archlinux.org/index.php/Software_access_point https://wiki.archlinux.org/index.php/Internet_sharing http://nims11.wordpress.com/2012/04/27/hostapd­the­linux­way­to­create­virtual­wifi­access­p oint/ Make a hotspot on your linux PC 1. Let $1 be your wifi interface, say wlan0 sudo iw dev $1 interface add sta0 type station sudo ip link set dev sta0 address 12:34:56:78:ab:cd sudo iw dev $1 interface add ap0 type __ap sudo ip link set dev ap0 address 12:34:56:78:ab:ce 1. sudo hostapd hostap_urs.conf hostapd_urs.conf: ssid=UnnisLinuxSW­AP wpa_passphrase=unni1234 interface=ap0 #bridge=br0 auth_algs=3 channel=1 driver=nl80211 hw_mode=g logger_stdout=­1 logger_stdout_level=2 max_num_sta=5 rsn_pairwise=CCMP wpa=2 wpa_key_mgmt=WPA­PSK wpa_pairwise=TKIP CCMP 1. Internet Sharing from your internet providing interface, say eth0: #sudo ip link set up dev $1 #sudo ip addr add 192.168.55.1/24 dev $1 # arbitrary address sudo sysctl net.ipv4.ip_forward=1 sudo sysctl net.ipv6.conf.default.forwarding=1 sudo sysctl net.ipv6.conf.all.forwarding=1 #sudo iptables ­t nat ­A POSTROUTING ­o eth0 ­j SNAT ­­to­source 192.168.55.1 sudo iptables ­t nat ­A POSTROUTING ­o eth0 ­j MASQUERADE sudo iptables ­A FORWARD ­i $1 ­o eth0 ­j ACCEPT sudo iptables ­A FORWARD ­m conntrack ­­ctstate RELATED,ESTABLISHED ­j ACCEPT sleep 3 echo "configuring IP up" sudo ifconfig ap0 192.168.55.1 netmask 255.255.255.0 up sleep 3 echo "starting DHCP server" sudo touch /var/run/dhcpd.pid sudo chmod 777 /var/run/dhcpd.pid sudo dhcpd DHCP configuration file: #dhcpd.conf START DHCPDARGS=ap0; # Set some defaults for lease time and DNS update method ddns­update­style none; default­lease­time 6000000; max­lease­time 72000000; # Set the subnet mask for the wireless IP network option subnet­mask 255.255.255.0; # Set the Broadcast address. This will be 10.x.x.255, # the "x.x" will depend upon the network assigned to you by NZWireless. option broadcast­address 192.168.55.255; # Set the router address, this will be 10.x.x.1, the address # of your wireless interface WLAN0 option routers 192.168.55.1; # Set the Name Server address. This will be the same as your WLAN0 address # because we intend to run DNS on this machine. option domain­name­servers 8.8.8.8; # Set the default domain name for clients on this network. # i.e. the DNS domain assigned to you by your wireless administrator. option domain­name "pp.org"; # Allocate a network range for dynamic IP addresses to hand out to clients. # Again, this range will be in 10.x.x.x, depending upon the network allocated # to you by your wireless administrator. subnet 192.168.55.0 netmask 255.255.255.0 { range 192.168.55.10 192.168.55.100; option subnet­mask 255.255.255.0; # Default subnet mask to be used by DHCP clients option broadcast­address 192.168.55.255; # Default broadcastaddress to be used by DHCP clients option routers 192.168.55.1; # Default gateway to be used by DHCP clients option domain­name "pp.org"; #on commit { #set clip = binary­to­ascii(10, 8, ".", leased­address); #set clhw = binary­to­ascii(16, 8, ":", substring(hardware, 1, 6)); #execute("/usr/share/dhcp_fifo.sh", clip); #} } #dhcpd.conf START Done! Now from your phone: 1. Say Android: connect to UnnisLinuxSW­AP with password unni1234 Then: In Advanced Options: Set Static IP: 192.168.55.251 NetMAsk: 255.255.255.0 DNS: 8.8.8.8 Cool.. Done and get your connection and Internet..