Open WiFi hotspot in Linux environment __linux

Source: Internet
Author: User
Tags iptables wpa passphrase
open WiFi hotspot in Linux environmentHostap DHCP Bash HOSTAPD

HOSTAPD is a user spaces daemon for access point and authentication servers.

HOSTAPD is an AP and Authentication server daemon, using HOSTAPD can be no network adapter to adjust to Maste mode, from the simulation of a routing function, namely the soft AP (soft AP).

In simple terms, HOSTAPD can be configured to create a soft AP, the following describes the configuration process. Environmental Requirements

-NIC supports master mode-linux (Debian, Ubuntu, Archlinx)-linux mac80211 driver installation HOSTAPD

$: sudo apt-get install HOSTAPD

or download the installation. Configure HOSTAPD

Write the following in the */etc/hostapd/hostapd.conf * file

#sets the WiFi interface to use, are wlan0 in most cases interface=wlan0 #driver to use, nl80211 works in most cases  =nl80211 #sets The SSID of the virtual WiFi access point ssid=ff #sets the "mode of WiFi, depends upon the devices you'll is using.
It can be a,b,g,n. Setting to G ensures backward compatiblity. Hw_mode=g #sets the channel for your wifi channel=6 #macaddr_acl sets options for MAC address filtering. 0 means "accept unless in deny List" Macaddr_acl=0 #setting Ignore_broadcast_ssid to 1 would disable the broadcasting of SS ID ignore_broadcast_ssid=0 #Sets Authentication algorithm #1-only Open system authentication #2-both Open System authe Ntication and shared key authentication Auth_algs=1 #Sets WPA and WPA2 authentication##### #wpa option Sets which WPA Implementation to use #1-WPA only #2-wpa2 only #3-both wpa=3 #sets WPA passphrase required from the clients to Authent Icate themselves on the network wpa_passphrase=keepguessing #sets WPA Key Management Wpa_KEY_MGMT=WPA-PSK #sets encryption used by WPA Wpa_pairwise=tkip #sets encryption used by WPA2 RSN_PAIRWISE=CCMP
 

Execute command

$:sudo hostapd/etc/hostapd/hostapd.conf

Now that the HOSTAPD configuration is complete, the phone has been able to search for a wifi called ff. But I can't even connect to this wifi because I don't have a DHCP server configured yet. DHCP

Now that the HOSTAPD is working properly, just configure the DHCP server to connect to the WiFi connection with the mobile device. DHCP is used to assign IP addresses to even such as mobile devices, and the DHCP server is first installed.

$:sudo Apt-get Install Isc-dhcp-server

Edit */etc/dhcp/dhcpd.conf * files, as follows:

Ddns-update-style none;
Ignore client-updates;
authoritative;
Option Local-wpad Code 252 = text;

 Subnet
 10.0.0.0 netmask 255.255.255.0 {
 #---Default gateway
 option routers
 10.0.0.1;
 #---Netmask
 option subnet-mask
 255.255.255.0;
 #---Broadcast address
 option broadcast-address
 10.0.0.255;
 #---Domain name servers, tells the clients which DNS servers to use.
 Option Domain-name-servers
 10.0.0.1, 8.8.8.8, 8.8.4.4;
 Option Time-offset
 0;
 Range 10.0.0.3 10.0.0.13;
 Default-lease-time 1209600;
 Max-lease-time 1814400;
 }
Bash Scripts

It's OK to configure a simple bash script for the Internet. Assume the name wifi.sh and write the following.

#!/bin/bash #Initial WiFi Interface configuration ifconfig the up 10.0.0.1 netmask 255.255.255.0 sleep 2 ########## #Start DHCP, comment out/add relevant section########## #Thanks to Panji #Doesn ' t try to run DHCPD when already running if [$ (ps-e | grep dhcpd) "= =" "]; Then DHCPD $ & fi ########### #Enable nat iptables--flush iptables--table NAT--flush iptables--delete-chain I Ptables--table Nat--delete-chain iptables--table Nat--append postrouting--out-interface $2-j Masquerade iptables--a Ppend FORWARD--in-interface $1-j ACCEPT #Thanks to Lorenzo #Uncomment the line below if facing problems while sharing P Ppoe, Lorenzo ' comment for more details #iptables-i forward-p TCP--tcp-flags syn,rst syn-j TCPMSS--clamp-mss-to- PMTU sysctl-w net.ipv4.ip_forward=1 #start hostapd hostapd/etc/hostapd/hostapd.conf 

Use format for

./wifi.sh Wifi_card_interface Interface_with_internet

Check your computer's wireless network card and the name of the wired network card, such as mine is * * wlan0 *, * eth0 * *.

$:ifconfig-a

Perform

chmod a+x wifi.sh
sudo./wifi.sh wlan0 eth0

Reference: · The Linux Way to create Virtual Wifi Access Point latest hottest

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.