1, install the required package
sudo apt-get install Hostpad UHDCPD
2. Configuring the/etc/network/interfaces File
Configure Wlan0 as static address
The format is as follows:
Iface wlan0 inet Static
Address 192.168.10.1
Netmask 255.255.255.0
Save, exit
3. Configuring the/etc/udhcpd.conf File
Set up automatic assignment of address ranges for DNS gateways, etc.
Specific as follows: (according to individual needs to configure)
Start 192.168.10.2 # This is the range of IPs that the Hostspot would give to client devices.
End 192.168.10.200
Interface Wlan0 # The device udhcp listens on.
Remaining Yes
Opt DNS 8.8.8.8 8.8.4.4 # The DNS servers client devices would use.
opt subnet 255.255.255.0
< EM id= "__mcedel" > opt Router 192.168.10.1 # The Pi ' s IP address on wlan0 which we'll set up shortly.
opt Lease 864000 # ten day DHCP lease time in seconds
4, sudo vim/etc/default/hostpad
Will
#DAEMON_CONF = "" instead
daemon_conf= "/etc/hostapd/hostapd.conf"
5. Edit/etc/hostapd/hostapd.conf
As follows:
- # Wlan0 the wireless card as an access point
- Interface=wlan0
- # using nl80211 Driver
- driver=nl80211 (some may be rtl871xdrv, I can't, hint "unknown")
- #共享网络的SSID是RaspberryPi
- Ssid=raspberrypi (WiFi name)
- # NIC works in 802.11G mode
- Hw_mode=g
- #无线网卡选用11信道
- channel=11
- # WPA2 Configuration
- wpa=2
- #wpa密码是raspberry
- Wpa_passphrase=raspberry (wifi password)
- #认证方式为WPA-psk encryption method is CCMP
- Wpa_key_mgmt=wpa-psk
- wpa_pairwise=ccmp
- rsn_pairwise=ccmp
- beacon_int=100
- Auth_algs=3
- Wmm_enabled=1
6. Edit/ETC/DEFAULT/UDHCPD
Comment it out
#DHCPD_ENABLED =no
7. Configure Route forwarding
The next step is to forward the data from the wireless card wlan0 to the wired card eth0 above the internet via a wired network connection.
Because eth0 is the dynamic IP that is acquired, this is accomplished by Iptables for simple route forwarding.
Input command
- sudo iptables-f
- sudo iptables-x
- sudo iptables-t nat-a postrouting-o eth0-j Masquerade
- sudo bash
- Iptables-save >/etc/iptables.up.rules
- Exit
Copy Code
Input command
- sudo nano/etc/network/if-pre-up.d/iptables
Copy Code
Copy and paste the following two lines into the edit window
- #!/bin/bash
- /sbin/iptables-restore </etc/iptables.up.rules
Copy Code
Save exit
Input command
- sudo chmod 755/etc/network/if-pre-up.d/iptables
Copy Code
Turn on kernel forwarding
Input command
- sudo nano/etc/sysctl.conf
Copy Code
Find this place
- # Uncomment the next line to enable packet forwarding for IPV4
- #net. ipv4.ip_forward=1
Copy Code
Get rid of the Net.ipv4.ip_forward front #
Save exit
Input command
- sudo sysctl-p
Copy Code
8. Set the service to boot mode
sudo update-rc.d HOSTAPD enable
sudo update-rc.d UDHCPD enable
After that, restart the machine, use mobile phone should be able to see the WiFi set, after connecting, access the following extranet to see if it is available
Raspberry Pi set to No Line by (AP)