
編輯:我發現這是重複的為什麼只有當網路介面卡處於混雜模式時才會有 ARP 回應?。
我使用帶有 Rasbian Stretch 的 Raspberry Pi 3B+,並按照 Debian 的教學使用代理 arp 設定它:使用代理 ARP 橋接網路連接將 eth0“橋接”到 wlan0。據此,很容易設定代理 arp:
rpi3 ~# echo 1 > /proc/sys/net/ipv4/conf/all/proxy_arp
rpi3 ~# echo 1 > /proc/sys/net/ipv4/ip_forward
rpi3 ~# ip route add 192.168.10.60/32 dev eth0
192.168.10.60
是 eth0 上的客戶端,應該「橋接」到 wlan0。
但這不起作用。我必須在 wlan0 上啟用混雜模式才能使其正常工作,但找不到任何提示來執行此操作。
rpi3 ~# ip link set wlan0 promisc on
是否需要混雜模式Stretch
?如果不是,我該如何避免呢?
更新:
檢查了一下rp_filter
設定為0
hostapd
。wlan0
處於客戶端模式並由 管理wpa_supplicant
。
答案1
顯然,不可能在客戶端模式下的無線和乙太網路之間橋接乙太網路幀。例如,它不會工作。
另外,請注意不要將其他來源的訊框作為客戶端注入 AP 基礎架構中。
大多數存取點 (AP) 將拒絕來源位址未通過 AP 進行驗證的訊框。
答案2
這似乎只是 Raspberry Pi 的 wifi 上的問題。還有一個重複的問題為什麼只有當網路介面卡處於混雜模式時才會有 ARP 回應?使用樹莓派。在任何教學課程的其他地方都找不到啟用代理 arp 混雜模式的註解。我已經在我的筆記型電腦上驗證了它,代理 arp 可以在沒有混雜模式的情況下工作。
我認為這個問題只能由 RASPBERRY PI FOUNDATION 和/或其閉源驅動程式製造商解決。在那之前我們必須忍受它。
答案3
使用 ARP 代理程式和 promisc 模式進行橋接
可以「橋接」從 WiFi 到 LAN 的連接(例如,在具有 microUSB-LAN 適配器的 Raspberry Pi Zero W 上),所有裝置都位於同一子網路(IP範圍)使用ARP代理和混雜模式。
•方案:
[路由器] <---WiFi---> [RasPi wlan0 <---bridge---> eth0] <---LAN 電纜---> [有線設備,例如電腦]
•提示:提供的解決方案是基於這些優秀的資源
來源#1作者:帕斯卡·蓋澤
來源#2透過威爾·哈利
•這些範例中使用的硬體/作業系統:
帶有 microUSB 至 LAN 適配器的 Raspberry Pi Zero W
Raspbian Stretch Lite (2019-04-08) + 更新
解決方案 #1 - 透過介面進行 ARP 代理(手動設定)
注意:這取決於您的 WiFi 路由器是否支援「IP Layer 3 解決方案」(網路層)
1)假設 Raspberry Pi 與路由器的 WiFi 連線已設定並連接
2)安裝包
$ sudo apt-get install parprouted dhcp-helper
3)編輯並新增以下行:
假設
- 無線區域網路0是樹莓派內建WiFi卡的ID
- 乙太網路0是有線乙太網路卡(microUSB-LAN 轉接器)的 ID
$ sudo nano /etc/network/interfaces
# Clone the dhcp-allocated IP to eth0 so dhcp-helper will relay for the correct subnet
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
pre-up /sbin/ip link set wlan0 promisc on
post-down /sbin/ip link set wlan0 promisc off
post-up /usr/sbin/parprouted eth0 wlan0
post-down /usr/bin/killall /usr/sbin/parprouted
post-up /etc/init.d/dhcp-helper restart
pre-up /sbin/ifup eth0
post-up /sbin/ip addr add $(/sbin/ip -4 -br addr show wlan0 | /bin/grep -Po "\\d+\\.\\d+\\.\\d+\\.\\d+")/32 dev eth0
pre-down /sbin/ip addr del $(/sbin/ip -4 -br addr show wlan0 | /bin/grep -Po "\\d+\\.\\d+\\.\\d+\\.\\d+")/32 dev eth0
post-down /sbin/ifdown eth0
# Set ethernet interface to "manual" mode
auto eth0
allow-hotplug eth0
iface eth0 inet manual
4)啟用封包轉送:
$ sudo nano /etc/sysctl.conf
# Find and uncomment this line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1
# to -->
net.ipv4.ip_forward=1
5)設定 DHCP 中繼
DHCP 幫助程式將擷取請求並將它們轉送到「真實」DHCP 伺服器:
$ sudo nano /etc/default/dhcp-helper
# Change eth0 by the name of your wireless interface (e.g. wlan0)
#DHCPHELPER_OPTS="-b eth0"
# to -->
DHCPHELPER_OPTS="-b wlan0"
6)配置 AVAHI
啟用「反射器模式」將允許用戶端瀏覽連接到網橋的所有服務:
$ sudo nano /etc/avahi/avahi-daemon.conf
# Find and change the following line
#enable-reflector=no
# to -->
enable-reflector=yes
7)重啟 RasPi
重啟後,透過 eth0 / LAN 連接的裝置應該可以存取 WiFi 路由器的相同網路。
注意:工作解決方案取決於您的 WiFi 路由器是否支援「IP 第 3 層解決方案」(網路層)
$ sudo reboot
解決方案 #2 - 透過 SERVICES 的 ARP 代理程式(自動腳本解決方案)
注意:這取決於您的 WiFi 路由器是否支援「IP Layer 3 解決方案」(網路層)
1)使用以下內容建立 bash 腳本:
$ sudo nano bridge.sh
#!/usr/bin/env bash
set -e
[ $EUID -ne 0 ] && echo "run as root" >&2 && exit 1
##########################################################
# You should not need to update anything below this line #
##########################################################
# Credits to Will Haley
# Mainly based on source: https://willhaley.com/blog/raspberry-pi-wifi-ethernet-bridge/#option-1---same-subnet
# Edited on line #52 by Tomtom: path to systemd for parprouted.service
# parprouted - Proxy ARP IP bridging daemon
# dhcp-helper - DHCP/BOOTP relay agent
apt update && apt install -y parprouted dhcp-helper
systemctl stop dhcp-helper
systemctl enable dhcp-helper
# Enable ipv4 forwarding.
sed -i'' s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/ /etc/sysctl.conf
# Service configuration for standard WiFi connection. Connectivity will
# be lost if the username and password are incorrect.
systemctl restart wpa_supplicant.service
# Enable IP forwarding for wlan0 if it's not already enabled.
grep '^option ip-forwarding 1$' /etc/dhcpcd.conf || printf "option ip-forwarding 1\n" >> /etc/dhcpcd.conf
# Disable dhcpcd control of eth0.
grep '^denyinterfaces eth0$' /etc/dhcpcd.conf || printf "denyinterfaces eth0\n" >> /etc/dhcpcd.conf
# Configure dhcp-helper.
cat > /etc/default/dhcp-helper <<EOF
DHCPHELPER_OPTS="-b wlan0"
EOF
# Enable avahi reflector if it's not already enabled.
sed -i'' 's/#enable-reflector=no/enable-reflector=yes/' /etc/avahi/avahi-daemon.conf
grep '^enable-reflector=yes$' /etc/avahi/avahi-daemon.conf || {
printf "something went wrong...\n\n"
printf "Manually set 'enable-reflector=yes in /etc/avahi/avahi-daemon.conf'\n"
}
# I have to admit, I do not understand ARP and IP forwarding enough to explain
# exactly what is happening here. I am building off the work of others. In short
# this is a service to forward traffic from WiFi to Ethernet.
#cat <<'EOF' >/usr/lib/systemd/system/parprouted.service
cat <<'EOF' >/etc/systemd/system/parprouted.service
[Unit]
Description=proxy arp routing service
Documentation=https://raspberrypi.stackexchange.com/q/88954/79866
Requires=sys-subsystem-net-devices-wlan0.device dhcpcd.service
After=sys-subsystem-net-devices-wlan0.device dhcpcd.service
[Service]
Type=forking
# Restart until wlan0 gained carrier
Restart=on-failure
RestartSec=5
TimeoutStartSec=30
# clone the dhcp-allocated IP to eth0 so dhcp-helper will relay for the correct subnet
ExecStartPre=/bin/bash -c '/sbin/ip addr add $(/sbin/ip -4 -br addr show wlan0 | /bin/grep -Po "\\d+\\.\\d+\\.\\d+\\.\\d+")/32 dev eth0'
ExecStartPre=/sbin/ip link set dev eth0 up
ExecStartPre=/sbin/ip link set wlan0 promisc on
ExecStart=-/usr/sbin/parprouted eth0 wlan0
ExecStopPost=/sbin/ip link set wlan0 promisc off
ExecStopPost=/sbin/ip link set dev eth0 down
ExecStopPost=/bin/bash -c '/sbin/ip addr del $(/sbin/ip -4 -br addr show wlan0 | /bin/grep -Po "\\d+\\.\\d+\\.\\d+\\.\\d+")/32 dev eth0'
[Install]
WantedBy=wpa_supplicant.service
EOF
systemctl daemon-reload
systemctl enable parprouted
systemctl start parprouted dhcp-helper
2)執行 bash 腳本(檢查輸出是否有錯誤):
$ sudo bash bridge.sh
3)重新啟動 RasPi
透過 eth0 / LAN 連接的裝置重新啟動後應該可以存取 WiFi 路由器的相同網路。注意:這取決於您的 WiFi 路由器是否支援“IP Layer 3 解決方案”
$ sudo reboot
一般注意事項:
- ARP代理需要支持透過 WiFi 路由器實現「IP 第 3 層/網路層」功能(我猜您可以嘗試找出答案)。
- 透過 WDS 的首選解決方案(此處未討論該主題),用於在同一子網路上提供橋接解決方案,需要 WiFi 晶片支援 WDS和WiFi路由器。您可以檢查 Raspberry Pi 的 WiFi 晶片是否支援 WDS
$ iw list
在部分支援的介面模式
Wiphy phy0
...
Supported interface modes:
* IBSS
* managed
* AP
* AP/VLAN
* WDS
* monitor
* mesh point
...
如果無線資料傳輸系統是沒有明確列出這裡,那WDS就是不支援透過 WiFi 晶片(Raspberry Pi Zero W 不支援 WDS)。