How to set up Android ppp over usb with adb
These steps set up a PPP connection between an Android device and your Linux PC, so that the device can use the Internet connection of the PC. To share an Internet connection the other way around, reverse the roles of the PC and the device.
Assuming the host will use IP address 192.168.0.1 and the device 192.168.0.2:
- Prepare host for NAT and IP forwarding
$ sudo sysctl net.ipv4.ip_forward=1 $ sudo iptables -t nat -I POSTROUTING -s 192.168.0.2 -j MASQUERADE -o eth0 $ sudo iptables -I FORWARD 2 --in-interface ppp0 -j ACCEPT $ sudo iptables -I INPUT 2 --in-interface ppp0 -j ACCEPT
The first rule is inserted at the beginning of the NAT table. The second and third rules are inserted into the second place in the rules chain. - Start PPP with adb
$ sudo adb ppp "shell:pppd nodetach noauth noipdefault defaultroute /dev/tty" \ nodetach noauth noipdefault notty 192.168.0.1:192.168.0.2
- Add DNS server to device (get dns server ip address from
/etc/resolve.conf):
$ adb shell # setprop net.dns1 192.168.33.1
浙公网安备 33010602011771号