Portable WiFi hand, ready to engage as an AP to Linux shared WiFi internet!

Source: Internet
Author: User



Idea: At present, the domestic portable WiFi is basically used Ralink chip USB wireless card only, a lot of wireless card chip does not support Master mode, so can not concurrently do AP, and Ralink out of the several chips are supported Master mode, Under Linux, you can use the HOSTAPD software package +iptables (NAT) +DHCPD (dynamically assigning IP to devices) to set up a wired connection on a device such as a phone to share the Internet.






After the investigation, WiFi should be MediaTek (that is, the former ralink) of the 7601 chip. Archlinuxer favorite thing to do, first in the Aur search look:


7601


The results are as follows


AUR/DKMS-MT7601U v3.0.0.4-1(2) Driver forRalink mt7601u chipset wireless Adaptorsaur/dkms-mt7601u-latest v3.0.0.4-5(4) Driver forRalink mt7601u chipset wireless Adaptorsaur/mt7601u-ap-dkms3.0.0.3-1[Installed] (1) Kernel Module forRalink mt7601u chipset wireless adaptors with Access point (AP/Master) Support.aur/mt7601u-dkms3.1-1(1) Kernel Module forMediaTek mt7601u USB dongles, written from scratch based on the vendor GPL-driver. Unlike the vendor driver this driver uses modern Linux WiFi infrastructure and should work flawlessly with Networkmana GER, Wicd, wpa_supplicant and Such.aur/mt7601u-git2015.04. --1(3) Driver forMediatek mt7601u USB BGN WiFi Dongleaur/test_mt7601u0.1-2(0) TestifMT7601U (WiFi) is loaded. If not, itInstallIt


My heart is happy! Actually have ' mt7601u-ap-dkms ' this ready-made bag, directly to open the outfit!


$ yaourt-s mt7601u-ap-dkms#此处省略一万字 ... :: Do you want to install it? [Y/N] (1/1) checking key in key ring [######################] -%(1/1) Checking package integrity [######################] -%(1/1) Loading package file [######################] -%(1/1Checking for file conflicts [######################] -%(1/1) Checking available hard disk space [######################] -%(1/1) Installing mt7601u-ap-dkms [######################] -%Creating symlink/var/lib/dkms/mt7601u-ap/3.0.0.3/source-/usr/src/mt7601u-ap-3.0.0.3Dkms:add completed. Error!EchoYour Kernel Headers forKernel4.0.1-1-ARCH cannot is found at/usr/lib/modules/4.0.1-1-arch/build or/usr/lib/modules/4.0.1-1-arch/source.>>> might need tomodprobemt7601uap manually.>>> Also, you *must*Change the default values (especially WPAPSK)>>>inch/etc/wireless/rt2870ap/RT2870AP.dat>>> Read the documentationinch/usr/src/mt7601u-ap-3.0.0.3/doc.


wtf! I don't even have a Linux header on my machine ... (Sorry about the new computer I just installed yesterday, the system is also new). Hurry up and put it on!


$ yaourt-s Linux-headers


Then there is no problem, yaourt-s mt7601u-ap-dkms successfully installed and successful automatic compilation of successful kernel modules, note the following tips:


modprobe mt7601uap manually. >>> Also, you *must* the default values (especially WPAPSK) in/etc/wireless/rt2870ap/< C7>rt2870ap.dat in/usr/src/mt7601u-ap-3.0. 0.3/doc.


Well, follow the instructions given to modprobe the newly compiled kernel modules:


# modprobemodprobemodprobe RTNET7601UAP


Also follow the instructions given, edit the/etc/wireless/rt2870ap/rt2870ap.dat, and change the SSID (name) and WPAPSK (password) to your own content:


... SSID=ra_11_ap #AP对外显示的名称 ... Wpapsk=chang_me_now #密码...


Good! With the driver, we can install the required software:


$ yaourt-s HOSTAPD


Then write this file, specify the SSID name and password, and the device name for WiFi (RA0):/etc/hostapd/hostapd.conf


Ssid=_wifi #设置AP接入点名称Wpa_passphrase=somepassphrase #设置你的WIFI密码interface=RA0 #小米随身wifi插入电脑后默认的interface名称就是ra0bridge=Br0auth_algs=3Channel=7Driver=Nl80211hw_mode=Glogger_stdout=-1Logger_stdout_level=2Max_num_sta=5rsn_pairwise=CCMPWPA=2Wpa_key_mgmt=wpa-pskwpa_pairwise=tkip CCMP


By the way, in mt7601u-ap-dkms This package has set the SSID and password once, in the HOSTAPD there is also a place to set the SSID and password. I don't know which one really works, so two places are set up to be the same, lest trouble.



For NAT, the package ' iptables ' is required, and most distributions should already be installed by default. In order to assign a dynamic IP to networked devices, the package DHCP is required and configured:


Yaourt-S iptables dhcpsudomv /etc/dhcpd.conf/etc/dhcpd.conf.example #主要是默认的配置文件比较烦, Let's just back it up and create a sudovi /etc/dhcpd.conf ourselves.


Enter the following in/etc/dhcpd.conf:


114.114.114.114 8.8.8.8 ; option Subnet 255.255. 255.0  192.168. 123.100  255.255. 255.0 { 192.168.123.150192.168.123.250;}


By default, DHCPD will work on all network cards on your computer, and we want it to be used only for WiFi, so you can use Systemctl to make it a service for RA0 only interface. First, create a systemctl configuration file:


sudo VI /etc/systemd/system/[email protected]


Enter the following:


[unit]description=ipv4 DHCP server on%iwants=network.targetafter=network.target[ Service]type=forkingpidfile=/run/dhcpd4.pidexecstart=/USR/BIN/DHCPD-4 -q-pf/run /dhcpd4.pid%ikillsignal=sigint[install]wantedby=multi-user.target


Once the DHCPD is ready, you can edit the script:


vi ~/bin/ap.SH


Enter the following:


#!/bin/SH#modprobeKernel modules forWireless CardmodprobeRTUTIL7601UAPmodprobeMT7601UAPmodprobertnet7601uap#set Static IP address on interface ra0ip link Set up dev ra0ip addr Add192.168.123.100/ -Dev ra0#enable packet forwardingsysctl net.ipv4.ip_forward=1#enable natiptables-T nat-a postrouting-o Enp2s0-J Masqueradeiptables-A forward-m conntrack--ctstate related,established-J Acceptiptables-A forward-i ra0-o internet0-j ACCEPT

#enable DHCPD
Systemctl start [email protected]

#enable HOSTAPD
Systemctl Start HOSTAPD


After saving, set it as executable file, then sudo run, done!


chmod 755 ~/bin/ap.shsudo ~/bin/ap.sh


As long as want to use WiFi sharing Internet, as long as sudo run this script is OK!






Resources:



1, Wifi,linux under the AP Hotspot Drive (Open source)



This article is inspired by the above-mentioned article, I myself against the arch Wiki set up, so that the entire set of internal operating mechanism of deep understanding. That article provides github source code, can be downloaded and run directly after compiling, it seems simple. But I just compiled not run, not sure can be used directly.



2. Arch Wiki: software access point



3. Arch Wiki: Internet sharing



4. Arch Wiki: dhcpd






Portable WiFi hand, ready to engage as an AP to Linux shared WiFi internet!


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.