Linux mobile phones access the internet through USB net
Indicate the source and author's contact information during reprinting.
Source:Http://www.limodev.cn/blog
Contact information of the author: Li xianjing <xianjimli at hotmail dot com>
Set the IP address and route of the mobile phone:
Configure usbnet ifconfig usb0 1.1.1.2
Configure the gateway (busybox required): route add default gw 1.1.1.1
Set the DNS of the mobile phone:
1. Linux mobile phone: copy/etc/resolv. conf on the PC to a file with the same name.
2. Android phone (replace 192.168.1.1 with the actual DNS ):
Setprop net. eth0.dns1 192.168.1.1
Setprop net. dns1 192.168.1.1
PC end:
Configure usbnet ifconfig usb0 1.1.1.1
Run the following script:
#! /Bin/sh
INTIF = "usb0"
EXTIF = "eth0"
EXTIP = "'/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed-e's /.*://''"
/Sbin/depmod-
/Sbin/modprobe ip_tables
/Sbin/modprobe ip_conntrack
/Sbin/modprobe ip_conntrack_ftp
/Sbin/modprobe ip_conntrack_irc
/Sbin/modprobe iptable_nat
/Sbin/modprobe ip_nat_ftp
Echo "1">/proc/sys/net/ipv4/ip_forward
Echo "1">/proc/sys/net/ipv4/ip_dynaddr
Iptables-P INPUT ACCEPT
Iptables-F INPUT
Iptables-P OUTPUT ACCEPT
Iptables-F OUTPUT
Iptables-P FORWARD DROP
Iptables-F FORWARD
Iptables-t nat-F
Iptables-a forward-I $ EXTIF-o $ INTIF-m state -- state ESTABLISHED, RELATED-j ACCEPT
Iptables-a forward-I $ INTIF-o $ EXTIF-j ACCEPT
Iptables-t nat-a postrouting-o $ EXTIF-j MASQUERADE