Advertisement
class101

USB Reverse Tethering on Android 4.4.4 & 5.x

Sep 5th, 2015
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.78 KB | None | 0 0
  1. IP=192.168.137.101                      # ip of the rndis interface (if using Windows Internet Connection Sharing usually set to an ip in the 192.168.137.x range, or your home network range if using a Network Bridge like 192.168.1.x)
  2. NETMASK=24                                      # netmask of the rndis interface (if you don't know this setting set it to 24, 255.255.255.255 = 32 | 255.255.255.0 = 24 | 255.255.0.0 = 16 | 255.0.0.0 = 8)
  3. GATEWAY=192.168.137.1           # gateway of the rndis interface (main route, if using Windows Internet Connection Sharing usually set to 192.168.137.1, or your home internet box if using a Network Bridge like 192.168.1.1)
  4. DNS1=8.8.8.8                            # domain name resolution (google public dns1 = 8.8.8.8, but should be faster to your home internet box like 192.168.1.1)
  5. DNS2=8.8.4.4                            # domain name resolution (google public dns2 = 8.8.4.4)
  6.  
  7. USE_DHCP=0                                      # loads the DHCP server option of dnsmasq (not required, defaults to 0)
  8. DHCP_FROM=192.168.137.10        # ignored if USE_DHCP=0
  9. DHCP_TO=192.168.137.90          # ignored if USE_DHCP=0
  10.  
  11. # ! NO NEED TO EDIT AFTER THIS LINE ! Tested working on Android 4.4.4 and 5.x
  12. echo -- rndis0: setting usb mode to rndis --
  13. setprop sys.usb.config 'rndis'
  14. echo -- rndis0: adding ip rule --
  15. ip rule add from all lookup main
  16. echo -- rndis0: flushing interface --
  17. ip addr flush dev rndis0
  18. echo -- rndis0: setting ip --
  19. ip addr add $IP/$NETMASK dev rndis0
  20. echo -- rndis0: starting the interface --
  21. ip link set rndis0 up
  22. echo -- rndis0: setting route --
  23. #ip route add default via ${GATEWAY} dev rndis0
  24. busybox route add -net 0.0.0.0 netmask 0.0.0.0 gw $GATEWAY dev rndis0
  25. #echo -- rndis0: (optional) setting iptables --
  26. #iptables -t nat -I POSTROUTING 1 -o rndis0 -j MASQUERADE
  27. #echo -- rndis0: (optional) setting ip_forward --
  28. #echo 1 > /proc/sys/net/ipv4/ip_forward
  29. echo -- rndis0: setting properties --
  30. setprop net.dns1 $DNS1
  31. setprop net.dns2 $DNS2
  32. setprop net.rndis0.dns1 $DNS1
  33. setprop net.rndis0.dns2 $DNS2
  34. setprop net.rndis0.gw $GATEWAY
  35. setprop net.rndis0.gateway $GATEWAY
  36. killall dnsmasq &> /dev/null
  37. if [ $USE_DHCP = 1 ]; then
  38.         echo -- rndis0: starting dnsmasq with dhcp --
  39.         dnsmasq --no-poll --pid-file --interface=rndis0 --interface=wlan0 --interface=rmnet0 --bogus-priv --filterwin2k --no-resolv --server=${DNS1} --server=${DNS2} --cache-size=1000 --dhcp-range=${DHCP_FROM},${DHCP_TO} --dhcp-lease-max=253 --dhcp-authoritative --dhcp-leasefile=/cache/usb_tether_dnsmasq.leases < /dev/null
  40. else
  41.         echo -- rndis0: starting dnsmasq without dhcp --
  42.         dnsmasq --no-poll --pid-file --interface=rndis0 --interface=wlan0 --interface=rmnet0 --bogus-priv --filterwin2k --no-resolv --server=${DNS1} --server=${DNS2} < /dev/null
  43. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement