This time I’d like to show you how to tethering your internet connection via Bluetooth or USB cable from your PC/Tablet/Smartphone with your Raspberry Pi!
What is Internet Tethering?
The internet tethering allows you to show your internet connection with another device using USB cable or bluetooth connection, in this case your network cards are free to use with another connection or to do some activity like pentesting.
USB Tethering with Smartphone/Tablet
In order to use USB tethering you need to configure your Raspberry Pi so that it can accept USB internet module.
Let’s start with type in the terminal:
sudo nano /etc/network/interfaces
Add this line at the end of the file:
allow-hotplug usb0 iface usb0 inet static address 192.168.42.42 netmask 255.255.255.0 network 192.168.42.0 broadcast 192.168.42.255
In this case I’d like to use a static IP address in order to connect via VNC or SSH with the same IP every time, the subnetwork IP are 192.168.42.* and you should choose every number from 1 to 254 and replace the ” * “. If you don’t want a static IP replace static with dhcp and delete the address,netmask,network and broadcast line.
After that all you need to do is connect you Smartphone/Tablet with USB cable and turn on USB tethering option.
In addition add a default route pointing all traffic from your Pi out to your device, to do that grab the IP from your device and replace “[IP]” in the second command with:
Make a default route pointing with command:
route add default gw [IP] usb0
All is now ready to use, test it with:
USB Tethering with PC
USB Tethering with PC is more simple that smartphone/tablet, all that you need to do is connect Raspberry Pi to PC via USB cable and tell to your PC that the Raspberry Pi is a network card. The way that I prefer is edit the config.txt and cmdline.txt file in the boot partition of your SD card.
Add this line at the end of config.txt file:
Add this line between rootwait and quiet in the cmdline.txt file:
After that you can share the internet connection from ethernet/wifi with your new “network card”, if you don’t know how to do that check my previus article at this link. Make sure to install Bounjour Services on your Windows PC if you want to connect via SSH and VNC with the hostname raspberrypi.local !
Bluetooth Tethering with all devices
In order to use Bluetooth Tethering you need to Pair and connect your device as Internet source, to do that
On your device:
- Open Settings
- Select Bluetooth
- This will make your device “discoverable”
- Start Bluetooth Tetheering
On your Raspberry Pi:
- Click (if it’s off)
- Your device will appear in the list, select it and click guilabel: Pair
- Enter a PIN code
On your device again:
- Enter the same PIN code when prompted
- Touch “OK”
You may receive errors relating to services not being able available or being unable to connect: these can be ignored.
Now you need to install Bluman on your Raspberry Pi and you can do that with command:
sudo apt-get update sudo apt-get install blueman
After the installation open the menu and go to Preferences -> Bluetooth Manager, select you Paired device and run the Setup option in the menù, select Internet source from options and click OK. Now you are able to use internet over bluetooth, last but not least make the connection automatic if you want to use it without reconfigure it every time. To do that download this repository with command:
git clone https://github.com/WayneKeenan/RaspberryPi_BTPAN_AutoConnect.git
After that go into the folder and move the file in /bin with command:
cd RaspberryPi_BTPAN_AutoConnect/ sudo mv bt-pan /bin sudo mv check-and-connect-bt-pan.sh /bin
Now you need to edit the check-and-connect-bt-pan.sh file in order to connect with your phone so take note about your MAC that you can read in the Bluetooth Manager window (is like AA:BB:CC:DD:EE:FF) and type in terminal:
cd /bin sudo nano check-and-connect-bt-pan.sh
And repalce your MAC in the line:
BT_MAC_ADDR=<Your MAC address>
Save and exit.
In order for the Pi to automatically (re)connect create a
cron job to run a script every minute.
Add this line:
* * * * * /bin/check-and-connect-bt-pan.sh
Then save the file.
Now you are ready to use your Raspberry Pi with all type of Internet Tethering options! Enjoy and hope you like it!