感谢支持
我们一直在努力

Linux中让智能手机使用蓝牙连接PC并利用PC网络上网

很多网友都希望能够使用智能手机的蓝牙连接上 PC机网络从而实现手机上网(注意和PC利用手机的GPRS上网不同), 这样做的好处有:


速度快(比GPRS快多了),不用钱(用的是PC机的网络).. 网络上关于这方面的介绍比较少,有的也主要实说在window下的方法. 这里,
我总结了国外网上关于使用Linux(Ubuntu gusty)进行实现的文章,经笔者的w958c验证,是可以使用的.
主要步骤包括.
1. 安装相应的bluetooth软件包..包括bluetooth,bluez-utils,bluez-gnome等.
2. 安装iptables及dhcp3-server(主要为了实现手机ip地址自动分配).
3. bluetooth 配置.. 主要内容包括:
    a. 修改 /etc/bluetooth/hcid.conf文件 其中,
        lm accept;
        修改为
        lm accept, master;
    b.修改 /etc/default/bluetooth文件
        PAND_ENABLED=0
        为
        PAND_ENABLED=1
        修改
        PAND_OPTIONS=””
        为
        PAND_OPTIONS=”–listen –role=NAP –devup /etc/bluetooth/pan/dev-up”
    c.建立/etc/bluetooth/pan目录,并在pan目录下建立dev-up文件,文件内容如下:
 #!/bin/sh
 ifup –force
 echo 1 > /proc/sys/net/ipv4/ip_forward
 sleep 2
 /etc/init.d/dhcp3-server restart
 d.给dev-up文件加上可执行权限.
 以上几步的目的在于使能PAN网络,这样一旦手机连接上PC端的蓝牙适配器并进行网络操作,
 就会执行dev-up文件.在dev-up文件中,我们将bring up bnep0设备(见ifup –force ..
 一定要加force哦..否则第二次连接的时候可能会出问题), 这里的就是blue-utils传下来的bnepx.

4.  配置bnep0设备…修改/etc/network/interfaces文件.在文件中添加:
 iface bnep0 inet static
  address 192.168.1.1
  netmask 255.255.255.0
  post-up iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
  post-up iptables -A FORWARD -i bnep0 -o eth0 -j ACCEPT
  post-up iptables -A FORWARD -o bnep0 -i eth0 -j ACCEPT
  pre-down /etc/init.d/dhcp3-server stop
 注意: 192.168.1.1可以换成其它的地址(若进行了修改, 192.168.1.0/24也需要做相应的调整) ,
  主要目的是为了构建一个虚拟网络.. (不要与PC机所在的局域网地址重叠,
  例如笔者实际的局域网地址为10.13.xx.xx,否则可能造成造成PC机网络路由错误,).
5. 配置dhcp服务器.
  a. 修改/etc/dhcp3/dhcp3.conf文件. 添加:
 subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.1 192.168.1.10;
    option routers 192.168.1.1;
    option domain-name-servers 202.120.224.6,202.120.224.26;
    option domain-name “Sardis_Private”;
    option broadcast-address 192.168.1.255;
    default-lease-time 600;
    max-lease-time 7200;
 }
 注意: 如果在第4步中,不是使用192.168.1.xx网段.需要根据你说指定的网段修改棕色部分内容.
  而绿色部分内容请修改
为PC网络的dns服务器地址.
 b. 修改/etc/default/dhcp_server文件,修改为
             INTERFACES=”bnep0″6. 启动bluetooth服务..
 插上蓝牙适配器,然后运行
 /etc/init.d/bluetooth start
 注意可以使用 ps aux | grep bluetooth 观察是否有一个
 /usr/bin/pand –listen –role=NAP –devup /etc/bluetooth/pan/dev-up的进程.
7. 打开手机中的蓝牙,然后连接PC端的蓝牙适配器.. 设置信任找到的PC适配器,同时PC端也
 信任手机端.可运行bluetooth-applet & ,然后在状态栏的蓝牙图标上观察蓝牙属性,
 看是否 连接正常..
 注意:  如果手机找不到蓝牙适配器可以在蓝牙属性中的mode of operation中点上
  Visible and connectable for other devices. PC端也
  可以使用hcitools scan命令,观察是否可以找到手机.
8. 在手机中添加蓝牙上网账号..
    a. 在控制面板的”连接”中选择”互联网账号”,然后在”更多”中新建Bluetooth(蓝牙)互联网账号”,,
 最后填入名称(名称随便取), 在”设备”选项中添加PC蓝牙适配器. 然后保存… 然后同样方法
 新建一个”组群”,填入名称(如”使用蓝牙上网”等,之后将刚刚新建的蓝牙互联网账号加入
 到组群中. 将该组群设置为默认上网组群.
9. 运行’移动梦网”, 随后在弹出的对话框中选择”使用蓝牙上网”组群, 点击”连接”并填入相应网址…
 一段时间后可就可以登录网站了..
 注意: 由于是使用PC端网络,因此PC能上手机也能上,PC不能上手机也不能上. 第一次连接的时候
 会比较慢, 因为要获得IP地址与PC建立连接等.
Troubleshooting
1. See if your bnep0 device is going up when a connection is requested and the interface is asked to come up.
You can watch this with the following command as root:
watch -n1 “ifconfig”
You should see bnep0 coming up when you fire up your bluetooth client device to try and access the PAN network.
2. See that the script /etc/bluetooth/pan/dev-up is being executed.
3.Watch the output of syslog to see if the dhcp server is asinign an IP to your device.
tail -f /var/log/syslog
tail -f /var/log/messages
4. Once you see the IP, try to ping your device with the ping command.如果有什么写得不清楚了,可以看看下一页中的英文文章.
我的这边就是使用他的方法…当然有一小部分修改.

Bluetooth PAND (Personal Area Network) Howto For Debian Etch
Overview
I wanted to access the internet over bluetooth instead of GPRS/3G network from my mobile phone (SE K800i). After a lot of searching I couldn’t find a clear explanation as how to accomplish this. I did manage to set it up with Windows XP, using the “Personal Area Network” in the bluetooth utility and doing internet connection sharing. After another fruitless search, I managed to figure out how to make a bluetooth internet profile instead of GPRS or 3G on the phone. Since I work in Linux most of the time, I decided to have a go and do it with Debian, my workstation’s main OS. After spending a few hours, I had it working using the steps below.


This howto is for Debian Etch, current “testing” branch soon to be 4.0. May work on Ubuntu or other Debian based distros. Settings for older versions may be similar. In Debian 3 the bluetooth daemon maybe regarded to as hcid.


Requirements
Kernel 2.6.x, may work under 2.4, not tested.
iptables is needed if you want to access other computers or the internet.
Install:


apt-get install bluetooth


install apt get install bluez-utils


install apt-get install dhcp3-server


Optional:


apt-get install kdebluetooth



Has the kde pinhelper application for easy pairing.


Note: Pairing your bluetooth devices is beyond the scope of this howto. It assumes you can pair you device to your system.


As root:


Edit /etc/bluetooth/hcid.conf. Change


lm accept;


to


lm accept, master;


Edit /etc/default/bluetooth.Change


PAND_ENABLED=0


to


PAND_ENABLED=1


and


PAND_OPTIONS=””


to


PAND_OPTIONS=”–listen –role=NAP –devup /etc/bluetooth/pan/dev-up”


mkdir /etc/bluetooth/pan


touch /etc/bluetooth/pan/dev-up


Put the following in /etc/bluetooth/pan/dev-up:


#!/bin/sh
echo 1 > /proc/sys/net/ipv4/ip_forward
ifup bnep0
sleep 2
/etc/init.d/dhcp3-server restart
Make it executable:


chmpd +x /etc/bluetooth/pan/dev-up


In /etc/network/interfaces add the bluetooth interface as follows:


iface bnep0 inet static
          address 10.0.254.1
          netmask 255.255.255.240
   
post-up iptables -t nat -A POSTROUTING -s 10.0.254.0/24 -j MASQUERADE
post-up iptables -A FORWARD -i bnep0 -o eth0 -j ACCEPT
post-up iptables -A FORWARD -o bnep0 -i eth0 -j ACCEPT
pre-down /etc/init.d/dhcp3-server stopeth0 is the interface you will be NAT-ed behind. Your external interface.


Change the IPs and network settings as you like, just make sure to also reflect it in your dhcp.


In /etc/dhcp3/dhcpd.conf make sure you set


option domain-name “somedomainname.com”;
option domain-name-servers ip-of-dns-server-goes-here;where ip-of-dns-server-goes-here is the IP address of the dns server to use. You can see the server you’re using in /etc/resolv.conf.


Declare a subnet for the PAN segment, should be the subnet you used for the bnetp device in /etc/network/interfaces. Replace the option routers 10.0.254.1; with the IP you have given your bnep0 interface in /etc/network/interfaces.


subnet 10.0.254.0 netmask 255.255.255.0 {
  range 10.0.254.1 10.0.254.10;
  option domain-name-servers 10.0.1.1;
  option domain-name “bluetoothap.int.yourdomain.com”;
  option routers 10.0.254.1;
  option broadcast-address 10.0.254.255;
  default-lease-time 600;
  max-lease-time 7200;
}Now restart the bluetooth daemon:


/etc/init.d/bluetooth restart


Pair your device with the machine. Once paired you should be able to access the network using the bluetooth PAN service for another computer, PDA or mobile phone.


Troubleshooting
1. See if your bnep0 device is going up when a connection is requested and the interface is asked to come up. You can watch this with the following command as root:


watch -n1 “ifconfig”


You should see bnep0 coming up when you fire up your bluetooth client device to try and access the PAN network.


2. See that the script /etc/bluetooth/pan/dev-up is being executed.


3.Watch the output of syslog to see if the dhcp server is asinign an IP to your device.


tail -f /var/log/syslog


tail -f /var/log/messages


4. Once you see the IP, try to ping your device with the ping command.


Bluetooth PAN settings for Sony Ericsson k800i
Menu:


Settings -> Connectivity -> Data Accounts.


In the list you should see your bluetooth AP.


Go to


Settings -> Connectivity -> Internet Settings -> Internet Profiles -> New profile


In Name enter a name for the connection. eg. PAN.


For Connect Using choose the bluetooth icon with the name of your bluetooth machine, the one showing in the data accounts, and also the PC you paired your k800i with.


Now make this profile active for internet, java and streaming.


Make sure you press save.


Now you should be able to browse the internet trough your k800k. Enjoy!


 


Written by Zdenek Bouresh.


zdenekbouresh [at] gmail dot com 

赞(0) 打赏
转载请注明出处:服务器评测 » Linux中让智能手机使用蓝牙连接PC并利用PC网络上网
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏