配置桥接 eth0 和 wlan0
eth0 只能与 AP
模式的 wlan0 进行桥接,或者是WDS
模式下的AP/STA
wlan0 桥接;
换言之,eth0 无法与 不开启WDS
功能的STA
模式的 wlan0 桥接。
这里完成的是:
- 将 eth0 和 wlan0 桥接
- 设置固定 IP 地址以供管理
- 由 wlan0 提供无线接入服务
- 由 eth0 的网关提供 DHCP 服务。
启用桥接接口 br0
$ sudo vi /etc/network/interfaces
auto lo
iface lo inet loopback
auto br0
iface br0 inet manual
bridge_ports eth0 wlan0
$
$ brctl show
bridge name bridge id STP enabled interfaces
br0 8000.b827eb1b9cbd no eth0
wlan0
$ sudo vi /etc/dhcpcd.conf
...
interface br0
static ip_address=192.168.1.6/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
...
$
配置 Wi-Fi 成为 AP 模式
需要安装hostapd
,安装后会停用连接 Wi-Fi 用的wpa_supplicant
。
$ sudo apt-get install bridge-utils hostapd
$ sudo vi /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
channel=11
hw_mode=g
bridge=br0
ssid=QZRPi
wpa=3
wpa_passphrase=66668888
auth_algs=1
wpa_pairwise=TKIP
rsn_pairwise=CCMP
$
开启服务开机自动运行
$ sudo vi /etc/init.d/hostapd
...
DAEMON_CONF=/etc/hostapd/hostapd.conf
...
$ sudo /lib/systemd/systemd-sysv-install enable hostapd
状态记录
localhost:~ qigezhao$ ssh [email protected]
[email protected]'s password:
Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Jan 30 06:22:14 2018
pi@raspberrypi:~ $ ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.6 netmask 255.255.255.0 broadcast 192.168.1.255
ether b8:27:eb:1b:9c:bd txqueuelen 1000 (Ethernet)
RX packets 390 bytes 34505 (33.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 91 bytes 11138 (10.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 169.254.28.90 netmask 255.255.0.0 broadcast 169.254.255.255
ether b8:27:eb:4e:c9:e8 txqueuelen 1000 (Ethernet)
RX packets 1051 bytes 391729 (382.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 592 bytes 92810 (90.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 10 bytes 906 (906.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 906 (906.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 169.254.218.240 netmask 255.255.0.0 broadcast 169.254.255.255
ether b8:27:eb:1b:9c:bd txqueuelen 1000 (Ethernet)
RX packets 536 bytes 70955 (69.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 841 bytes 369163 (360.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
pi@raspberrypi:~ $
pi@raspberrypi:~ $ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto br0
iface br0 inet manual
bridge_ports eth0 wlan0
pi@raspberrypi:~ $
pi@raspberrypi:~ $ cat /etc/dhcpcd.conf
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.
# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel
# Inform the DHCP server of our hostname for DDNS.
hostname
# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid
# Persist interface configuration when dhcpcd exits.
persistent
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit
# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu
# A ServerID is required by RFC2131.
require dhcp_server_identifier
# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private
# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1
# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1
# fallback to static profile on eth0
#interface eth0
#fallback static_eth0
interface br0
static ip_address=192.168.1.6/24
static routers=192.168.1.1
pi@raspberrypi:~ $
pi@raspberrypi:~ $ cat /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
channel=11
hw_mode=g
bridge=br0
ssid=QZRPi
wpa=3
wpa_passphrase=13511053556
auth_algs=1
wpa_pairwise=TKIP
rsn_pairwise=CCMP
pi@raspberrypi:~ $
pi@raspberrypi:~ $ cat /etc/init.d/hostapd
#!/bin/sh
### BEGIN INIT INFO
# Provides: hostapd
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Should-Start: $network
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Advanced IEEE 802.11 management daemon
# Description: Userspace IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP
# Authenticator
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON_SBIN=/usr/sbin/hostapd
DAEMON_DEFS=/etc/default/hostapd
DAEMON_CONF=/etc/hostapd/hostapd.conf
NAME=hostapd
DESC="advanced IEEE 802.11 management"
PIDFILE=/run/hostapd.pid
[ -x "$DAEMON_SBIN" ] || exit 0
[ -s "$DAEMON_DEFS" ] && . /etc/default/hostapd
[ -n "$DAEMON_CONF" ] || exit 0
DAEMON_OPTS="-B -P $PIDFILE $DAEMON_OPTS $DAEMON_CONF"
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
start-stop-daemon --start --oknodo --quiet --exec "$DAEMON_SBIN" \
--pidfile "$PIDFILE" -- $DAEMON_OPTS >/dev/null
log_end_msg "$?"
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
start-stop-daemon --stop --oknodo --quiet --exec "$DAEMON_SBIN" \
--pidfile "$PIDFILE"
log_end_msg "$?"
;;
reload)
log_daemon_msg "Reloading $DESC" "$NAME"
start-stop-daemon --stop --signal HUP --exec "$DAEMON_SBIN" \
--pidfile "$PIDFILE"
log_end_msg "$?"
;;
restart|force-reload)
$0 stop
sleep 8
$0 start
;;
status)
status_of_proc "$DAEMON_SBIN" "$NAME"
exit $?
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload|reload|status}" >&2
exit 1
;;
esac
exit 0
pi@raspberrypi:~ $
pi@raspberrypi:~ $ sudo chkconfig --list
alsa-utils 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on
avahi-daemon 0:off 1:off 2:on 3:on 4:on 5:on 6:off
bluetooth 0:off 1:off 2:on 3:on 4:on 5:on 6:off
console-setup.sh 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cron 0:off 1:off 2:on 3:on 4:on 5:on 6:off
dbus 0:off 1:off 2:on 3:on 4:on 5:on 6:off
dhcpcd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
dphys-swapfile 0:off 1:off 2:on 3:on 4:on 5:on 6:off
fake-hwclock 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on
hostapd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
hwclock.sh 0:off 1:off 2:off 3:off 4:off 5:off 6:off
keyboard-setup.sh 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on
kmod 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on
lightdm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
lighttpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
networking 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on
nfs-common 0:off 1:off 2:off 3:off 4:off 5:off 6:off
paxctld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
plymouth 0:off 1:off 2:on 3:on 4:on 5:on 6:off
plymouth-log 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on
procps 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on
raspi-config 0:off 1:off 2:on 3:on 4:on 5:on 6:off S:on
rpcbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off
rsync 0:off 1:off 2:on 3:on 4:on 5:on 6:off
rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ssh 0:off 1:off 2:on 3:on 4:on 5:on 6:off
sudo 0:off 1:off 2:off 3:off 4:off 5:off 6:off
triggerhappy 0:off 1:off 2:on 3:on 4:on 5:on 6:off
udev 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on
x11-common 0:off 1:off 2:off 3:off 4:off 5:off 6:off S:on
pi@raspberrypi:~ $