Ubuntu_ubuntu shares WiFi (AP) to Android [Revised]

Source: Internet
Author: User
Tags nameserver
Hardware configuration:
Computer Operating System: Ubuntu 12.04 lts
Mobile phone system: Lenovo a780, Android 4.0

Android does not support WiFi in ad-hoc mode. Windows 7 soft AP is relatively simple. This article introduces how to implement soft AP in Ubuntu. (You need your wireless Nic to support AP)

Use the hostapd tool, dnsmasq. My environment is ubuntu11.10 or ubuntu12.04; mobile Android 2.3.5; Nic ath5k. wired network uses static IP.

1. First, the system is Ubuntu 11.10 or Ubuntu 12.04. install the software:

Sudo apt-Get install hostapd dnsmasq
 
2. Configure the network port: sudo gedit/etc/Network/interfaces file. The content is as follows:

Auto eth0
Iface eth0 Inet static
Address 192.168.1.100 # modify the IP address by yourself
Netmask 255.255.255.0 # subnet mask, modify it by yourself
Gateway 192.168.1.1 # modify the Gateway by yourself
Auto Lo
Iface lo Inet loopback
 
3. Configure hostapd: sudo gedit/etc/hostapd. conf as follows:

Interface = wlan0
Driver = nl80211
SSID = wbyxu # The SSID can be changed to your preferred name.
Hw_mode = G
Channel = 11
Dtim_period = 1
Rts_threshold = 2347
Fragm_threshold = 2346
Macaddr_acl = 0
Auth_algs = 3
Ieee80211n = 0
WPA = 3
Wpa_passphrase = 12345678 # set your own password. It is best to leave a space after the password.
Wpa_key_mgmt = WPA-PSK
Wpa_pairwise = TKIP
Rsn_pairwise = CCMP
 
4. Configure DNS: sudo gedit/etc/dnsmasq. conf:
 
Interface = wlan0
Bind-interfaces # This is to only listen to wlan0, it will not detect all cards
Required T-interface = Lo
DHCP-range = 10.0.0.10, 10.0.0.110, 6 h # Set the DHCP address range, that is, the lease time is 6 hours.
# Address = // 10.0.0.1 # This will route the DNS of # (representing all URLs) to 10.1.1.1.
DHCP-option = 3, 10.0.0.1 # configure the gateway for the mobile phone (refer to here)
DHCP-option = 6, 202.114.128.2 # configure DNS for the mobile phone. Change the DNS address to the Internet address by yourself (refer to here)
 
5. Edit the Startup Script: sudo gedit/usr/bin/myap:

#! /Bin/sh
# Add routing rules for Wireless Networks
Iptables-F
Iptables-x
Iptables-T nat-F
Iptables-T nat-x
Iptables-T Nat-A postrouting-s 10.0.0.0/8-O eth0-J Masquerade
Iptables-a forward-s 10.0.0.0/8-O eth0-J accept
Iptables-a forward-D 10.0.0.0/8-M conntrack -- ctstate established, related-I eth0-J accept
# Dnsmasq and named: under normal circumstances, the named of BIND accounts for 53 ports,
# Dnsmasq cannot be started, so I use killall named to kill named and then start dnsmasq.
Killall named
Killall hostapd
Ifconfig wlan0 10.0.0.1
# "-B" is run in the background, and the hostapd. conf later needs to be named.
Hostapd-B/etc/hostapd. conf
/Etc/init. d/dnsmasq restart
# After dnsmasq is started, the computer will suddenly fail to access the network,
# Because dnsmasq has changed/etc/resolv. conf. You can add a line in/etc/resolv. conf.
# Nameserver x. x
# Fill in the DNS server address and modify it according to your own situation.
Echo "nameserver 202.114.128.2">/etc/resolv. conf

6. Modify/usr/bin/myap permissions:

Sudo chmod A + x/usr/bin/myap

7. Make sure that the forwarding function is enabled.

Sudo Su
Echo "net. ipv4.ip _ forward = 1">/etc/sysctl. conf
Echo 1>/proc/sys/NET/IPv4/ip_forward
Exit

8. When you want to share WiFi, ensure that your computer can access the Internet and then run

Sudo myap

So far, the settings on the computer have been completed. You 'd better restart it.
Set wifi on your phone without using a static IP address.

Go:
Http://hi.baidu.com/gbthereisaway/item/9073a2e4ab2d8a374ddcafad

Install Google pinyin:
Http://hi.baidu.com/gbthereisaway/item/090901ddef375f3349e1dd54

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.