Bluetooth PAND (Personal Area Network) Howto For Debian Etch

Want to support HowtoForge? Become a subscriber!
 
Submitted by zdenekbouresh (Contact Author) (Forums) on Fri, 2007-03-23 17:09. :: Debian | Networking

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 stop

eth0 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  


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by raisedgardenplanter (not registered) on Fri, 2012-04-20 02:55.

but i d not think many people will do like this.it is just a little complicated

Submitted by wilgeman (not registered) on Fri, 2010-04-30 01:10.

This line

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

 Should be

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

 Otherwise this works great in Arch Linux

Submitted by Destrukto (not registered) on Tue, 2009-03-03 10:25.
I've tried this with my Debian Etch and Acer Bluetooth Adapter but my bnep0 never comes up and with my notebook I don't see my PC. So does anybody know what I could have forgot?
Submitted by giordano (not registered) on Tue, 2009-01-06 15:07.

Worked on Ubuntu Intrepid.

I had to add in /etc/bluetooth/network :

 

Interface=pan0

 

because bluetoothd try to use the bridge pan1: from syslog:

Can't add bnep0 to the bridge pan1: No such device(19) Hope this helps.

Submitted by Kaustubh (not registered) on Wed, 2010-02-03 00:14.

Hi,

I am getting the same error as you are, however, your solution apparently does not help. Could you please be a bit more elaborate ? 

You are talking about the network.conf file in /etc/bluetooth right ? 

And you changed the Interface value to pan0 for the  NAP Role ?

Thanks, I will hugely appreciate any input

 Kaustubh

Submitted by eee1000huser (not registered) on Tue, 2009-02-24 17:44.

Are you sure this works in Ubuntu 8.10? As far as I can tell the bluetooth statck between 8.04 and 8.10 is totally different ... i.e. there is no hcid and hcid.conf in 8.10.

I get the same error you mentioned (bnep0) but chancing the Interface to pan0 does not work either...

 

Any ideas?

 

Cheers,

 

-e

Submitted by THANX (not registered) on Wed, 2008-10-29 21:56.
Well done!!! This worked for me and after several times of trying to make this thing work on my slackware I made it finally because of this great post.
Submitted by matthew_exon (registered user) on Thu, 2007-05-17 13:25.

Inspired by this HOWTO, I had another go at setting up a PAN: and this time, finally, after years of failure, I managed to get things working! I used a somewhat simpler approach, so maybe this should be incorporated...

I would suggest using ipmasq instead of iptables and dnsmasq instead of dhcp3-server. Both of these are "I'm just an ordinary user, quit bugging me and give me my damn internet already!"-oriented packages which use sensible defaults and keep configuration to a minimum.

So, as you suggest:

lm accept,master

PAND_ENABLED=1

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

For /etc/bluetooth/pan/dev-up, my version boils down to just the following:

#!/bin/sh
ifup --force $1
    

It relies on the ifupdown system for setting up masquerading and DHCP, so it only has to ifup the device. Also, pand supplies two arguments to this script: the first is the name of the Linux device (i.e., "bnep0"), the second is the connecting phone's MAC address. Using the argument instead of hard-coding bnep0 is cleaner and should make this part work smoothly even with multiple connections (although I've never tried that, and you'd still have to set up extra /etc/network/interfaces.)

I found I needed the --force flag because once the device is brought up, it's never cleanly brought down again. The device just disappears, but this seems to confuse the ifupdown system, which thinks it's still configured. Then, when another connection comes in, the ifupdown system thinks it doesn't need to do anything, and the device remains unconfigured. So I use --force to make it configure the device anyway. In upstream (at least bluez-utils 3.10) they seem to have added a hook to pand to allow it to run a script when the device is shut down, as well as when it's brought up. That should allow the device to be brought down cleanly by a /etc/bluetooth/pan/dev-down script, and remove the need for the --force flag. But we'll have to wait before that makes it into stable.

I'd also mention that I experimented with simply doing this:

PAND_OPTIONS="--listen --role=NAP --devup /sbin/ifup"

...which avoids the need for a separate script. This does actually work (it complains about the nonsense MAC argument, but this is benign). But I couldn't find a way to get the --force argument in there, so for me this would only work once.

So then we come to /etc/network/interfaces:

iface bnep0 inet static
        address 192.168.65.1
        netmask 255.255.255.0
        up /usr/sbin/ipmasq
        down /usr/sbin/ipmasq
    

In this case I've gone for 192.168.65.0/24 as my bluetooth network. The up and down commands are as recommended by the package maintainer of ipmasq (see /usr/share/doc/ipmasq/README.Debian.gz). The down command is a little pointless, since this interface will never be brought down cleanly, but what the hell.

And finally, /etc/dnsmasq.conf:

dhcp-range=192.168.65.50,192.168.65.150,12h

Obviously this has to be adjusted for whatever network you chose in /etc/network/interfaces. This gives you a DHCP server on the specified interface, and it also provides a forwarding DNS server. Note that it pretty much takes care of itself, it doesn't need to be told about new interfaces coming up or going away.

Thanks for the HOWTO!

Submitted by Pushkar (not registered) on Sun, 2012-07-22 15:31.

Hi!

Excellent article. Worked for me after I kept at it for sometime. I now have a bluetooth tether going between my PC (it is connected to internet) and my tablet. I am able to ping my tablet from my PC. I am able to access a webpage hosted on my PC from my tablet too.

But my PC uses a proxy server to access the internet. My tablet does not have a way of specifying proxy settings. Is it possible to handle the packet forwarding to the proxy in the DHCP configuration itself? Please suggest a way to do this or suggest an alternative.

Thanks!