Changes between Initial Version and Version 1 of linux/bnetp


Ignore:
Timestamp:
2017/03/26 13:28:56 (7 years ago)
Author:
yuna
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • linux/bnetp

    v1 v1  
     1= Linuxを使ってBluetoothでインターネット接続 
     2 
     3Linuxをアクセスポイントとして、Bluetoothでネットワーク接続する方法を紹介します。 
     4 
     5Xperia Z1(C6903)を購入したのですが、WIFIに不具合があり使い物にならなかったので、 
     6Bluetoothで接続することにしたメモです。 
     7 
     8なお、Ubuntu 16.04で構築しているので、他のディストリビューションをお使いの方は適用に読み替えてください。 
     9 
     10== 用意するもの 
     11 
     12 * bluezパッケージ 
     13  * apt-get install bluezでインストールしておきます。bluetoothデバイスを操作するのに必要です。 
     14 
     15 * bt-panスクリプト 
     16  * Bluetoothでネットワーク共有を行うためのスクリプトです。下記のサイトのスクリプトを/usr/local/binなどにコピーして使います。 
     17    * https://github.com/mk-fg/fgtk/blob/master/bt-pan 
     18    * なお、python-dbusパッケージなどが動作に必要です。 
     19 
     20== 準備 
     21 
     22まず、bluetooh自身を利用できるようにします。 
     23 
     24bluetoothサービスを設定します。 
     25 
     26{{{ 
     27# systemctl start bluetooth.service 
     28# systemctl enable bluetooth.service 
     29}}} 
     30 
     31bluetoothコマンドで、bluetoothの有効化、ペアリングなどを行います。 
     32 
     33{{{ 
     34root@piano:/etc/systemd/system/multi-user.target.wants# bluetoothctl 
     35[NEW] Controller 00:1B:DC:0F:C1:52 mypc [default] 
     36[NEW] Device 74:23:44:6B:XX:XX Android 
     37[bluetooth]# power on 
     38Changing power on succeeded 
     39[bluetooth]# discoverable on 
     40Changing discoverable on succeeded 
     41[CHG] Controller 00:1B:DC:0F:C1:52 Discoverable: yes 
     42[bluetooth]# agent on 
     43Agent registered 
     44[bluetooth]# scan on 
     45}}} 
     46 
     47これでAndroidから認識されるようになるので、Androidからデバイスの登録を行い、ペアリングを行います。 
     48 
     49{{{ 
     50[bluetooth]# pair 74:23:44:6B:XX:XX 
     51[bluetooth]# trust 74:23:44:6B:XX:XX 
     52}}} 
     53 
     54ペアリングコマンドを実行すると、Androidの方で許可メッセージが出るので、許可します。 
     55 
     56== ネットワークの設定 
     57 
     58Bluetoothで接続するネットワークの設定をします。 
     59{{{ 
     60auto br-bnetp 
     61face br-bnetp inet static 
     62        address 192.168.1.1 
     63        netmask 255.255.255.0 
     64        network 192.168.1.0 
     65        broadcast 192.168.1.255 
     66        gateway 192.168.1.254 
     67        bridge_ports enp2s0 
     68        dns-nameservers 8.8.8.8 
     69}}} 
     70 
     71DNSが動作していなければ、DNSを設定します。下記は、dnsmasqの例です。 
     72 
     73/etc/dnsmasq.d/bnetp 
     74 
     75{{{ 
     76dhcp-range=tag:bt-br,192.168.1.2,192.168.1.63,30m 
     77dhcp-option=tag:bt-br,option:router,192.168.1.254 
     78dhcp-option=tag:bt-br,option:dns-server,8.8.8.8 
     79}}} 
     80 
     81適当にdnsmasqパッケージをインストールして起動しておきます。 
     82 
     83 
     84== サービスの設定 
     85 
     86net-bnetp.serviceファイルを作成し、/etc/systemd/system/multi-user.target.wantsディレクトリに 
     87置きます。 
     88 
     89{{{ 
     90[Unit] 
     91After=bluetooth.service 
     92PartOf=bluetooth.service 
     93 
     94[Service] 
     95ExecStart=/usr/local/bin/bt-pan server br-bnetp 
     96 
     97[Install] 
     98WantedBy=bluetooth.target 
     99}}} 
     100 
     101bt-panの実行コマンドで、Bluetoothデバイスを接続するブリッジをしています。配置したら、サービスとして起動します。 
     102 
     103{{{ 
     104# systemctrl daemon-reload 
     105# systemctl start net-bnetp.service 
     106}}} 
     107 
     108== Android側でBluetoothネットワークに接続 
     109Bluetoothのデバイスを表示すると、「Internet access(インターネットアクセス)」という項目があるので、ONにするとインターネットアクセス可能になります。