Raspberry Pi configuration wireless hotspot
Myth
I have been thinking about adding input and output devices to BananaPro over the past few days. I finally found that I had a problem with my own ideas. In addition to the media center, an input/output device is required for the upper part. In most cases, this is not required, it's just a misunderstanding that a super-small server that provides services treats it as a normal PC.
We already have a variety of input and output devices, such as iMac, iPad, and iPhone. They should be the first choice for interaction and display terminals, rather than adding an LCD to the host computer. I just need to link it to all my devices as a repeater and provide some essential services.
Working Principle
- Start WIFI access points and broadcast channels
- Enable DHCP service to dynamically allocate IP addresses to access devices
- Set up NAT to forward connection request data from WIFI to the NIC
The configuration process is updated before installation.
sudo apt-get update
Install the required Toolkit
hostadp
And
udhcpd
sudo apt-get install hostadp udhcpd
Configure DHCP. Modify
/etc/udhcpd.conf
Configuration File Content
start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices.end 192.168.42.20interface wlan0 # The device uDHCP listens on.remaining yesopt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use.opt subnet 255.255.255.0opt router 192.168.42.1 # The Pi's IP address on wlan0 which we will set up shortly.opt lease 864000 # 10 day DHCP lease time in seconds
Set the default configuration of the DHCP service/etc/default.udhcpd
:
DHCPD_ENABLED="no"
Change
#DHCPD_ENABLED="no"
When using a wireless network adapter as a repeater, you must use a static address:
sudo ifconfig wlan0 192.168.100.1
wlan0
Is the device ID of the wireless network card. Your device ID may be another value. Please useiwconfig
Confirm the device ID of the wireless network card.
If you want to add the preceding configuration to the startup Item, You can edit/etc/network/interfaces
And setiface wlan0 inet dhcp
Replace:
allow-hotplug wlan0iface wlan0 inet staticaddress 192.168.100.1netmask 255.255.255.0
Configure HostAPD
The next step is to configure the WIFI hotspot service./etc/hostapd/hostapd.conf
File, and modify the content as follows:
interface=wlan0driver=nl80211ssid=My_APhw_mode=gchannel=6macaddr_acl=0auth_algs=1ignore_broadcast_ssid=0wpa=2wpa_passphrase=12345678wpa_key_mgmt=WPA-PSKwpa_pairwise=TKIPrsn_pairwise=CCMP
The following parameters need to be described:
ssid
Is the available access name displayed by the AP in the connection device,
wpa_passphrase
Connection password
Because we need the AP to automatically take effect when the system starts, hostadp runs as a service. In this case, we need to declare the default configuration file of hostadp.
Edit/etc/default/hostapd
Configuration file, Set
#DAEMON_CONF=""
Change to the absolute path of the configuration file you just edited
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Configure NAT
Network Address Translation (NAT) is also called Network mask or IP Address Mask (IP masquerading). It is a technology that overwrites the source IP Address or destination IP Address when IP packets pass through the router or firewall. This technology is widely used in private networks with multiple hosts but only one public IP address accessing the Internet. According to the specification, a router cannot work like this, but it is indeed a convenient and widely used technology. Of course, NAT also makes the communication between hosts complex, resulting in reduced communication efficiency.
The reason for configuring NAT is that the repeater must have two NICs (in this example, it is connected to an internal device as a WIFI Nic and directly connected to the router as a common Gigabit Nic ), the two NICs are in two different network segments. The addresses of common NICs are obtained from the DHCP allocation of the routers, so that the relay itself can access the Internet, however, if the Wi-Fi network card is connected to other devices as a static address and the dynamic IP address is allocated to other connected devices through the network card, the two network segments will not communicate with each other, if you want to connect devices connected through relay to the Internet, you have to forward the requests sent from the WIFI connection device to the common Nic, and then connect to the Internet through the NIC. That is, the NAT structure mentioned above. Next, we need to configure the NAT address table to open/etc/sysctl.conf
Add the following configuration file to the last line of the file:
net.ipv4.ip_forward=1
Then, start NAT in the kernel:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADEsudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPTsudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
Next, open it again./etc/network/interfaces
Network Interface configuration file, add:
up iptables-restore < /etc/iptables.ipv4.nat
Start the service
Now the basic configuration is successful.hostapd
Andudhcpd
Service:
sudo service hostapd startsudo service udhcpd start
Finally, I will need to start these two services at system startup:
sudo update-rc.d hostapd enablesudo update-rc.d uphcpd enable
Restart. All done! This configuration process is successfully tested on both LUbuntu and Raspberry.
How to run Ubuntu Snappy Core in Raspberry Pi 2
Install NodeJS on the (Raspberry Pi) Raspberry Pi
Install Weston on Raspberry Pi
Linux OS for Raspberry Pi is available
Raspberry Pi (Raspberry Pi) trial note
Introduction to Raspberry Pi (Raspberry Pi) installation, IP configuration, and software source
This article permanently updates the link address: