2013年1月11日金曜日

An installation of Arch Linux on Raspberry Pi : assign static IP (wired and wireless)

How to assign static IP addresses to  a wireless device and a wired device.

Raspberry Piで、有線/無線LANに、それぞれ固定IPアドレスを設定する方法。
13台のRaspberry Piで、問題なく稼動しています。
Please refer https://wiki.archlinux.org/index.php/Static_IP_and_DHCP
少し、なやんだ事があります。
両方とも固定にすると、立上げ時にデバイス認識できず起動せず。
起動後、再度sysmtectlでunitをstart させると正常に起動する。
結論から言うと、USBハブとの相性が悪かったみたい。その場合は、 (6) 2項を実施すると、問題なく動きます。boot時の様に、負荷が比較的高い状態で、かつ起動後最初のUSBハブ経由のwifi USB dongle認識に少し時間が必要な様です。他のデバイスでも発生する可能性がありますが、確かめてはいません。

Wifi dongle     : BUFFALO WLI-UC-GNM
Wired LAN      : 192.168.11.10
Wireless LAN  : 192.168.11.11
DNS             :  192.168.11.1  -> (4)

無線LANを使うには、wpa_supplicantパッケージのインストールと、
/etc/wpa_supplicant.confの設定が必要です。
Arch Linux installのページを参照して下さい。section 4.2 です。
手動で確認する手順も記述してあります。その後、下記手順をどうぞ

(1) Create the file /etc/conf.d/network
(2) Create the file /etc/systemd/system/network.service
(3) Run systemcrl
(4) Edit /etc/resolv.conf & reboot
(5) Check
(6) If you have  errors

設定が終わったら、Design Philosoph and Concept of my robots も見てね!

-------------------------------------------------------------------------------------------------
(1) Create the file /etc/conf.d/network
[root@rcmp-sv01 ~]# vi /etc/conf.d/network
[root@rcmp-sv01 ~]# cat /etc/conf.d/network
interfacew=wlan0
interface=eth0
addressw=192.168.11.10
address=192.168.11.11
netmask=24
broadcast=192.168.11.255
gateway=192.168.11.1

(2) Create the file /etc/systemd/system/network.service
 この設定は、無線LAN子機接続を優先して設定し、有線LANを補助として使う設定方法です。従って、起動時に無線LAN子機が取り外れている時には、エラーになります。そのような運用に問題がある場合には、serviceをそれぞれ作る事が必要です。

[root@rcmp-sv01 ~]# vi /etc/systemd/system/network.service
[root@rcmp-sv01 ~]# cat /etc/systemd/system/network.service
[Unit]
Description=Network Connectivity (Static IP wlan0 eth0)
Wants=network.target
Before=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/network
ExecStart=/sbin/ip link set dev ${interfacew} up
ExecStart=/sbin/ip link set dev ${interface} up
ExecStart=/usr/sbin/wpa_supplicant -B -D wext -i ${interfacew} -c /etc/wpa_supplicant/wpa_supplicant.conf
ExecStart=/sbin/ip addr add ${addressw}/${netmask} broadcast ${broadcast} dev ${interfacew}
ExecStart=/sbin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev ${interface}
ExecStart=/sbin/ip route add default via ${gateway}
ExecStop=/sbin/ip addr flush dev ${interfacew}
ExecStop=/sbin/ip addr flush dev ${interface}
ExecStop=/sbin/ip link set dev ${interfacew} down
ExecStop=/sbin/ip link set dev ${interface} down
[Install]
WantedBy=multi-user.target

(3) Run systemcrl
[root@rcmp-sv01 ~]# systemctl disable dhcpcd@eth0.service
rm '/etc/systemd/system/multi-user.target.wants/dhcpcd@eth0.service'
[root@rcmp-sv01 ~]# systemctl enable network.service
ln -s '/etc/systemd/system/network.service' '/etc/systemd/system/multi-user.target.wants/network.service'

(4) Edit /etc/resolv.conf & reboot
After a static IP address set on your Raspberry Pi, you  need to assign a  DNS address (nameserver) into /etc/resolv.conf.
If you are able to ping the following  address, you may try adding this nameserver to your /etc/resolv.conf file. It is the address of Google's primary DNS server.

[root@rcmp-sv01 ~]# ping -c 3 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=46 time=46.4 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=46 time=50.1 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=46 time=50.2 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 46.446/48.952/50.259/1.791 ms
[root@rcmp-sv01 ~]# vi /etc/resolv.conf
[root@rcmp-sv01 ~]# cat /etc/resolv.conf
# Generated by dhcpcd
# /etc/resolv.conf.head can replace this line
# /etc/resolv.conf.tail can replace this line
#nameserver 192.168.11.1                      # your DNS 
nameserver 8.8.8.8                            # 8.8.8.8 ping OK
nameserver 8.8.8.4

Insert a wifi dongle to your Raspberry Pi.

[root@rcmp-sv01 ~]# reboot

(5) Check
[root@rcmp-sv01 ~]# dmesg | grep eth0
[    2.326344] smsc95xx 1-1.1:1.0: eth0: register 'smsc95xx' at usb-bcm2708_usb-1.1, smsc95xx
USB 2.0 Ethernet, b8:27:eb:7a:da:c6
[   17.464573] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[   18.971807] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[   18.974373] smsc95xx 1-1.1:1.0: eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
[root@rcmp-sv01 ~]# dmesg | grep wlan0
[   17.471293] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[   20.137110] wlan0: authenticate with xx:xx:xx:xx:44:74
[   20.282721] wlan0: send auth to xx:xx:xx:xx:44:74 (try 1/3)
[   20.284445] wlan0: authenticated
[   20.361233] wlan0: associate with xx:xx:xx:xx:44:74 (try 1/3)
[   20.365241] wlan0: RX AssocResp from xx:xx:xx:xx:44:74 (capab=0x431 status=0 aid=7)
[   20.381284] wlan0: associated
[   20.381465] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[root@rcmp-sv01 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host valid_lft forever preferred_lft forever
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether xx:xx:xx:xx:da:c6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.11/24 brd 192.168.11.255 scope global eth0
    inet6 fe80::ba27:ebff:fe7a:dac6/64 scope link valid_lft forever preferred_lft forever
5: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 100
    link/ether xx:xx:xx:xx:95:f4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.10/24 brd 192.168.11.255 scope global wlan0
    inet6 fe80::126f:3fff:fe5b:95f4/64 scope link valid_lft forever preferred_lft forever

(6) If you have errors.
-   Check below files
     network, network.service, resolv.conf

-  Insert a sleep command
[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/network
ExecStart=/usr/bin/sleep 2
ExecStart=/sbin/ip link set dev ${interface} up

-  Last challenge.
It's a good luck charm   maybe.
[root@rcmp-sv01 ~]# ip addr add  local <ip address>/<mask> brd <broadcast>
                                      dev wlan0 label wlan0:0
[root@rcmp-sv01 ~]# reboot

peace!

0 件のコメント:

コメントを投稿