简体   繁体   English

RPI通过以太网和网桥wifi并行访问网络

[英]RPI access network over ethernet and bridge wifi parallel

im currently try to use an pi as monitoring system which requires a connection to the local ethernet. 我目前正在尝试使用pi作为监视系统,该系统需要连接到本地以太网。 Now i also want to use the same pi as wifi ap. 现在我也想使用与wifi ap相同的pi。 But all configuration examples i've found for pi bridging ethernet and wifi so the pi itself cannot access the ethernet anymore. 但是我发现了pi桥接以太网和wifi的所有配置示例,因此pi本身再也无法访问以太网了。

Currently the configuration looks like this 当前配置看起来像这样

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wireless-power off

If i bridge the networks (and rpi works as intended as a wifi ap) the configuration looks like this 如果我桥接网络(并且rpi可以用作wifi ap),则配置如下所示

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wireless-power off

auto br0
iface br0 inet static
address 192.168.1.11
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
bridge-ports eth0 wlan0
bridge-waitport 5
bridge-stp off
bridge-fd 0

So the question is how to combine both configurations so that the pi has also access to the same (bridged) network? 那么问题是如何结合这两种配置,以便pi也可以访问同一(桥接)网络?

For topology something like this, the configuration is this . 对于类似这样的拓扑,配置是this

             ________________________________________ 
            |                  RPi                   |
Internet ---  WLAN(WiFi)          (Ethernet Ports)LAN ----- Devices
            |________________________________________|

Based on Milinds comment i reversed a solution from the post: 根据Milinds的评论,我从帖子中撤消了一个解决方案:

First, install the following packages: 首先,安装以下软件包:

apt-get update && apt-get -y install hostapd hostap-utils iw bridge-utils dnsmasq

add to /boot/cmdline.txt : 添加到/boot/cmdline.txt

[...] net.ifnames=0 [...]

replace /etc/network/interfaces : 替换/etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
wireless-power off
address 192.168.2.1
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255

create /etc/hostapd/hostapd.conf : 创建/etc/hostapd/hostapd.conf

ctrl_interface=/var/run/hostapd
macaddr_acl=0 auth_algs=1
driver=nl80211
interface=wlan0
hw_mode=g
ieee80211n=1
channel=1
ssid=REPLACE_WITH_YOUR_SSID
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=1
wpa=3
wpa_passphrase=REPLACE_WITH_YOUR_PASSPHRASE
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

replace /etc/dnsmasq.conf : 替换/etc/dnsmasq.conf

interface=wlan0 
listen-address=192.168.2.1 
bind-interfaces
server=8.8.8.8 
domain-needed 
bogus-priv
dhcp-range=192.168.2.2,192.168.2.100,12h

uncomment in /etc/sysctl.conf : /etc/sysctl.conf取消注释:

[...]
net.ipv4.ip_forward=1
[...]

Run now the following commands for iptable routing: 现在运行以下命令进行iptable路由:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE  
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT  
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Enable ip table routing on startup 在启动时启用IP表路由

add to /etc/rc.local before exit 0 : exit 0之前添加到/etc/rc.local

[...]
iptables-restore < /etc/iptables.ipv4.nat
[...]

Finally reboot and the pi should works as intended as wifi ap sharing internet from ethernet port. 最终重新启动,并且pi应该像从以太网端口共享wifi ap一样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM