强制门户的 DNSMASQ 配置

555*_*597 7 captive-portal dnsmasq hostapd

我正在尝试创建一个强制门户 wifi 热点。

设置目的:

  1. 决不允许通过 wlan0 连接到热点的用户通过 eth1 访问互联网。

  2. 为了让“登录 wifi 网络”出现在 android、iphone 和任何可以连接的设备上,我试图将请求路由到
    http://clients1.google.com/generate_204和其他操作系统的其他 url,我还没有弄清楚,到我的本地服务器并返回真实服务器将返回的内容。

我使用 dnsmasq 和 hostapd 来实现这一点。

问题:当我在 dnsmasq.conf 中使用 address=/#/127.24.2.1 时,来自内部脚本的互联网请求也会失败。我想我正在关注 dnsmasq 配置手册页,其中说明了如何使用 dnsmasq 仅过滤 wlan0 接口流量。

我应该怎么做。

机器有这些接口

    eth1      Link encap:Ethernet  HWaddr 00:1e:06:30:5b:03
          inet addr:192.168.0.107  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::21e:6ff:fe30:5b03/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:37047 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1752 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3351437 (3.1 MiB)  TX bytes:176100 (171.9 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:796 errors:0 dropped:0 overruns:0 frame:0
          TX packets:796 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:284838 (278.1 KiB)  TX bytes:284838 (278.1 KiB)

wlan0     Link encap:Ethernet  HWaddr 98:de:d0:1b:95:5a
          inet addr:172.24.1.1  Bcast:172.24.1.255  Mask:255.255.255.0
          inet6 addr: fe80::9ade:d0ff:fe1b:955a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:576 (576.0 B)
Run Code Online (Sandbox Code Playgroud)

DNSMASQ 看起来像这样

interface=wlan0      # Use interface wlan0
listen-address=172.24.1.1 # Explicitly specify the address to listen on
#bind-interfaces      # Bind to the interface to make sure we aren't sending things elsewher$
server=8.8.8.8       # Forward DNS requests to Google DNS
domain-needed        # Don't forward short names
bogus-priv           # Never forward addresses in the non-routed address spaces.
dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24$
address=/#/172.24.1.1
except-interface=eth1
Run Code Online (Sandbox Code Playgroud)

我使用 nodejs express 服务器并执行此操作

 app.get('/generate_204', function(req, res) {
        console.log('generate 204 hit');
        res.statusCode = 302;
        res.setHeader("Location", "/");
        res.end();
    });
Run Code Online (Sandbox Code Playgroud)

我使用hostapd创建了热点,配置是

    # This is the name of the WiFi interface we configured above
interface=wlan0

# Use the nl80211 driver with the brcmfmac driver
driver=nl80211

# This is the name of the network
ssid=Pi3-AP

# Use the 2.4GHz band
hw_mode=g

# Use channel 6
channel=6

# Enable 802.11n
ieee80211n=1

# Enable WMM
wmm_enabled=1

# Enable 40MHz channels with 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]

# Accept all MAC addresses
macaddr_acl=0

# Use WPA authentication
auth_algs=1

# Require clients to know the network name
ignore_broadcast_ssid=0

# Use WPA2
wpa=2

# Use a pre-shared key
wpa_key_mgmt=WPA-PSK

# The network passphrase
wpa_passphrase=raspberry

# Use AES, instead of TKIP
rsn_pairwise=CCMP
Run Code Online (Sandbox Code Playgroud)

我试图解释要求,我不确定我是否把解释部分做得很好。我在 serverfault 上针对同一问题提出了另一个问题,该问题被标记为偏离主题,阅读它会让您清楚地了解需求。https://serverfault.com/questions/823139/iptables-for-linux-captive-portal-wifi-hotspot

Sli*_*eer 4

当我使用 address=/#/127.24.2.1 时,来自内部脚本的互联网请求也会失败

看来您的内部脚本使用与 wifi 客户端相同的本地 dnsmasq 服务器来解析 DNS 名称。

检查您的/etc/resolv.conf配置,如果存在您的 dnsmasq 服务器地址(127.24.2.1127.0.0.1其他)- 将其删除。相反,请使用您的 ISP DNS 服务器、Google DNS,或您喜欢的任何其他服务器,它们不会将任何地址替换为127.24.2.1.

笔记。如果您系统使用resolvconf来生成/etc/resolv.conf(在resolv.conf中出现类似警告# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN),那么您需要编辑配置/etc/resolvconf/resolv.conf.d/,然后重新生成/etc/resolv.conf(重新启动网络或更好 - 重新启动整个系统)

另一种可能性:删除包resolvconf并编辑/etc/resolv.conf