RPI3 PIXEL Jessie - usb0 interface - android

Greetings to everyone!
I have a project on RPI but I have 1 problem.
Project description: RPI (server, connected to LAN DHCP with internet access) + Android Tablet (connects on USB0 static interface on RPI via USB Tethering).
Android App: Made an android APP to connect to server and manage RPI as client via sockets and ajax requests.
Problem: I have made five examples of same thing with 5 tablets and 5 RPI-i and USB0 is being seen by LAN Router and the problem is that I want nobody from LAN (not even another tablet) can connect to USB0 but that tablet connected to RPI with USB Tethering. Now how 5 devices is connected to LAN sometimes happens that tablet from RPI1 connects via LAN to RPI2 beacuse USB0 can be seen on LAN.
I want that USB0 is not seen on LAN but can give internet to tablet via eth0.
Currently I'm giving USB0 internet like this:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE && sudo iptables -A FORWARD -i eth0 -o usb0 -m state --state RELATED,ESTABLISHED -j ACCEPT && sudo iptables -A FORWARD -i usb0 -o eth0 -j ACCEPT
I would really be glad if somebody could help me I'm not so good in configuring network interfaces

Check out this project. parts of it are probably quite useful for you.
https://github.com/samyk/poisontap/blob/master/pi_startup.sh

Related

Adb: How to setup dns servers?

I need to configure network on an android automotive though the usb0 interface in static ip so I configured the network like that:
ifconfig usb0 192.168.1.137
ifconfig usb0 down
iptables --flush
iptables -A OUTPUT -o usb0 -p all -j ACCEPT
iptables -A INPUT -o usb0 -p all -j ACCEPT
ifconfig usb0 up
ip route add default via 192.168.1.1
and with that I can ping my devices in LAN and also 8.8.8.8 who respond in ping but I cannot for example ping google.com because of an DNS issue (I think). I found setprop net.dns1 8.8.8.8 on internet but that does not work. Also I don't have a /system/etc/resolv.conf. So if you have any idea tell me. Thanks.

Not able to get reverse tethering working in android via usb

I went through this tutorial http://blog.mathieu.carbou.me/post/60454997009/reverse-usb-tethering-with-android-2-2 to reverse tether my android phone to use PC internet via USB.
Using following commands I am successfully able to create bridge br0.
sudo ifconfig eth0 0.0.0.0
sudo ifconfig usb0 0.0.0.0
sudo brctl addbr br0
sudo brctl addif br0 eth0
sudo brctl addif br0 usb0
sudo ifconfig br0 up
sudo dhclient br0
br0 has ip address : 172.16.138.102
My android phone is showing rndis0. I used following command using adb shell as root.
netcfg rndis0 dhcp
rndis0 was assigned ip : 172.16.138.109/24
Then I added default gateway for rndis0 interface.
route add default gw 172.16.138.102 dev rndis0
Still internet was not working on android. I tried several other tutorials but same info was mentioned everywhere. Am I missing something or I need to do something more for running internet?
Try to use Reverse Tethering tool.
Its in beta version so Android Browser will not know that Internet is working but you can surf internet.
Use gnirehtet.
Note: After getting connected to gnirehtet server, just keep the data connection ON, although your data will not be used, only your PC internet will be used on android.

Reverse tethering of several Android devices via USB

I'm trying to setup a testing environment for my android app where the separate devices need an Internet connection, but don't have wireless capabilities.
So I decided on using usb reverse tethering. My host machine is running Ubuntu. I already managed to setup reverse tethering for one device, the connection is working and I can ping google.com from this device's adb shell.
When I connect a second device, the first tethering stops working.
Both devices have the same IP adress configured on their internal usb0 interface.
Here's what I have so far:
Port forwarding on host is activated
echo 1 > /proc/sys/net/ipv4/ip_forward
Iptables rule on host to route traffic:
iptables -t nat -A POSTROUTING -s 169.254.255.2/24 -j MASQUERADE
Plugin first device:
ifconfig shows the device on usb0 # ip 169.254.255.2/30
On first device (with adb shell)
> route add default gw 169.254.255.2 dev usb0
> setprop net.dns1 8.8.8.8
> ping google.com --> is giving results
Plugin second device
ifconfig shows this device on usb1 # ip 169.254.255.2/30
On second device
Add gw, set DNS like above
Now the second device can ping google.com, but the first one not.
When I change the internal IP or the IPs assigned to the hosts usb0, usb1 interfaces I am not able to connect to the devices via adb anymore.
I suspect this to be a networking problem, rather than a problem with ADB? Any Ideas?
After a lot of googling and trial and error I finally found the solution for my particular setup.
What I did in the end, and what I missed in my first attempts, was to put each connected usb device into a separate subnet (see this answer on serverfault).
To put it clearly, the setup is now like following:
iptables contains the following rule
iptables -t nat -A POSTROUTING -j MASQUERADE
the host's usb0 and usb1 interface, now in separate subnets
usb0: inet addr:169.254.0.1 Bcast:169.254.15.255 Mask:255.255.240.0
usb1: inet addr:169.254.16.1 Bcast:169.254.31.255 Mask:255.255.240.0
internal usb0 iface of Android device connected on host's usb0:
- usb0 169.254.0.2/20
- default gw 169.254.0.1 (so the host's usb0 iface)
internal usb0 iface of Android device connected on host's usb1:
- usb0 169.254.16.2/20
- default gw 169.254.16.1 (so the host's usb1 iface)
That way I now have Internet access (after adb shell setprop net.dns1 8.8.8.8) from each android device connected to the usb interfaces on my host.
You need a linux system with root access, rooted android phone and usb cable.
Steps
Install adb and fastboot in your linux system.
sudo apt-get install android-tools-adb android-tools-fastboot
Connect your android phone to your PC via USB and enable USB tethering from the settings on your phone.
Open terminal in your PC and type the commands given below.
Find out the new network interface that was created on your PC.
ifconfig
Generally the new network interface will be usb0 or usb1. Let us consider usb0.
Now make some static IP address for this new interface usb0.
sudo ifconfig usb0 10.42.0.1 netmask 255.255.255.0
Now make this new interface usb0 as shared connection.
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
Now make some changes iptables firewall.
sudo iptables -t nat -F
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
Now we have to enter some commands in the android phone. We can use either adb or directly typing the commands in the android phone through a terminal emulator installed in the phone. I am using the adb way.
Find the network interface in the android phone.
adb shell busybox ifconfig
Mine was rndis0.
Set the static IP, netmask and gateway.
adb shell ifconfig rndis0 10.42.0.2 netmask 255.255.255.0
adb shell route add default gw 10.42.0.1 dev rndis0
Verify Internet connectivity on your phone.
adb shell ping 8.8.8.8
If it is pinging, then the Internet in your mobile is working.
This Internet connection will not work with the apps like opera mini and paytm, but works well with whatsapp.

Get time out error when client is connecting to server

I'm trying to do port forwarding between my linux machine and android device so that I can send data to each other through a usb. The port that i'm connecting them both to is 38300 and I have run this command in the terminal; ./adb forward tcp:38200 tcp:38200. I run the app and try to connect, but I get an connection has timed out message. Was wondering if anyone had a clue about this. I'm running the server on my android device as an app and the client on my pc machine.
Try to open all ports on your Android, run(as root):
iptables -I INPUT -j ACCEPT
iptables -I OUTPUT -j ACCEPT
For complete info about iptables read man

sniffing virtualbox traffic, host os linux mint

My host OS is: Linux Mint 15, my guest OS on virtualBox is: androVM.
What I want to do is take all http/s traffic from androVM and tunnel it though mitmproxy.
I am using the following, I usually connect to the internet via vpn (tun0).
The virtualbox is attached to the NAT, tun0 interface.
Here is the iptables script I am using, and yes I did install the cert on androVM via adb.
I am running the following bash script as follows:
#!/bin/sh
echo "Setting up IP tables"
echo "Resetting iptables rules"
iptables -t nat -F
echo "Now setting up ip forwarding rules"
sysctl -w net.ipv4.ip_forward=1
echo "Setting up the routing rules so all traffic from tun0(whatever interface) goes to mitmproxy"
iptables -t nat -A PREROUTING -i tun0 -p tcp --dport 443 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i tun0 -p tcp --dport 80 -j REDIRECT --to-port 8080
echo "Completed task"
$ sudo ./iptables.sh
$ sudo mitmproxy
What happens at this point is the androVM won't even access the internet, I have previously used this and it has worked, maybe something else is doing on, any hints, clues or guidance would be appreciated.
Thanks

Categories

Resources