带有 Web 身份验证的 Ubuntu Wi-fi 热点

带有 Web 身份验证的 Ubuntu Wi-fi 热点

我正在寻找一种解决方案,供我的公司为客人或访客使用,即像酒店那样的 Wi-Fi 热点系统。我将使用用户名和密码共享 Wi-Fi 连接。当用户连接到 Wi-Fi 时,系统将重定向到基于 Web 的登录页面以连接网站。

我在 Google 和这里​​搜索过,但说实话,作为一个 Linux 新手,看了这么多文章后,我的大脑已经爆炸了 :) 大多数人推荐一个叫 ZoneCD 的 Live CD,但我在互联网上找不到(他们提供的页面是关于屋顶修理的——http://www.publicip.net/features.php-- 文章在这里http://www.linuxplanet.com/linuxplanet/reports/7087/2)。

另外,我发现一些其他文章说你可以使用开放半径、开放热点附加组件,但老实说,我无法在我的 ubuntu 上安装。

我真的很困惑,决定在这里问一下,我认为在 ubuntu bot 上可以做到这一点,我们该怎么做?以前有人这样做过吗?你能分享有关我们如何做到这一点的信息或文章吗?

答案1

第一部分

我遇到了一个 Ubuntu 热点应用程序,它允许您通过 Ubuntu 提供 wifi,所以我希望这将有助于您寻找的那个方面。

文章来源在这里http://www.webupd8.org/2013/06/how-to-set-up-wireless-hotspot-access.html

要安装 ppa,请执行以下命令

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install ap-hotspot

现在,在 14.04 版本中,hostapd 无法正常工作,因此以下命令将降级 hostapd 并使用 apt 来保存软件包,从而防止自动升级。

对于 64 位

cd /tmp
wget http://archive.ubuntu.com/ubuntu/pool/universe/w/wpa/hostapd_1.0-3ubuntu2.1_amd64.deb
sudo dpkg -i hostapd*.deb
sudo apt-mark hold hostapd

或者,对于 32 位

cd /tmp
wget http://archive.ubuntu.com/ubuntu/pool/universe/w/wpa/hostapd_1.0-3ubuntu2.1_i386.deb
sudo dpkg -i hostapd*.deb
sudo apt-mark hold hostapd

启动并配置...

sudo ap-hotspot start

安装后重新配置...

sudo ap-hotspot configure

要停止热点...

sudo ap-hotspot stop

并重新启动...

sudo ap-hotspot restart

有关命令列表...

ap-hotspot

第二部分基于 Web 的身份验证

改编自http://pepperspot.sourceforge.net/index.php?n=Doc.UserDocumentation

我已经更新了一些命令以符合使用 sudo 的最新做法。

第一的安装构建模块

sudo apt-get install build-essential linux-headers-generic automake subversion libtool

要下载并构建 pepperspot 源包;执行以下命令:

svn co svn://svn.code.sf.net/p/pepperspot/code/trunk pepperspot
cd pepperspot
autoreconf -f -i
./configure
make
sudo make install
sudo modprobe ipv6
sudo apt-get install radvd iptables libc6-dev quagga apache2 libapache2-mod-php5 libssl-dev freeradius

1.) 激活 IPv6

首先,确保你的内核已激活 IPv6。如果 IPv6 已编译为模块,请输入:

sudo modprobe ipv6

1.1)无状态自动配置

这是/etc/radvd.conf配置文件:

interface ath0  
{
  AdvSendAdvert on;
  AdvIntervalOpt on;
  MinRtrAdvInterval 2;
  MaxRtrAdvInterval 6;
  prefix 2001:db8:1::/64
  {
    AdvOnLink on;
    AdvAutonomous on;
    AdvRouterAddr on;
    };

    RDNSS 2001:db8:2::1 
    {
        AdvRDNSSPreference 8;
    AdvRDNSSOpen off;
    AdvRDNSSLifetime 30;
    };
};

将接口、前缀和 RDNSS(DNS 服务器信息)行替换为您自己的值,然后使用以下命令启动 radvd:

sudo radvd -C /etc/radvd.conf

1.2)寻址和路由

强制门户必须将经过身份验证的用户的数据包路由到 Internet。因此系统必须启用 IPv6 转发。您可以使用以下命令将其打开:

echo "1" | sudo tee /proc/sys/net/ipv6/conf/all/forwarding

为了保持此配置持久,可以使用以下命令:

echo 'net.ipv6.conf.all.forwarding=1' | sudo tee -a /etc/sysctl.conf

IPv6 转发将禁用 IPv6 自动配置,因此可以使用路由守护程序静态或动态设置网络配置(分配地址和路由)。有关最后一种程序,请参阅第 2 节。

如果您要使用静态寻址和路由程序,假设 eth0 是连接到 Internet 的 IPv6 网络的接口,请键入以下命令并替换为您自己的值。

在有线接口上分配地址:

sudo ip -6 addr add 2001:db8:1::1234/64 dev eth0

添加默认路由配置(替换为您的路由地址值):

sudo route -A inet6 add default gw fe80::1:2:3:4 dev eth0

您可以将此配置持久插入网络配置/etc/网络/接口正如你在本例中看到的:

auto eth0
iface eth0 inet6 static
        address 2001:db8:1::1234
        netmask 64
                gateway fe80::1:2:3:4
        pre-up modprobe ipv6      # to be sure that ipv6 is enabled before we turn up the interface 

请注意,您不必在连接到接入点盒的接口(或无线接口,如果您使用的话)上配置地址。

1.3)IPv4

IPv4 配置与 IPv6 大致相同,只是您不需要为网络配置宣传客户端。 PepperSpot 集成了 DHCP 模块,用于将 IPv4 地址分配给远程客户端。 如果无线链路已经有 DHCP 服务器,或者客户端配置是静态设置的,您可以在 PepperSpot 配置中禁用此模块。 不过,您仍需要配置链接到 IPv4 网络的接口。

以同样的方式,使用以下命令启用IPv4转发:

echo "1" | sudo tee /proc/sys/net/ipv4/conf/all/forwarding
echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.conf

并配置接口地址和路由(替换为您的参数):

sudo ip addr add 192.168.0.1/24 dev eth1
sudo route add default gw 192.168.0.254 dev eth1

您可以使用以下阻止命令来更新 /etc/network/interfaces 文件:

echo 'auto eth1
iface eth1 inet static
    address 192.168.0.1
    netmask 24
    gateway 192.168.0.254' | sudo tee /etc/network/interfaces

1.4)Netfilter 支持

PepperSpot 会使用一些 Netfilter 规则来处理客户端和互联网之间的通信。因此系统必须支持 Netfilter。如果不支持,请修改内核配置:

对于IPv4,需要启用Nat、Mangle和跟踪支持;

对于IPv6,只需要基本支持。

1.5)注意事项

所有服务(Radius、Web 服务器、PepperSpot 等)均可安装在提供 Wi-Fi 接入(主模式)的系统上。它可以是嵌入式设备,也可以是从头配置为接入点的系统。

对于这种情况,您的 Wi-Fi 卡必须支持主模式。

例如,如果您使用带有 madwifi 驱动程序的无线接口,这里有一个示例初始化脚本:

#!/bin/bash

# Setting ath0 in Master mode
# Replace PepperSpot by your SSID

wlanconfig ath0 destroy
wlanconfig ath0 create wlandev wifi0 wlanmode ap
iwconfig ath0 essid "PepperSpot"    
ifconfig ath0 up

2)配置Quagga路由套件

Quagga 路由套件实现了一些 IPv4 和 IPv6 路由协议。本节介绍如何安装 RIPng 协议以允许 IPv6 路由。我们假设您有一个委托的 IPv6 前缀,并且您需要为此前缀路由通信。如果不是这种情况,您可以跳过本节。

quagga 的配置是通过在/etc/quagga目录,但 quagga 套件为每种协议集成了一些类似 cisco 的接口,以允许动态配置和查看一些路由信息(如路由表)。

您可以将前面描述的 IPv6 和 IPv4 网络配置放入路由协议配置中。对于所需的每个协议,请在/etc/quagga/守护进程

我们需要启用 zebra,因为它是使用其他协议和配置接口所需的主要路由模块。在我们的例子中,我们只需要添加 RIPng:

# This file tells the quagga package which daemons to start.
#
# Entries are in the format: <daemon>=(yes|no|priority)
#   0, "no"  = disabled
#   1, "yes" = highest priority
#   2 .. 10  = lower priorities
# Read /usr/share/doc/quagga/README.Debian for details.
#
# Sample configurations for these daemons can be found in
# /usr/share/doc/quagga/examples/.
#
# ATTENTION:
#
# When activation a daemon at the first time, a config file, even if it is
# empty, has to be present *and* be owned by the user and group "quagga", else
# the daemon will not be started by /etc/init.d/quagga. The permissions should
# be u=rw,g=r,o=.
# When using "vtysh" such a config file is also needed. It should be owned by
# group "quaggavty" and set to ug=rw,o= though. Check /etc/pam.d/quagga, too.
#
zebra=yes
bgpd=no
ospfd=no
ospf6d=no
ripd=no
ripngd=yes
isisd=no

现在我们必须为启动的每个守护进程创建一个配置文件。

/etc/quagga/zebra.conf文件:

!
! Zebra configuration saved from vty
!   2008/04/10 12:18:58
!
hostname MobSpot
password ***********
enable password *************
!
interface ath0
 ipv6 nd suppress-ra
!
interface eth0
 ipv6 address 2001:db8:1::1234/64
 ipv6 nd suppress-ra
!
interface eth1
 ip address 192.168.0.1/24
 ipv6 nd suppress-ra
!
interface eth2
 ipv6 nd suppress-ra
!
interface eth3
 ipv6 nd suppress-ra
!
interface lo
!
interface tun0
 ipv6 nd suppress-ra
!
interface wifi0
 ipv6 nd suppress-ra
!
ipv6 forwarding
!
!
line vty
!

在这个文件中,我们设置了连接到服务网络的每个接口(eth0 和 eth1)的静态配置。

/etc/quagga/ripngd.conf文件:

! -*- rip -*-
!
! RIPngd sample configuration file
!
! $Id: ripngd.conf.sample,v 1.1.1.1 2002/12/13 20:15:30 paul Exp $
!
hostname MobSpot
password ***********
enable password ************
!
! debug ripng events
! debug ripng packet
!
!
router ripng
network eth0
redistribute connected
redistribute static
route 2001:db8:1::/64
!
line vty
!

在这个文件中,我们配置 RIPng 协议,表明我们能够在 eth0 接口上为 2001:db8:1::/64 前缀路由数据包。

对于这两个文件,第一部分将定义配置接口 (vty) 的密码。启用密码行表示需要密码才能获得重新配置守护进程的权限。不要忘记启用此配置接口的 vty 行。

对于斑马配置类型:

sudo telnet 127.0.0.1 zebra

对于 RIPng 配置:

sudo telnet 127.0.0.1 ripngd

注意:经过身份验证(将密码行写入配置文件)后,您将获得一个命令行来配置守护进程。输入“?”查看可用的命令。

最后,重新启动 quagga 守护进程:

sudo /etc/init.d/quagga restart 

注意:如果需要配置 IPv4 路由,请将此配置适应 RIP 守护进程。

3)Apache 配置

PepperSpot 需要与安装在同一台机器上的 Web 服务器通信,以允许客户端进行身份验证。Web 服务器必须配置为 SSL、PHP 和 CGI​​。

以下是 Apache2 Web 服务器的配置:

生成 SSL 证书来保证 Web 服务器的身份:

sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/key.pem

第二步,加载Apache2-SSL模块:

sudo a2enmod ssl

Web 服务器需要虚拟主机才能访问。创建文件/etc/apache2/sites-available/pepperspot包含以下内容(根据您所需的配置进行调整):

NameVirtualHost *:443

<VirtualHost *:443>
        ServerAdmin webmaster@pepperspot
        SSLEngine on
        SSLCertificateFile /etc/apache2/key.pem

        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
                    # This directive allows us to have apache2s default start page
                    # in /apache2-default/, but still have / go to the right place
                RedirectMatch ^/$ /apache2-default/
        </Directory>

            # CGI - We need cgi support to communicate with PepperSpot
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>'

如果您想修改虚拟主机的名称,请不要忘记 Apache 需要同时监听 IPv6 和 IPv4 地址以适应双栈模式,并且需要监听 IPv4 或 IPv6 接口以适应您选择的单栈模式。

在 /etc/apache2/ports.conf 中添加以下块代码以允许 HTTPS 监听(如果尚不存在):

echo '<IfModule mod_ssl.c>
    Listen 443
</IfModule>' | sudo tee -a /etc/apache2/ports.conf

最后,加载网站:

sudo a2ensite pepperspot
sudo /etc/init.d/apache2 reload

4)FreeRadius 配置

PepperSpot 能够通过 IPv4 或 IPv6 协议与 Radius 服务器通信,具体取决于 /etc/pepper.conf 中的 radius 服务器地址配置。以下是 FreeRadius 服务器的配置。要获得 IPv6 支持,您需要 FreeRadius 版本 >= 2.0。

FreeRadius 配置比较复杂,下面仅介绍在 FreeRadius 上启用 IPv6 支持的基本配置以及添加一些用户帐户的简便方法。如果您需要更好的配置,请参阅 FreeRadius 文档。

4.1)IPv6配置

修改 /etc/freeradius/radiusd.conf 文件以添加以下部分:

# For authentication 
listen {
        type = auth
#       ipaddr = *
        ipv6addr = ::1
        port = 0
#       interface = eth0
#       clients = per_socket_clients
}

# For accounting                         
listen {
        type = acct
#       ipaddr = *
        ipv6addr = ::1
        port = 0
#       interface = eth0
#       clients = per_socket_clients
}

使用此配置,将字段 ipv6addr 中的 ::1 替换为 FreeRadius 必须侦听的地址。port = 0 表示使用默认 Radius 端口。如果为 ipv6addr 指定 *,FreeRadius 将侦听系统上配置的每个 IPv6 地址。

现在,您需要配置一个 FreeRadius 客户端(称为 NAS),通常 NAS 是强制门户。

打开 /etc/freeradius/clients.conf 文件并添加以下行:

client ::1 {      # here ::1 is the name of the client. Replace with your own value
    ipv6addr    = ::1
    secret  = testing123
    shortname   = localhost
    nastype     = other
}

如果 PepperSpot 和 FreeRadius 在不同的盒子上,则必须将 ipv6addr 替换为 PepperSpot 和 FreeRadius 通信的地址。同时修改短名称。

要重新启动 FreeRadius:

sudo /etc/init.d/freeradius restart

4.2)IPv4 配置

对于 FreeRadius 的 IPv4 配置,将 ipv6addr 字段替换为 ipaddr,并填充所需的 IPv4 地址。

4.3) 账户

最后,我们需要在 /etc/freeradius/users 中创建账户:

toto 明文密码 := “totoilsaitpas”

ping6 明文密码 := "pong6"

重新启动 FreeRadius:

sudo /etc/init.d/freeradius restart

5)PepperSpot配置

复制一些配置文件:

sudo cp doc/pepper.conf /etc/
sudo cp doc/hotspotlogin.cgi /usr/lib/cgi-bin/
sudo chmod +x /usr/lib/cgi-bin/hotspotlogin.cgi

对于 IPv4:

sudo cp doc/pepper.iptables /etc/
sudo chmod +x /etc/pepper.iptables

对于 IPv6:

sudo cp doc/pepper.ip6tables /etc/
sudo chmod +x /etc/pepper.ip6tables

5.2)iptables

修改 /etc/pepper.iptables 和/或 /etc/pepper.ip6tables 脚本并根据您的配置调整 $INTIF(连接到接入点或无线接口的接口)、$EXTIF4(连接到 IPv4 LAN 的接口)和 $EXTIF6(连接到 IPv6 LAN 的接口)值。请注意,对于双栈配置,$EXTIF4 和 $EXTIF6 可以具有相同的值。

您可以按照 pepperspot 用户文档中的说明完成其余设置。http://pepperspot.sourceforge.net/index.php?n=Doc.UserDocumentation只剩下一个配置部分。

相关内容