Jex’s Note

設定無線網路

安裝 wpa client

sudo apt-get install wireless-tools wpasupplicant

掃描無線網路

sudo iwlist wlan0 scan | grep SSID
                    ESSID:"hinet-net4690695"
                    ESSID:"BUFFALO-E05EE0"
                    ESSID:"BUFFALO-E05EE0-1"
                    ESSID:"kking22"
                    ESSID:"TP-LINK_5499B2"
                    ESSID:"HTC ONE X - Jex"
                    ESSID:"P880"

等等要將 SSID 填入 /etc/network/interfaces wpa-ssid 的值

新增 /etc/network/interfaces :

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp


auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid My-Hone-Wireless
wpa-psk My-Password
  • SSID 就是無線網路的名稱
  • WPA-PSK金鑰 就是無線網路的密碼

重新啟動無線網路介面

sudo ifdown wlan0
sudo ifup wlan0

成功連線的結果 :

pi@raspbmc:~$ sudo ifdown wlan0
ifdown: interface wlan0 not configured
pi@raspbmc:~$ sudo ifup wlan0
ioctl[SIOCSIWAP]: Operation not permitted
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
Internet Systems Consortium DHCP Client 4.2.2
Copyright 2004-2011 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/00:0b:81:84:7a:17
Sending on   LPF/wlan0/00:0b:81:84:7a:17
Sending on   Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 4
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 11
DHCPREQUEST on wlan0 to 255.255.255.255 port 67
DHCPOFFER from 192.168.1.1
DHCPACK from 192.168.1.1
Reloading /etc/samba/smb.conf: smbd only.
bound to 192.168.1.10 -- renewal in 38644 seconds.

以下是我實體網路線及無線網路都有連線的結果

pi@raspbmc:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:7e:6e:3f
          inet addr:192.168.1.236  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::ba27:ebff:fe7e:6e3f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3168 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2190 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:443833 (433.4 KiB)  TX bytes:375591 (366.7 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:480 (480.0 B)  TX bytes:480 (480.0 B)

wlan0     Link encap:Ethernet  HWaddr 00:0b:81:84:7a:17
          inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20b:81ff:fe84:7a17/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:28 errors:0 dropped:2179 overruns:0 frame:0
          TX packets:51 errors:0 dropped:3 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:31439 (30.7 KiB)  TX bytes:36803 (35.9 KiB)

其他

如果將無線網路登入設定寫在 interfaces 裡面的一些設定寫法

/etc/network/interfaces 的寫法 :

wpa-scan-ssid 1
wpa-ap-scan 1
wpa-key-mgmt WPA-PSK
wpa-proto RSN WPA
wpa-pairwise CCMP TKIP
wpa-group CCMP TKIP
wpa-ssid "My Secret SSID"
wpa-psk "My SSID PSK"

另外一種連線設定, 使用 wpa_supplicant

/etc/network/interfaces :

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

/etc/wpa_supplicant/wpa_supplicant.conf 新增(沒有的話建立)

完整寫法 :

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
  ssid="wireless_1"                                                     // 無線網路的名稱
  #scan_ssid=1
  proto=WPA RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP TKIP
  group=CCMP TKIP
  psk=ec8cdd1c0aa2ebcc6564ee81587ebad81e4a39ebf6c4265e3f931175e3926c5b  // 無線網路的密碼(加密後) 寫法1
  # psk="my_password"   // 無線網路的密碼(未加密) 寫法2
}

偷懶寫法 :

network={
  ssid="TP-LINK_34403E"
  psk="2734403E"
  id_str="home"
}
network={
  ssid="jx"
  psk="00000000"
  id_str="my mobile"
}

不將明碼打在設定檔上, 使用加密後的密碼在設定檔裡較為安全

$ wpa_passphrase jex_ssid jex_password
network={
        ssid="jex_ssid"
        #psk="jex_password"
        psk=fce88e792dea2299472529eea209012a812cda28cbbf540e2a55d45be98988d0
}

加密協定

  • TKIP 與 CCMP 為安全加密協定
  • 有些無線網路設備以 AES 或 AES-CCMP 來表示 CCMP
  • AES 效能更好, 主流, 安全, 美國主推, 在 wifi 上用來取代 TKIP, 雙向加密解密

Comments