網頁

2017年6月15日 星期四

Raspberry Pi 網路設定

/etc/network/interfaces
---------------------------------
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
---------------------------------

/etc/wpa_supplicant/wpa_supplicant.conf
---------------------------------
country=TW
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
  ssid="SSID2"
  psk="password"
  key_mgmt=WPA-PSK
  priority=2
  id_str="id_SSID2"
}

network={
  ssid="SSID1"
  key_mgmt=NONE
  priority=1
  id_str="id_SSID1"
}
---------------------------------

/etc/dhcpcd.conf
---------------------------------
nohook lookup-hostname

interface eth0
static ip_address=192.168.1.61
netmask 255.255.255.0
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

interface wlan0
SSID DigiChance
static ip_address=192.168.1.60
netmask 255.255.255.0
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
---------------------------------

iwconfig wlan0 #查看目前無線網路設定
iwlist wlan0 scan #掃描無線網路
ifdown wlan0 #停用無線網路
ifup wlan0 #啟動無線網路


ssh 預設帳號
pi/raspberry


2017年5月24日 星期三

Arduino Yun 網路

Arduino Yun 也可同時啟動 AP+STA 模式,但測試時花了很多時間
因為 Arduino Yun 真的比 Linkit 7688 慢很多

回復AP模式或出廠值
1. 使用 WLAN 按鈕
按5秒,wifi 回AP模式 SSID=Arduino-Yun-XXXXXXXXXXXX, IP=192.168.240.1
按30秒,linux 環境回復出廠值,清除板上的 Flash 記憶體
2. 登入作業系統,使用命令
wifi-reset-and-reboot
reset-to-factory-anyway

wifi-reset-and-reboot 中加入下一行,才能正確回復AP模式
$UCI "delete" "wireless.@wifi-iface[1]"

設定檔位於 /etc/config
dhcp, network, wireless, firewall

使用網頁 (Arduino Luci)設定,新增 Wi-Fi Station 網路
Network/Wifi/Scan
Join Network
取消勾選 An additional network will be created if you leave this unchecked.
沒有取消勾選,會導致 AP 網路被取消掉

uci set wireless.@wifi-iface[1].ssid='DigiChance'
uci set wireless.@wifi-iface[1].key='xxxxx'
uci set wireless.@wifi-iface[1].encryption='psk2'
uci set wireless.@wifi-iface[1].bssid='B8:55:10:56:05:20'
uci commit wireless

uci set network.wwan.proto='static'
uci set network.wwan.ipaddr='192.168.1.60'
uci set network.wwan.netmask='255.255.255.0'
uci set network.wwan.gateway='192.168.1.1'
uci set network.wwan.dns='192.168.1.1'
uci commit network

修改完執行
/etc/init.d/network restart

相關命令
wifi up
wifi down
wifi status
ifconfig
ifconfig eth1 up
ifconfig eth1 down
ifconfig eth1 192.168.1.61 netmask 255.255.255.0
ifup EWAN // 參考 /etc/config/network
ifdown EWAN // 參考 /etc/config/network

同時啟動 ap+sta 模式,網路不用密碼,使用 MAC filter,會出問題,一直找不到如何解決
1. 不用密碼命令
uci set wireless.@wifi-iface[1].encryption='none'
2. MAC filter 似乎會檢查 BSSID
uci set wireless.@wifi-iface[1].bssid='B8:55:10:56:05:20'
3. 切開不同的網段,似乎能解決問題,但不同網段
uci set network.wwan.ipaddr='192.168.3.60'

若開機時沒接上有線網路,會導致無線網路開不起來
停止網路
uci set network.EWAN.auto='0'
開機後(無線網路啟動後)再啟動有線網路
編輯 /etc/rc.local
加入
ifconfig eth1 192.168.1.61 netmask 255.255.255.0
或
ifup wan
ifup EWAN

uci delete wireless.@wifi-iface[1]
uci add wireless wifi-iface
uci set wireless.@wifi-iface[1].network='wwan'
uci set wireless.@wifi-iface[1].device='radio0'
uci set wireless.@wifi-iface[1].mode='sta'
uci set wireless.@wifi-iface[1].ssid='DigiChance'
uci set wireless.@wifi-iface[1].key='22463458'
uci set wireless.@wifi-iface[1].encryption='psk2'
uci set wireless.@wifi-iface[1].bssid='B8:55:10:56:05:20'
uci commit wireless

uci delete network.wwan
uci add network interface
uci rename network.@interface[-1]='wwan'
uci set network.wwan._orig_ifname='wlan0-1'
uci set network.wwan._orig_bridge='false'
uci set network.wwan.proto='static'
uci set network.wwan.ipaddr='192.168.1.60'
uci set network.wwan.netmask='255.255.255.0'
uci set network.wwan.gateway='192.168.1.1'
uci set network.wwan.dns='192.168.1.1'
uci commit network

uci delete network.ewan
uci add network interface
uci rename network.@interface[-1]='ewan'
uci set network.ewan.ifname='eth1'
uci set network.ewan._orig_ifname='eth1-1'
uci set network.ewan.proto='static'
uci set network.ewan.ipaddr='192.168.1.61'
uci set network.ewan.netmask='255.255.255.0'
uci set network.ewan.gateway='192.168.1.1'
uci set network.ewan.dns='192.168.1.1'
uci commit network

wifi-reset-and-reboot 中加入
$UCI "delete" "wireless.@wifi-iface[1]"

2017年5月17日 星期三

Linkit 7688 網路-非 Bridge

以下設定透過有線和無線連接外網,並同時啟動 Wifi Ap mode
但是不可以同時連接同一路由器網段
如 192.168.1.60, 192.168.1.61
此時會有一個網路無法連接
故使用 192.168.1.60, 192.168.2.61
Wifi Ap 使用 192.168.100.1

新增對外有線網路
Network/Interfaces/Add new interface...
Name: EWAN
Protocol: Static address (192.168.2.61)
Interface: Ethernet Switch: "eth0"
Firewall Settings: wan

取消 Bridge
Network/Interfaces/LAN/Physical Settings
取消勾選 Bridge interfaces
選擇 Wireless Network: Master "LinkIt_Smark_7688_xxxxxx"
Static address(192.168.100.1)

此時網路(EWAN)生效

修改 Wifi 之 UplinkAp
Network/Wifi/radio0: Client "UplinkAp"
修改 ESSID: router
新增對外無線網路
Network/Interfaces/Add new interface...
Name: WWAN
Protocol: Static address (192.168.1.60)
Interface: Wireless Network: Client "router"
Firewall Settings: wan
使用終端機登入
root@mylinkit:~# wifi_mode apsta

Network/Interfaces/LAN
Protocol: static address (192.168.100.1)
取消 Disable DHCP for this interface

修改 WWAN 的 gateway 和 DNS

Linkit 7688 預設網路 & Bridge

先說說 Bridge 吧!
一般來說,網路使用路由器形成階層
Bridge 可以使中間的路由器通透,直接連上上層網路,扁平化網路

Linkit 7688 Wi-Fi 預設為 AP 模式,並且啟動 Bridge
因為 WAN 指定到 Wireless Network: Client "UplinkAp", 並沒有連上網路
所以不論透過有線或無線的網路登入,皆可透過同一IP 192.168.100.1 登入
此時沒有連上外網
設定如下
Network/Interfaces/WAN/General Setup/Protocol: DHCP client
Network/Interfaces/WAN/Physical Settings
選定 Wireless Network: Client "UplinkAp" (wan)

Network/Interfaces/LAN/General Setup/Protocol
Static address: 192.168.100.1
Network/Interfaces/LAN/Physical Settings
啟動 Bridge interface
勾選
Ethernet Switch: "eth0" (lan)
Ethernet Adapter: "ra0" (lan)
Wireless Network: Master "LinkIt_Smart_7688_xxxxxx" (lan)

設定使用有線網路(Ethernet),連接外網
Network/Interfaces/WAN/Physical Settings
改選
Ethernet Switch: "eth0"
此時 LAN 上的 Bridge 還有效,所以有線網路還是 192.168.100.1
Network/Interfaces/LAN/Physical Settings
取消勾選
Ethernet Switch: "eth0"
此時有線網路才會生效,因為是使用 DHCP client, 所以需透過路由器查詢 IP
可透過 LinkIt_Smark_7688_xxxxxx 登入(192.168.100.1)
並且 ping 路由器和外網,以證明成功

回復出廠值
設定使用無線網路(WiFi),連接外網
Network/Wifi
不要點選 Scan/Join Network, 會取消 LinkIt_Smart_7688_xxxxxx, 轉入 station mode
建議編輯 UplinkAp
Network/Wifi/radio0: Client "UplinkAp"
設定: ESSID, Mode 選 Client, 設定 Wireless Security
可參考設定檔 /etc/config/network /etc/config/wireless
執行 wifi_mode sta 切換成 Station mode
所以 LinkIt_Smark_7688_xxxxxx 會消失
可透過有線網路登入(192.168.100.1)
並且 ping 路由器和外網,以證明成功

Wi-Fi 設定為 Ap + Station mode
執行 wifi_mode apsta 切換成 Ap + Station mode
因為此時
Network/Interfaces/LAN/General Setup/Protocol 自動切換為 DHCP client
Network/Interfaces/LAN/Physical Settings 有啟動 Bridge
所以 client 可以透過有線連上 LinkIt 7688 的上層網路
client 也可透過 LinkIt_Smark_7688_xxxxxx 連上 LinkIt 7688 的上層網路
因為 LinkIt 是使用 DHCP client 連接外網, 所以需透過路由器查詢 IP
再透過此 IP 連上 LinkIt 7688
當然你可將
Network/Interfaces/LAN/General Setup/Protocol 切換為 Static address
可以注意一下 Network/Interfaces/WAN 已經不能 Edit


Linkit 7688 起步

電源燈: 綠色表示供電中
Wi-Fi燈: 橘色
  AP Mode: 沒 client 連線,暗
  AP Mode: 有 client 連線,一秒閃三次,暫停5秒,重複
  Station Mode: 沒連線,暗
  Station Mode: 連線中,一秒閃兩次
  Station Mode: 已連線,有資料傳輸,則閃爍


Wi-Fi Reset 按鈕
Resets Wi-Fi to AP mode: 壓按鈕至少5秒
Factory resets and enters AP mode: 壓按鈕至少20秒
(Restore to default setting and all user data will be removed from the device)
Upgrades firmware from a USB drive:
A. 供電時壓按鈕至少5秒
1. 下載 lks7688.img 置於 FAT32 Usb drive 的根目錄
2. 插上 USB drive, 可以透過 OTG 線, 或 Breakout 板
3. 壓住 Wi-Fi Reset 按鈕
4. 壓一下 MPU Reset 按鈕
5. 數約5秒後放開 Wi-Fi Reset 按鈕(等 Wi-Fi 燈暗)
6. Wi-Fi 燈,快閃約3分鐘
7. 等機器重開機
Upgrades bootloader from a USB drive:
A. 供電時壓按鈕至少20秒
1. 下載 lks7688.ldr 置於 FAT32 Usb drive 的根目錄
2. 插上 USB drive, 可以透過 OTG 線, 或 Breakout 板
3. 壓住 Wi-Fi Reset 按鈕
4. 壓一下 MPU Reset 按鈕
5. 至少20秒後放開 Wi-Fi Reset 按鈕

預設 Wi-Fi SSID: LinkIt_Smart_7688_xxxxxx
IP: 192.168.100.1, 使用 DHCP
Ethernet IP: 192.168.100.1, 使用 DHCP
第一次輸入設定密碼
設定完,再輸入一次密碼

進入 OpenWrt, 再輸入一次密碼
進入下個畫面
點入上方粉紅色的 Go to password configuration...
設定 Router Password, 才可透過 SSH 登入




2017年4月17日 星期一

OpenSSL 證書

openssl学习笔记--CA及https网站证书配置

root@arduino:~/openssl# mkdir openssl
root@arduino:~/openssl# cd openssl
root@arduino:~/openssl# mkdir private
// 產生 根私鑰
root@arduino:~/openssl# openssl genrsa -out private/cakey.pem 2048
root@arduino:~/openssl# vi /etc/ssl/openssl.cnf
dir             = /root/openssl         # Where everything is kept
default_md = sha512 # 使用預設(sha1)方法,chrome 會報說此方法已經不安全,不給用
ountryName                     = Country Name (2 letter code)
countryName_default             = TW
stateOrProvinceName             = State or Province Name (full name)
stateOrProvinceName_default     = Taiwan
localityName                    = Locality Name (eg, city)
localityName_default            = Taichung
0.organizationName              = Organization Name (eg, company)
0.organizationName_default      = SDL
organizationalUnitName          = Organizational Unit Name (eg, section)
organizationalUnitName_default  = R&D

// 產生 根證書
root@arduino:~/openssl# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
root@arduino:~/openssl# touch index.txt serial
root@arduino:~/openssl# echo 01 >serial
root@arduino:~/openssl# mkdir newcerts
root@arduino:~/openssl# mkdir web1
// 產生網站要用的私鑰,通常在別台電腦
root@arduino:~/openssl# openssl genrsa -out web1/httpd.key 2048
root@arduinoYun:~/openssl# cp /etc/ssl/openssl.cnf web1/
root@arduinoYun:~/openssl# vi web/openssl.cnf
req_extensions = v3_req # The extensions to add to a certificate request
[ v3_req ]
subjectAltName = @alt_names
# Extensions to add to a certificate request
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
[alt_names]
IP.1 = 192.168.1.61
IP.2 = 192.168.240.1
IP.3 = 192.168.43.201
DNS.1 = arduinoyun.local

// 產生證書申請書
root@arduino:~/openssl# openssl req -new -key web1/httpd.key -out web1/httpd.csr -sha512 -config web1/openssl.cnf
// 填入要簽署的網址
Common Name (e.g. server FQDN or YOUR name) []:Arduino Yun
// 下面兩個不要填
A challenge password []:
An optional company name []:

// 可用下面命令,查看證書申請
root@arduinoYun:~/openssl# openssl req -text -noout -in web1/httpd.csr
// 將證書申請書送到根證書的機器,簽屬證書
root@arduino:~/openssl# openssl ca -in web1/httpd.csr -out web1/httpd.crt -days 3650 -extensions v3_req -extfile web1/openssl.cnf
// 回答兩個 y 即可,若發生下列錯誤,查詢 newcerts 目錄下最後的一個 pem
failed to update database
TXT_DB error number 2
// 使用命令
root@arduinoYun:~/openssl# openssl ca -revoke newcerts/02.pem

root@arduino:~/openssl# cd ..
root@arduino:~# vi pythonWeb.py
  server.socket = ssl.wrap_socket(server.socket,
    keyfile='openssl/web1/httpd.key',
    certfile='openssl/web1/httpd.crt',
    #cert_reqs=ssl.CERT_REQUIRED,
    #ca_certs='openssl/cacert.pem',
    server_side=True,
    ssl_version=ssl.PROTOCOL_TLSv1)

傳送根證書 cacert.pem 到 local, 並改名為 cacert.crt
匯入憑證


更改 arduino.local 網址

Arduino Yun ,不須設定 DNS 即可透過 arduino.local 連接上
它是透過 zeroconf  連上 arduino
目前使用 zeroconf 產品有 Apple 的 Bonjour 和 Linux 的 Avahi
Arduino Yun 就是使用 Avahi, 設定檔在 /etc/avahi/avahi-daemon.conf
其中
#host-name=foo

因為沒有設定,所以是使用主機的 host name
可以透過網頁設定