I looked at several solutions for this question, but none of them worked. Additionally, I tried some of the tutorials provided (with the necessary changes), but none of them worked
My aim is to use a RPi 3B+ as a router with an existing wireless router connected as an access point. The following figure explains this:
'eth0' is the Rpi's WAN port. The IP for eth0 is assigned automatically by a DHCP server that is beyond my control.
'eth1' is an 'USB to Ethernet' adapter. The wireless network is separated from the network the switch is in, by a NAT service that should run on the RPi.
I am following this tutorial as a guide. I have already configured the router as an AP.
My Problem: When I configure the network (i.e. edit the /etc/network/interfaces file) and restart the networking services (sudo /etc/init.d/networking restart
), I get the following error:
Restarting networking (via systemctl): networking.serviceJob for networking.service failed because the control process exited with error code.
See 'systemctl status networking.service' and 'journalctl -xn' for details.
I also get a similar error when I try to start the DHCP server after configuration.
Starting isc-dhcp-server (via systemctl): isc-dhcp-server.serviceJob for isc-dhcp-server.service failed because the control process exited with error code.
See 'systemctl status isc-dhcp-server.service' and 'journalctl -xn' for details.
In addition, when I install isc-dhcp-server using sudo apt-get install isc-dhcp-server
, it gives an error saying failed to start
although it installs properly.
Can someone show me what I'm doing wrong?
EDIT: I have made a change to the setup. Instead of getting a direct connection from the ISP, I get it through a switch (hence no modem). What happens beyond the switch is none of my concern)
-
1"Can someone show me what I'm doing wrong?" Running a 7 year old tutorial designed for an obsolete OS.Milliways– Milliways2019年08月20日 03:39:01 +00:00Commented Aug 20, 2019 at 3:39
-
1You might like to try the following tutorials: (1) Rpi Wireless Hotspot - elinux 2018aug elinux.org/RPI-Wireless-Hotspot (2) Setting up a Raspberry Pi as a Wireless Access Point raspberrypi.org/documentation/configuration/wireless/… (3) How to use your Raspberry Pi as a wireless access point - Stephen Lovely 2017july thepi.io/… (4) Setting up a Raspberry Pi 3 as an Access Point - Shawn Hymel learn.sparkfun.com/tutorials/…tlfong01– tlfong012019年08月20日 07:04:31 +00:00Commented Aug 20, 2019 at 7:04
-
What operating system do you use? What version? Is there a special reason why you don't connect the AP direct to ISP with an ethernet cable?Ingo– Ingo2019年08月20日 11:29:56 +00:00Commented Aug 20, 2019 at 11:29
-
@Ingo OS is Raspbian buster Jul 2019. I am replacing the router with the RPi to get more insight into the traffic. I am using the existing router as an AP connected to the RPi because its signal strength is better and I don't want to buy a new wifi dongle or something similar :)Nht_e0– Nht_e02019年08月20日 21:15:43 +00:00Commented Aug 20, 2019 at 21:15
-
I do not understand how the RasPi is connected to ISP by eth0. How does the interface eth0 gets it ip address? For what do you need a DHCP server on the RasPi? Does not the AP provide a DHCP server?Ingo– Ingo2019年08月20日 21:25:47 +00:00Commented Aug 20, 2019 at 21:25
2 Answers 2
To do what you want is simple with systemd-networkd because it has everything built-in and you don't need additional helpers. So I will use it for my suggestion, tested with Raspbian Buster Lite 2019年07月10日 updated on 2019年08月22日. Updates done with sudo apt update && sudo apt full-upgrade && sudo reboot
.
First switch over to systemd-networkd. For further information look at (1), (2) .
# disable classic networking
rpi ~$ sudo -Es
rpi ~# systemctl mask networking.service dhcpcd.service
rpi ~# mv /etc/network/interfaces /etc/network/interfaces~
rpi ~# sed -i '1i resolvconf=NO' /etc/resolvconf.conf
# enable systemd-networkd
rpi ~# systemctl enable systemd-networkd.service systemd-resolved.service
rpi ~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
Then create these files:
rpi ~# cat > /etc/systemd/network/04-eth0.network <<EOF
[Match]
Name=eth0
[Network]
DHCP=yes
IPForward=yes
EOF
rpi ~# cat > /etc/systemd/network/06-eth1.network <<EOF
[Match]
Name=eth1
[Network]
Address=192.168.5.1/24
DHCPServer=yes
[DHCPServer]
DNS=84.200.69.80 1.1.1.1
EOF
We also need a Network Address Translation (NAT) on interface eth0 to reach all devices on the access point. Create it with:
rpi ~# systemctl --full --force edit [email protected]
In the empty editor insert these statements, save them and quit the editor:
[Unit]
Description=NAT for interface %i
After=systemd-networkd.service
BindsTo=systemd-networkd.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/iptables -t nat -A POSTROUTING -o %i -j MASQUERADE
ExecStopPost=-/sbin/iptables -t nat -D POSTROUTING -o %i -j MASQUERADE
[Install]
WantedBy=systemd-networkd.service
Enable the new service:
rpi ~# sudo systemctl enable [email protected]
Reboot and it should do.
References:
(1): Compare three available networking systems on Raspbian
(2): Howto migrate from networking to systemd-networkd with dynamic failover
You could use my project I once wrote. It isn't perfect and I don't have the time making it better. I'm using dnsmasq and dnsmasq can communicate with eth and wifi due to the Layer-3 protocol.
My tool is tested on the Pi2 running Arch Linux.
The project