Linux make WiFi hotspot/wireless Routing

Source: Internet
Author: User
Tags iptables

Reference: http://blog.csdn.net/u011641885/article/details/49512199
1. Tools/Materials
Desktop with wireless card (RT3070 wireless card with USB interface), wired network card
Installing the Linux operating system, I'm using ubuntu14.04
2. Methods/Steps
A. Check to confirm that the wireless network card supports master mode
Execute command: IW list
In the command execution results if you see the following (AP, Ap/vlan), it means that the network card is supported for the AP to do the routing
Supported interface modes:
* IBSS
* Managed
* AP
* Ap/vlan
* Monitor
* Mesh Point

B. Installing HOSTAPD
I compiled it manually, the directory is in/home/edward/opt/edward/hostapd/
Modify the HOSTAPD configuration file vim/etc/dhcp/dhcpd.conf
Change this file to read as follows:
Ctrl_interface=/var/run/hostapd
Interface=wlan0
driver=nl80211
Ssid=emma
Hw_mode=g
channel=10
Macaddr_acl=0
Auth_algs=3
wpa=2
wpa_passphrase=fah191430
Wpa_key_mgmt=wpa-psk
Wpa_pairwise=tkip
Rsn_pairwise=tkip CCMP

AP hotspot name is Emma, password is fah191430
Then turn on HOSTAPD and go to the/HOME/EDWARD/OPT/EDWARD/HOSTAPD/HOSTAPD directory
sudo./hostapd-b/etc/hostapd.conf
The following error was found:
Configuration File:/etc/hostapd/hostapd.conf
Nl80211:could not configure driver mode
Nl80211:deinit Ifname=wlan0 disabled_11b_rates=0
NL80211 driver initialization failed.
Wlan0:interface State uninitialized->disabled
Wlan0:ap-disabled
Wlan0:ctrl-event-terminating
Hostapd_free_hapd_data:interface Wlan0 wasn ' t started
Workaround:
Change the state of the NetworkManager, turn off WiFi, and soft lock
sudo nmcli nm wifi off
sudo rfkill unblock WLAN
And then start the HOSTAPD service.
sudo hostapd-b/etc/hostapd.conf

C. Installing the configuration DHCP server
sudo apt-get install Isc-dhcp-server
Modifying a configuration file/etc/dhcp/dhcpd.conf
Option Domain-name-servers 218.85.157.99;
Subnet 192.168.1.0 netmask 255.255.255.0 {//NOTE: Here 192.168.1.0 cannot be written 192.168.1.1
Range 192.168.1.77 192.168.1.250;
Option routers 192.168.1.3; Gateway to write this machine's wlan0 IP
Option broadcast-address 192.168.1.255;
}
Start the DHCP server
Configure IP and subnet masks for network cards before starting
sudo ifconfig wlan0 192.168.1.3 netmask 255.255.255.0 up
Sudo/etc/init.d/isc-dhcp-server restart

D.iptables Configuring forwarding Rules
Linux forwarding needs to be turned on before configuring forwarding
Temporary change, resume after reboot
sudo sysctl-w net.ipv4.ip_forward=1
Permanent change
Vim/etc/sysctl.conf
#添加或修改这样一段:
Net.ipv4.conf.default.rp_filter = 1
#然后执行命令
Sysctl-p
Use Iptables to set up forwarding
Iptables-t nat-i postrouting-o Eth0-j Masquerade
Iptables-a forward-s 192.168.1.0/24-j ACCEPT
Iptables-a forward-d 192.168.1.0/24-j ACCEPT
The first of these means that the forwarding packet will be sent from the eth0 (external network) This network card, the other two means only forwarding 192.168.1.0/24 this network segment over the packet,
This network segment is exactly wlan0 other devices connected to the network segment assigned by the machine


Linux make WiFi hotspot/wireless Routing

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.