我目前尝试使用pi作为监控系统,需要连接到本地以太网。现在我也想使用与wifi相同的pi。但是我发现pi桥接以太网和wifi的所有配置示例都让pi本身无法再访问以太网了。
目前配置如下所示
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
如果我桥接网络(并且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
所以问题是如何组合两种配置,以便pi也可以访问相同的(桥接)网络?
答案 0 :(得分:0)
对于类似这样的拓扑,配置为this。
________________________________________
| RPi |
Internet --- WLAN(WiFi) (Ethernet Ports)LAN ----- Devices
|________________________________________|
答案 1 :(得分:0)
根据Milinds的评论,我推翻了帖子的解决方案:
首先,安装以下软件包:
[...] net.ifnames=0 [...]
添加到/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
替换/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
创建/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
替换/etc/sysctl.conf
:
[...]
net.ipv4.ip_forward=1
[...]
取消注释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"
:
/etc/rc.local
立即运行iptable routing的以下命令:
exit 0
启动时启用ip表路由
在[...]
iptables-restore < /etc/iptables.ipv4.nat
[...]
之前添加到SELECT
COUNT(*) AS count,
article_id
FROM prices
GROUP BY article_id, price, tstamp
HAVING count > 1;
:
price
最后重新启动,pi应该像以太网端口上的wifi ap共享互联网一样工作。