简体   繁体   中英

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. Now i also want to use the same pi as wifi ap. But all configuration examples i've found for pi bridging ethernet and wifi so the pi itself cannot access the ethernet anymore.

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

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?

For topology something like this, the configuration is this .

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

Based on Milinds comment i reversed a solution from the post:

First, install the following packages:

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

add to /boot/cmdline.txt :

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

replace /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 :

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 :

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 :

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

Run now the following commands for iptable routing:

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

add to /etc/rc.local before exit 0 :

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

Finally reboot and the pi should works as intended as wifi ap sharing internet from ethernet port.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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