2014年2月16日日曜日

piCorePlayer:IPアドレスを固定する

サーバのIPアドレスは固定したい

piCorePlayerはDHCPでIPアドレスを取得している。

<変更前の状況>
tc@piCorePlayer:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr B8:27:EB:A0:C2:79
          inet addr:192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:225 errors:0 dropped:0 overruns:0 frame:0
          TX packets:169 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:18806 (18.3 KiB)  TX bytes:27535 (26.8 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:96 errors:0 dropped:0 overruns:0 frame:0
          TX packets:96 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:8424 (8.2 KiB)  TX bytes:8424 (8.2 KiB)

サーバのアドレスが変わると気持ちよくないので固定したい。
Debian系のLinuxであれば「/etc/network/interfaces」で設定するが、
ここで使われているLinuxはTiny Core Linuxというモノでちょっと勝手が違うようだ。

色々調べて、どうにかできたので纏めておきます。
(参考にしたサイトはここここです。ありがとうございます。)

1.初期設定環境の確認
piCorePlayerを初期設定するスクリプトは/optに置かれているようです。

tc@piCorePlayer:~$ cd /opt
tc@piCorePlayer:/opt$ ls -a
./              .filetool.lst   bootlocal.sh    shutdown.sh
../             .xfiletool.lst  bootsync.sh     tcemirror

bootsync.sh:ブート時に起動されるスクリプトが記述されている
.filetool.lst:SDカードに記憶させるファイルが記述されている

2.IPアドレスを設定するスクリプトを作成
固定アドレスを設定するための「eth0.sh」なるスクリプトを作成する。

tc@piCorePlayer:/opt$ vi eth0.sh

#!/bin/sh
pkill udhcpc
ifconfig eth0 192.168.1.41 netmask 255.255.255.0 broadcast 192.168.1.255 up
route add default gw 192.168.1.1
echo nameserver 192.168.1.1 > /etc/resolv.conf

3.実行権限の付与
「eth0.sh」のモードを変更する。

tc@piCorePlayer:/opt$ chmod +x eth0.sh

tc@piCorePlayer:/opt$ ls -l
total 20
-rwxrwxr-x    1 tc       staff          530 Feb 15 03:31 bootlocal.sh
-rwxr-xr-x    1 root     staff          281 Feb  4 18:51 bootsync.sh
-rwxr-xr-x    1 tc       staff          179 Feb 15 04:31 eth0.sh
-rwxrwxr-x    1 root     staff          613 Jan 20 07:24 shutdown.sh
-rw-rw-r--    1 root     staff           31 Jan 20 07:24 tcemirror

4.ブート時に実行されるようにする
「bootsync.sh」に「eth0.sh」を設定する。

tc@piCorePlayer:/opt$ sudo vi bootsync.sh

#!/bin/sh
# put other system startup commands here, the boot process will wait until they complete.
# Use bootlocal.sh for system startup commands that can run in the background
# and therefore not slow down the boot process.
/usr/bin/sethostname piCorePlayer
/opt/bootlocal.sh &
/opt/eth0.sh &

5.SDカードに保存されるようにする
「.filetool.lst」に「etho.sh」を設定する。

tc@piCorePlayer:/opt$ vi .filetool.lst

opt
home
 ・・・
usr/local/sbin/updates_sql.sh
usr/local/sbin/upsample.sh
usr/local/sbin/wifi_picoreplayer.sh
opt/eth0.sh

6.SDカードに書き戻す
「filetool.sh」を実行する。

tc@piCorePlayer:/opt$ sudo filetool.sh -b
Backing up files to /mnt/mmcblk0p2/tce/mydata.tgz

7.リブート
リブートして確認します。

tc@piCorePlayer:~$ sudo reboot

<変更後の状況>
tc@piCorePlayer:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr B8:27:EB:A0:C2:79
          inet addr:192.168.1.41  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:117 errors:0 dropped:0 overruns:0 frame:0
          TX packets:84 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:9832 (9.6 KiB)  TX bytes:10066 (9.8 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

tc@piCorePlayer:~$ cat /etc/resolv.conf
nameserver 192.168.1.1

以上、バッチリできました。

2022/02/08:追記
今現在はBetaタブのメニューから簡単に設定できるようになっている(^^)v

0 件のコメント:

コメントを投稿