I generally write in Spanish, but this time I’m gonna try to go a step further so more people can get some profit from my experiences.
I’m going to show you how to create a PAN (Personal Area Network) between two computers running Linux using bluetooth devices. This PAN is supoussed to be set up any time you plug your bluetooth adapter.
First of all, I’ll try to explain how I have set up my network so the following explanation will be easier to understand, here’s in a simple schema:
My LAN
I have on router with access point, one personal computer, one server (used to P2P, remote login, FTP…) and my laptop. I usually connect to the network using the wireless connection (shown in blue), but sometimes it seems to fail so I get out of connection and I’m too lazy to move some meeters to reset the router. So, in order to avoid this, I’m gonna show you how to create a bluetooth conection between the server and the laptop (shown in red) that can be used as a gateway to the Internet for both my laptop and my mobile phone or as a simple LAN to perform some administration tasks through ssh.
For both sides:
Be ensure that you have the bnep module compiled in your kernel:
Networking --->
<M>Bluetooth subsystem support --->
<M>BNEP protocol support
The server side:
It is using a bluetooth adapter Conceptronic. The MAC will be used in the client side you can use hcitool dev to get it.
First of all edit the /etc/default/bluetooth adding the following lines:
....
PAND_ENABLED=1
PAND_OPTIONS="--listen --role NAP --devup /etc/bluetooth/pan/dev-up"
....
This will enable PAND and tell the system how to act, if you see, when the system PAND receives a connection it will execute the /etc/bluetooth/pan/dev-up script which has to be set up like this:
#!/bin/sh
ifup bnep0
ifconfig bnep0 up
ifconfig bnep0 192.168.5.1
ifconfig bnep0 netmask 255.255.255.252
Remeber to make it executable and restart the bluetooth system:
$ chmod +x /etc/bluetooth/pand/dev-up
$ /etc/init.d/bluetooth restart
The client side
As well as for the server edit the /etc/default/bluetooth adding the following lines (notice the MAC gotten before is now used):
...
PAND_ENABLED=1
PAND_OPTIONS="--connect 00:80:5A:20:4E:F7 --devup /etc/bluetooth/pan/dev-up"
...
In the same way, the file specifying how to act when the system notices the connection has to be edited, so here is how /etc/bluetooth/pan/dev-up should look like:
#!/bin/sh
ifup bnep0
ifconfig bnep0 up
ifconfig bnep0 192.168.5.2
ifconfig bnep0 netmask 255.255.255.252
Remeber to make it executable and restart the bluetooth system:
$ chmod +x /etc/bluetooth/pand/dev-up
$ /etc/init.d/bluetooth restart
Now, everytime you connect the bluetooth adapter, a new interface bnep0 should be brought up in both sides with the specified rules. You can see it using the ifconfig command. You should be able to do any tasks from both sides like ping, ssh… here’s an expample:
root@Stronghold:/etc/bluetooth/pan# ifconfig
bnep0 Link encap:Ethernet HWaddr 00:80:5a:20:4e:f7
inet addr:192.168.5.1 Bcast:192.168.5.3 Mask:255.255.255.252
inet6 addr: fe80::280:5aff:fe20:4ef7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:21 errors:0 dropped:0 overruns:0 frame:0
TX packets:43 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3925 (3.8 KiB) TX bytes:7047 (6.8 KiB)
root@Stronghold:/etc/bluetooth/pan# ping 192.168.5.2
PING 192.168.5.2 (192.168.5.2) 56(84) bytes of data.
64 bytes from 192.168.5.2: icmp_seq=1 ttl=64 time=59.9 ms
^C
— 192.168.5.2 ping statistics —
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 59.977/59.977/59.977/0.000 ms
Additional comments:
- Of course, you will have to change some information as the MAC and the IP address
- If you get the following error:
ExoduS:/home/kets# pand --connect 00:80:5A:20:4E:F7 -n
pand[10820]: Bluetooth PAN daemon version 3.30
pand[10820]: Connecting to 00:80:5A:20:4E:F7
pand[10820]: Connect to 00:80:5A:20:4E:F7 failed. File exists(17)
It’s because you have already a connection set up in your computer, probably running on the background you can see it with pand -l and destroy it with pand -K
- By now I’m just using this connetion as a simple LAN not as a gateway to the Internet. If you wish to do that, you’ll have to set up some iptables rules in the server side, these rules are very well explained in the first link of the following section.
Useful links:
http://www.howtoforge.com/bluetooth_pand_debian_etch
http://bluez.sourceforge.net/contrib/HOWTO-PAN
Hope it helps & don’t hesitate to contact me for any help.