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.
NETFILTER IP_NF_CONNTRACK IP_NF_IPTABLES IP_NF_NAT IP_NF_TARGET_MASQUERADE NETFILTER_XT_MATCH_STATE
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 192.168.1.1 # Done with bluetooth configuration. Next is the routing part: iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE iptables -A INPUT -s 192.168.1.0/24 -i bnep0 -j ACCEPT iptables -A FORWARD -s 192.168.1.0/24 -i bnep0 -o eth0 -j ACCEPT iptables -A FORWARD -d 192.168.1.0/24 -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:
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 192.168.1.2 route add default gw 192.168.1.1
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 IN="$1" OUT="$2" if [ "$3" != "" ]; then ADDR=$3 IP=`echo $3 | cut -f 1,2,3 -d .` else ADDR=192.168.1.1 IP=192.168.1 fi if [ "$1" = "bnep0" ]; then /etc/init.d/bluetooth restart pand --listen --role NAP fi 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 else echo "Usage: router in_iface out_iface [local_ip]" fi