Archive for the 'Networking' category

Linux connection sharing over bluetooth

Jul 07 2006 Published by under Linux,Networking

Sharing connection between two computers via bluetooth is a very simple task that consists mostly of establishing a Personal Area Network — ethernet over bluetooth. For this you need to have a kernel module bnep enabled (and loaded). The rest is just an application of routing techniques, so make sure your kernel supports that.

Iptables modules:


On the safe side you should enable everything in Network packet filtering section of your kernel, except for perhaps debugging, won’t hurt but will widen the routing possibilities.

In short, we need to pair the computers, initiate the PAN server, set up routing, and finally connect the client with proper interface configurations.

On the server — the device that is going to provide network access — execute the following:

echo 123456 > /etc/bluetooth/pin
/etc/init.d/bluetooth restart
pand --listen --role NAP
ifconfig bnep0 up
ifconfig bnep0
# Done with bluetooth configuration. Next is the routing part:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A INPUT -s -i bnep0 -j ACCEPT
iptables -A FORWARD -s -i bnep0 -o eth0 -j ACCEPT
iptables -A FORWARD -d -i eth0 -o bnep0 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/tcp_syncookies

Change eth0 to the name of the interface to which you want to forward traffic, change the addresses to those that do not conflict with any other addresses you are using.

On the client side, you will need to know the server’s bluetooth MAC address. Execute:

hcitool scan

This will show your server’s name and MAC address (in the form 11:22:33:44:55:66), along with any other bluetooth devices in vicinity. Then execute:

hcitool auth baddr
pand --connect baddr
ifconfig bnep0 up
ifconfig bnep0
route add default gw

Insert your server’s MAC address instead of baddr. When a prompt appears, enter the pin you set for the server before. If you are going to access the Internet over this connection, make sure to have a valid DNS server in /etc/resolv.conf. In any case, at this point you should be done. If there are any errors, check system logs to see what might be causing them.

You will not need to pair the same devices again if you want to use this repeatedly.

Improved Basic Routing Script — with Bluetooth Support

if [ "$2" != "" ]; then


if [ "$3" != "" ]; then
IP=`echo $3 | cut -f 1,2,3 -d .`

if [ "$1" = "bnep0" ]; then
/etc/init.d/bluetooth restart
pand --listen --role NAP

iptables -F
ifconfig $IN up
ifconfig $OUT up

ifconfig $IN $ADDR
echo "$IN IP: $ADDR"

iptables -t nat -A POSTROUTING -o $OUT -j MASQUERADE
iptables -A INPUT -s $IP.0/24 -i $IN -j ACCEPT
iptables -A FORWARD -s $IP.0/24 -i $IN -o $OUT -j ACCEPT
iptables -A FORWARD -d $IP.0/24 -i $OUT -o $IN -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/tcp_syncookies


echo "Usage: router in_iface out_iface [local_ip]"


No responses yet

« Newer posts Older posts »