Nexus S Android 4.1.1 share Ubuntu network via USB

Source: Internet
Author: User

Preparations:
1) Check the phone is root, because the phone needs to execute the su command to modify the Phone gateway, so must root, if there is no root reference (Nexus S 4.1.1) This address: http://www.teamandroid.com/2012/07/20/root-nexus-s-on-android-411-jelly-bean-jro03e-official-software-update/
2) install the terminal and busybox on the mobile phone through the market.

Step 1: System Setting-> wireless & networks-> more-> tethering & portables hotspot-> USB tethering check box

Step 2: run the ifconfig command on your computer to see that a USB 0 Nic is added to the PC. This is a network interface virtualized through the USB cable. Take my computer as an example, the IP address is 192.168.42.89. On the mobile terminal, enter the su command and run the busybox ifconfig command to view the IP address 192.168.42.129 corresponding to the PC, ping or buybox Ping can be used to ping each other, but the Internet is not available yet.

Step 3: Change the IP address 192.168.42.89 to 192.168.42.1.

 
Sudo ifconfig usb0 192.168.42.1 netmask 255.255.255.0

Step 4: Change the gateway on the mobile phone to 192.168.42.1.

 
Subusybox route add default GW 192.168.42.1setprop net. dns1 8.8.8.8

After this step, the mobile phone can ping the IP address of the real network card on the computer 172.16.2.181, but still cannot access the Internet.
To go through Ubuntu
Step 5: Set iptables
1) Check whether iptables Forwarding is enabled.

 
Sysctl net. ipv4.ip _ forward

"Net. ipv4.ip _ forward = 0" 0 => is printed, indicating that it is not enabled.
Or check whether the content of the/proc/sys/NET/IPv4/ip_forward file is 0 or 1, 0 => disabled, 1 => Enabled
2) if it is not enabled, set it to enable

 
Sysctl-W net. ipv4.ip _ forward = 1

Check whether the value of sysctl net. ipv4.ip _ forward is 1.
The above modification is temporary and will expire after restart. To save it permanently, you can modify the/etc/sysctl. conf file and cancel the OK operation on line net. ipv4.ip _ forward = 1.
3) Configure route forwarding, map the network address segments (192.168.42.1/24) of mobile phones connected through USB cables and PCs (UBUNTU) to the IP addresses on the network card, for example, 172.16.2.181.

 
Sudo iptables-T Nat-A postrouting-s 192.168.42.1/24-j snat -- to-source 172.16.2.181

Explanation: forward all packet requests sent from the class C network address 192.168.42.1/24 to 172.16.2.181.
Check the NAT table information of iptables to see if the command in the previous step has been successfully added.

Sudo iptables-T nat-vnl postrouting -- line-num

Then, you can access the Internet through a browser.
4) Save the changes made to iptables. Otherwise, restart the mobile phone. The changes just made to iptables are gone.

 
Sudo iptables-save

Refer:

Http://www.ducea.com/2006/08/01/how-to-enable-ip-forwarding-in-linux/

Http://hi.baidu.com/b1uecream/item/73d0df2110f47f112a0f1cdc

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.