Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use hostapd and dhcpd to turn on wireless hotspots on Ubuntu

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to use hostapd and dhcpd to open wireless hotspots on Ubuntu". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Introduction to Hostapd:

To put it simply, hostapd can switch the wireless network card to master mode, simulating the function of AP (usually thought of as a router), which is what we call soft AP (Soft AP).

The function of Hostapd is to act as the authentication server of AP, which is responsible for controlling and managing the access and authentication of stations (usually PC with wireless network card).

Through Hostapd, the wireless network card can be switched to AP/Master mode, and an open (unencrypted) WEP,WPA or WPA2 wireless network can be established by modifying the configuration file. And by modifying the configuration file, you can set various parameters of the wireless network card, including frequency, signal, beacon packet interval, whether to send beacon packets, if responding to probe requests, and so on. You can also set mac address filtering conditions and so on. You can refer to its configuration file description for details.

Here are some of the reasons and translations taken from the official website. Please forgive me for the poor translation.

Hostapd is an IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator.

Hostapd is the authenticator of IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP/RADIUS

Hostapd is a user space daemon for access point and authentication servers. It implements IEEE 802.11 access point management, IEEE 802.1X/WPA/WPA2/EAP Authenticators, RADIUS client, EAP server, and RADIUS authentication server. The current version supports Linux (Host AP, madwifi, mac80211-based drivers) and FreeBSD (net80211).

Hostapd is an access point and daemon running in user space for authentication servers. It implements the IEEE 802.11 access with you (Access Point) management function, is the IEEE 802.1X/WPA/WPA2/EAP authenticator, is the RADIUS client, EAP server, and RADIUS authentication server. The current version of hostapd supports Host AP,madwifi on linux and drivers based on the mac80211 stack, as well as drivers for the net80211 stack on FreeBSD.

Hostapd is designed to be a "daemon" program that runs in the background and acts as the backend component controlling authentication. Hostapd supports separate frontend programs and an example text-based frontend, hostapd_cli, is included with hostapd.

Hostapd is a background daemon that acts as a background component to control and manage authentication functions. Hostapd supports multiple foreground programs. Hostapd_cli is a command line foreground program with hostapd.

Let's take a look at how to use hostapd and dhcpd to establish wireless hotspots on Ubuntu systems:

Execute iwlist if there is an AP under the Supported interface modes, it means that the network card supports AP mode and can create a wireless hotspot.

For example, my wireless network card comes with a driver ath9k in the Qualcomm Atheros AR9485 Wireless Network Adapter,Linux kernel, which supports the creation of AP wireless hotspots.

1. Install hostapd and dhcpd

The code is as follows:

Sudo apt-get install hostapd isc-dhcp-server

You do not need to start these two services to boot. It is recommended that you turn them off:

The code is as follows:

Sudo update-rc.d-f hostapd remove

Comment out the start on line of the following two files:

The code is as follows:

Sudo nano / etc/init/isc-dhcp-server.conf

Sudo nano / etc/init/isc-dhcp-server6.conf

two。 Configure hostapd and dhcpd

The code is as follows:

Sudo nano / etc/hostapd/hostapd.conf

Pay attention to setting the wireless hotspot name ssid and authentication password wpa_passphrase.

The code is as follows:

Interface=wlan0

Driver=nl80211

Ssid=YOUR_AP_NAME

Hw_mode=g

Channel=10

Macaddr_acl=0

Auth_algs=3

Wpa=2

Wpa_passphrase=YOUR_AP_PASSWORD

Wpa_key_mgmt=WPA-PSK

Wpa_pairwise=TKIP CCMP

Rsn_pairwise=TKIP CCMP

The code is as follows:

Sudo nano / etc/dhcp/dhcpd.conf

Add the following at the end:

The code is as follows:

Subnet 192.168.0.0 netmask 255.255.255.0

{

Range 192.168.0.2 192.168.0.10

Option routers 192.168.0.1

Option domain-name-servers 192.168.0.1180.76.76.76,8.8.8.8

}

Among them, 180.76.76.76 is Baidu public DNS server, 8.8.8.8 is Google DNS server.

Create a hostapd directory under your home directory, and create a new startup and shutdown script, as I wrote (change the eechen to your user name):

The code is as follows:

Nano / home/eechen/hostapd/ap-start.sh

#! / bin/bash

# enable kernel IP forwarding

Bash-c "echo 1 > / proc/sys/net/ipv4/ip_forward"

# enable firewall NAT forwarding (if the local computer uses eth0 to access the Internet, change ppp0 to eth0)

Iptables-t nat-A POSTROUTING-o ppp0-j MASQUERADE

# turn off the control of wireless network card by NetworkManager

Nmcli nm wifi off

# set up and start the wireless network card

Ifconfig wlan0 192.168.0.1 netmask 255.255.255.0

# unlock the wireless device, you can use rfkill list to view the unlocking result.

Rfkill unblock wlan

# Sleep for 6 seconds, waiting for rfkill to unlock.

Sleep 6s

# start dhcpd and hostapd. If hostapd cannot be started, check the log hostapd.log and view the two processes ps-ef | egrep "dhcpd | hostapd"

Nohup hostapd/ etc/hostapd/hostapd.conf > / home/eechen/hostapd/hostapd.log 2 > & 1 &

Dhcpd wlan0-pf / var/run/dhcpd.pid

Ps-ef | head-N1 & & ps-ef | egrep "dhcpd | hostapd"

Nano / home/eechen/hostapd/ap-stop.sh

#! / bin/bash

Killall hostapd dhcpd

Bash-c "echo 0 > / proc/sys/net/ipv4/ip_forward"

Ifconfig wlan0 down

3. Start hostapd and dhcpd

Create two new initiators (shortcuts) on the desktop and fill them with:

The code is as follows:

Gksu / home/eechen/hostapd/ap-start.sh

Gksu / home/eechen/hostapd/ap-stop.sh

Because the script needs to be executed as root, it needs to be run with gksu.

Note: if you enable ufw firewall, ufw forbids forwarding by default, which will cause firewall NAT forwarding to fail. In this case, allow forwarding should be set:

The code is as follows:

Sudo nano / etc/default/ufw sets DEFAULT_FORWARD_POLICY to ACCEPT

Then restart ufw:

The code is as follows:

Sudo service ufw restart

Then run the initiator to start and turn off the AP wireless hotspot.

4. Use wireshark to monitor communications through wlan0

Install wireshark (where eechen is changed to your user name):

The code is as follows:

Sudo apt-get install wireshark

Sudo chgrp eechen / usr/bin/dumpcap

Sudo chmod 750 / usr/bin/dumpcap

Sudo setcap cap_net_raw,cap_net_admin+eip / usr/bin/dumpcap

Alt+F2 runs wireshark. Select network interface wlan0,Filter and enter http.cookie contains mail.qq.com.

Then log in to the web page QQ Mail on the mobile end, and view and obtain the Cookie logged in by QQ Mail on WireShark, as shown in the figure:

Right-click the Cookie item to copy the Value, and then use Firefox to visit the site https://w.mail.qq.com/ Magazine Altinium C to activate Original Cookie Injector (GreaseMonkey), pop up the input box Wireshark Cookie Dump, paste the Value of the Cookie item into it, and then click OK to determine and refresh the page to log in to QQ Mail. Or you can use the Firefox extension Tamper Data to change the cookie value at the time of submission.

Attached:

View the clients connected to the wlan0 network:

The code is as follows:

Sudo arp

Returns the IP address and MAC hardware address and wireless interface name.

The code is as follows:

Iw dev wlan0 station dump

Can display sending and receiving packets and the number of bytes and so on.

Check the network interface speed:

The code is as follows:

Sar-n DEV 1

That's all for "how to use hostapd and dhcpd to turn on wireless hotspots on Ubuntu". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report