Wednesday, November 21, 2012

command line to connect wifi in Linux


=============== WPA only ============
step 1:
ifconfig wlan0 up
wpa_passphrase yournetworkessid passphrase > /opt/wpa_configure.conf

step 2, vi to edit more info into it:   (vi quick guide: start "vi filename" then press "i" for insert mode, after edit press ESC for cmd mode, type :w to write, :q to quit)
ssid=yournetworkessid
      proto=WPA
      key_mgmt=WPA-PSK
      pairwise=TKIP
      group=TKIP
      psk=f242925f83787084d58101d5eb52485989e2a553983bfe6fc5b8d27fdfa063bd

step 3, connect:
wpa_supplicant -iwlan0 -c/opt/wpa_configure.conf &

step 3, dhcp to get IP:
udhcpc -i wlan0

=============== WEP only =============
Tools to use:
ifconfig: Enable your wireless device.
iwlist: List the available wireless access points.
iwconfig: Configure your wireless connection.
dhclient: Get your IP address via dhcp.


Step 1: enable your wifi device (ifconfig wlan0 down)
ifconfig wlan0 up

Step 2: scan wifi network
iwlist wlan0 scan

Step 3: connect to the wifi (WEP only) network
iwconfig wlan0 essid NETWORK_ID key s:WIRELESS_PASSWORD

Step 4: dhcp to get IP address
udhcpc -i wlan0
OR dhclient wlan0

manual IP, gateway:
ifconfig wlan0 192.168.1.9 netmask 255.255.255.0 up
route add default gw 192.168.1.1

============== to change mac address ========

ifconfig eth0 down hw ether 00:00:00:00:00:01
ifconfig eth0 up