26

I know how to do it the classic way as described for example by the official documentation at Wireless connectivity. But that needs many different components which must play together and each component must be configured its own way. These are networking (ifupdown), dhcpcd, hostapd, dnsmasq and bridge-utils.

Nowadays Raspbian Stretch has all needed components built in so it is not necessary to install additional software. This could simplify the setup a lot.

Is it possible just to configure Raspbian to work as an wifi access point without installing additional software?

Ingo
  • 40,606
  • 15
  • 76
  • 189

3 Answers3

47

━━━ Setting up an access point ━━━

We are talking about an access point together with an ethernet port eth0.

If you want an access point together with a wlan0 client connection to another wifi network (wlan repeater) then look at Access point as WiFi router/repeater, optional with bridge.

It is possible to configure Raspbian Stretch as a wifi access point without installing additional software. All needed components are available: networking, DHCP server and bridging comes with systemd-networkd and wifi can be setup with wpa_supplicant. Connecting two interfaces eth0 and wlan0 can be done by routing or by bridging. Below first the setup for quick installation and then the details. First we have to switch over to systemd-networkd.

Tested with
Raspbian Buster Lite 2020-02-13 on a Raspberry Pi 4B updated at 2020-05-12.
Updates done with sudo apt update && sudo apt full-upgrade && sudo reboot.
Here you can find the last tested revision for previous Raspbian versions.


♦ General setup

Switch over to systemd-networkd

Just follow to Use systemd-networkd for general networking. You can use section "♦ Quick Step". Then come back here.

Configure wpa_supplicant as access point

To configure wpa_supplicant as access point create this file with your settings for country=, ssid=, psk= and maybe frequency=. You can just copy and paste this in one block to your command line beginning with cat and including both EOF (delimiter EOF will not get part of the file):

rpi ~$ sudo -Es   # if not already done
rpi ~# cat > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf <<EOF
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="RPiNet"
    mode=2
    frequency=2437
    #key_mgmt=NONE   # uncomment this for an open hotspot
    # delete next 3 lines if key_mgmt=NONE
    key_mgmt=WPA-PSK
    proto=RSN WPA
    psk="password"
}
EOF

rpi ~# chmod 600 /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rpi ~# systemctl disable wpa_supplicant.service
rpi ~# systemctl enable wpa_supplicant@wlan0.service
rpi ~# rfkill unblock wlan

Finished General setup. Go back.


♦ Setting up a stand alone access point

Example for this setup:

                 wifi
mobile-phone <~.~.~.~.~> (wlan0)RPi(eth0)
            \             /
           (dhcp)   192.168.4.1

Do "General setup" then create the following file to configure wlan0. We only have the access point. There is no ethernet device configured.

rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
Address=192.168.4.1/24
MulticastDNS=yes
DHCPServer=yes
EOF

If you want this then reboot.
That's it.
Otherwise go on, no need to reboot at this time.


♦ Setting up an access point and with eth0, without routing

Example for this setup:

                                 |
                 wifi            |           wired            wan
mobile-phone <~.~.~.~.~> (wlan0)RPi(eth0) <---------> router <---> INTERNET
            \             /      |     \             /
           (dhcp)   192.168.4.1  |    (dhcp)   192.168.50.1

Setup

Do "Setting up a stand alone access point" then create the following file to configure eth0.

rpi ~$ sudo -Es   # if not already executed before
rpi ~# cat > /etc/systemd/network/04-eth0.network <<EOF
[Match]
Name=eth0
[Network]
DHCP=yes
EOF

Reboot.
That's it.

Details

Interface eth0 is connected with an ethernet cable to the internet router and gets it configuration by DHCP from the internet router. It is no problem to give it a static ip address with e.g. Address=192.168.50.2 instead of DHCP=yes.

Without routing you cannot get into the internet with the mobile-phone. You can only get into it from the RPi itself to get updates or something like.


♦ Setting up an access point and with eth0, with NAT (recommended)

Example for this setup:

                 wifi                        wired            wan
mobile-phone <~.~.~.~.~> (wlan0)RPi(eth0) <---------> router <---> INTERNET
            \             /            \
           (dhcp)   192.168.4.1       (dhcp)

Setup

Do "General setup" then create the following files to configure wlan0 and eth0. If you have tried one of the previous setups then you can just overwrite the two files. Be sure that you use a different subnet for the access point than that from the router. The router in this example does not use subnet 192.168.4.0/24. If you need another subnet then just change the Address line, e.g. Address=192.168.5.1/24.

rpi ~$ sudo -Es   # if not already executed before
rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
Address=192.168.4.1/24
MulticastDNS=yes
# IPMasquerade is doing NAT
IPMasquerade=yes
DHCPServer=yes
[DHCPServer]
DNS=84.200.69.80 1.1.1.1
EOF

rpi ~# cat > /etc/systemd/network/04-eth0.network <<EOF
[Match]
Name=eth0
[Network]
DHCP=yes
EOF

Reboot.
That's it.

Details

If you have no access to the internet router you can fake it with NAT (network address translation) to tell it a lie that all packages are coming from your RasPi AP. But this is not clean routing and has limitations. Clients on the subnet of the router cannot connect to clients on the wifi. But in most cases this is not needed so this setup is recommended because it simplifies the setup. If you need to connect to the wifi clients from the router network then you have to use full routing as desribed in the next section.


♦ Setting up an access point and with eth0, with routing

Example for this setup:

                 wifi                        wired            wan
mobile-phone <~.~.~.~.~> (wlan0)RPi(eth0) <---------> router <---> INTERNET
            \             /            \              /
           (dhcp)   192.168.4.1   192.168.50.2   192.168.50.1

Setup

Do "General setup" then create the following files to configure wlan0 and eth0. If you have tried one of the previous setups then you can just overwrite the two files. Be sure that you use different subnets for the access point and the router network. We have to use static ip addresses because we must use them as gateways.

rpi ~$ sudo -Es   # if not already executed before
rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
Address=192.168.4.1/24
MulticastDNS=yes
DHCPServer=yes
[DHCPServer]
DNS=84.200.69.80 1.1.1.1
EOF

rpi ~# cat > /etc/systemd/network/04-eth0.network <<EOF
[Match]
Name=eth0
[Network]
Address=192.168.50.2/24
Gateway=192.168.50.1
DNS=84.200.69.80 1.1.1.1
IPForward=yes
EOF

Reboot.

To get routing complete working you have to set a static route in your internet router so it can find the route for back coming packages over the RasPi to the clients connected by wifi to the access point. On most internet router you can set a static route but how to do that varies from model to model. It's up to you to find it out. For example your RasPi eth0 interface has the static ip address 192.168.50.2. Then on your router the gateway (next hop) is 192.168.50.2, destination network is 192.168.4.0/24 (or 192.168.4.0 netmask 255.255.255.0).

That means for the internet router: "send all packages belonging to subnet 192.168.4.0/24 (destination network from AP) to the next router on my subnet, the RasPi AP 192.168.50.2 (gateway). It knows where to go on."

That's it.


♦ Setting up an access point with a bridge

Example for this setup:

                               RPi
               wifi   ┌──────bridge──────┐   wired            wan
mobile-phone <.~.~.~> │(wlan0) br0 (eth0)│ <-------> router <-----> INTERNET
            \                   |                   / DHCP-server
           (dhcp              (dhcp           192.168.50.1
        from router)       from router)

If you have already an ethernet network with DHCP server and internet router and you want to expand it with a wifi access point but with the same ip addresses then you use a bridge. This is often used as an uplink to a router.

Setup

Do "General setup" then create the following three files to configure the network interfaces. If you have tried one of the previous setups then you can just delete all files in /etc/systemd/network/ except 99-default.link if present. The ip addresses are examples. You have to use your own.

rpi ~$ sudo -Es   # if not already executed before
rpi ~# cat > /etc/systemd/network/02-br0.netdev <<EOF
[NetDev]
Name=br0
Kind=bridge
EOF

rpi ~# cat > /etc/systemd/network/04-br0_add-eth0.network <<EOF
[Match]
Name=eth0
[Network]
Bridge=br0
EOF

rpi ~# cat > /etc/systemd/network/12-br0_up.network <<EOF
[Match]
Name=br0
[Network]
MulticastDNS=yes
DHCP=yes
# to use static IP uncomment these and comment DHCP=yes
#Address=192.168.50.60/24
#Gateway=192.168.50.1
#DNS=84.200.69.80 1.1.1.1
EOF

Now we have to tell wpa_supplicant to use a bridge. We do it by modifying its service with:

rpi ~# systemctl edit wpa_supplicant@wlan0.service

In the empty editor insert these statements, save them and quit the editor:

[Service]
ExecStartPre=/sbin/iw dev %i set type __ap
ExecStartPre=/bin/ip link set %i master br0

ExecStart=
ExecStart=/sbin/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-%I.conf -Dnl80211,wext -i%I -bbr0

ExecStopPost=-/bin/ip link set %i nomaster
ExecStopPost=-/sbin/iw dev %i set type managed

Reboot.
That's it.

Details

We have to tell wpa_supplicant that its interface wlan0 is slave of a bridge. Otherwise it will reject client connects with "wrong password" means the key negotiation does not work. When we tell /sbin/wpa_supplicant with option -dbr0 to use a bridge for wlan0 then the interface must already be a member of the bridge. That's what we do with the drop in file (overlay) for the wpa_supplicant service. The empty statement ExecStart= deletes the old entry. Otherwise you have two lines ExecStart= and wpa_supplicant will start two times. The original ExecStart= you can view with systemctl cat wpa_supplicant@wlan0.service.

Normally the router you are connected to with the ethernet cable has a DHCP server enabled. The bridge is also transparent for DHCP requests from the stations (devices connected to the access point) so you don't have to worry about configuration of its interfaces with ip addresses and options. The router will serve it.
excursus:
But if the router doesn't have a DHCP server, you can setup one on the RasPi. systemd-networkd has options to configure its built-in DHCP server but the problem is that systemd-networkd assumes it is running on the router itself and that's not true in this case. It will serve wrong options to the stations, in particular the router option. There is no way to configure it. So we have to install dnsmasq in this case that can be configured as needed. Install and configure it with (example, use your own ip addresses):

rpi ~$ sudo -Es
rpi ~# apt install dnsmasq
rpi ~# systemctl stop dnsmasq
rpi ~# mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

rpi ~# cat > /etc/dnsmasq.conf <<EOF
interface=br0
  dhcp-range=192.168.50.128,192.168.50.164,255.255.255.0,24h
  dhcp-option=option:router,192.168.50.1
  dhcp-option=option:dns-server,8.8.8.8,1.1.1.1
EOF

rpi ~# systemctl start dnsmasq
rpi ~# exit
rpi ~$

In this example are ip addresses 192.168.50.128 to 192.168.50.164 reserved to give to stations. For other static ip addresses use one outside this pool, also the ip address for the bridge itself.


♦ Optimizing

When starting wpa_supplicant you mostly get this messages in the journal:

wpa_supplicant[427]: random: Cannot read from /dev/random: Resource temporarily unavailable
wpa_supplicant[427]: random: Only 12/20 bytes of strong random data available from /dev/random
wpa_supplicant[427]: random: Not enough entropy pool available for secure operations
wpa_supplicant[427]: WPA: Not enough entropy in random pool for secure operations - update keys later when the first station connects

It is not a big issue. wpa_supplicant needs random numbers to generate encrpyting keys. This is done a little bit slow so it has to wait. Fortunately the RasPi has a build in True Random Number Generator (TRNG). We can use it and speed up getting random numbers by installing a piece of software (3) with:

rpi ~$ sudo apt install rng-tools

Update:
Since Raspbian Stretch 2019-04-08 there is no need to install rng-tools. They are installed by default.


♦ Troubleshooting

systemd-networkd

Look at the status of a service:

rpi ~$ systemctl status systemd-networkd.service
rpi ~$ systemctl status wpa_supplicant@wlan0.service

Or even a bit more:

rpi ~$ journalctl --boot --pager-end

I found it helpful to follow the ongoing logging:

rpi ~$ journalctl --boot --follow

If you have made a drop in file you can look at the result:

rpi ~$ systemctl cat wpa_supplicant@wlan0.service

To check the runtime environment of a unit you can show it and for example look if there are two ExecStart= lines:

rpi ~$ systemctl show wpa_supplicant@wlan0.service

And if nothing others help you can enable the debug option from /sbin/wpa_supplicant with -d in a drop in file:

rpi ~$ sudo systemctl edit wpa_supplicant@wlan0.service
ExecStart=
ExecStart=/sbin/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-%I.conf -Dnl80211,wext -i%I -bbr0 -d

The output is in the journal. This way I have found the issue with the wrong key negotiation.

wifi

If you have setup the access point you should find it with a mobile phone. Showing the available networks, it is presented with name RPiNet and you can connect to it. On the RasPi you can also use the command:

rpi ~$ sudo iw dev wlan0 info
phy#0
        Interface wlan0
                ifindex 3
                wdev 0x2
                addr b8:27:eb:06:e8:8b
                ssid RPiNet
                type AP
                channel 1 (2412 MHz), width: 20 MHz, center1: 2412 MHz

As you can see it is type AP (access point) and it will also show you what channel it is using. A problem may be to translate a channel into frequency. The frequency must match a channel. You can look at (2) for a list of WLAN channels. For example to use channel 36 on the 5.1 GHz band you have to set frequency=5180 in /etc/wpa_supplicant\wpa_supplicant.conf. But you must be sure that your wifi supports the 5.1 GHz band. You can check with sudo iw phy. This will give you a bunch of information. It must also contain supported frequencies above 5000 MHz. If you only see frequencies of 24xx MHz then of course you can only use this.

Another point could be random numbers. For encrypting keys for secured connections wpa_supplicant needs random numbers. Generating this is very slow on a Raspberry Pi. If it does not have enough entropy to generate encrypting keys wpa_supplicant will reject the authentication. You can look with cat /proc/sys/kernel/random/entropy_avail how many entropy is available. It should be >1000 to work quick enough. To speed up this, the rng-tools are installed by default. Look at the section Optimizing for further information.


references:
[1] Howto migrate from networking to systemd-networkd with dynamic failover
[2] List of WLAN channels
[3] Rng-tools

Ingo
  • 40,606
  • 15
  • 76
  • 189
  • rpi ~# systemd-tmpfiles --create --prefix /var/log/journalroot FAILS with this output message @pi:~ # systemd-tmpfiles --create --prefix /var/log/journal Cannot set file attribute for '/var/log/journal', value=0x00800000, mask=0x00800000: Operation not supported Cannot set file attribute for '/var/log/journal/6d18954849a74479955b761e891619aa', value=0x00800000, mask=0x00800000: Operation not supported So the journal cannot be implemented. Not a good start of implementing the procedure . – Jan Hus Aug 18 '18 at 00:51
  • 1
    Hi @JanHus Thanks for your feedback. This is only a warning not an error and doesn't matter. I also get it every time. The persistent journal is created. Look with `ls /var/log/journal/`. You will see a directory that looks like `fa9462093e8d419cb646d0a0c44771c2`. This is the storage for the journal you access with `journalctl`. I will update my answer. – Ingo Aug 18 '18 at 06:59
  • Yes, I did checked if the file was created. But I got sidetracked and stopped. I'll continue today. So far this is one of the better "tutorials" on subject. Thanks for posting it. PS is calling it persistent OK ? Little confusing when it is created using temp process. – Jan Hus Aug 18 '18 at 18:08
  • @JanHus Please give me feedback if there are some issues so I can improve the answer. – Ingo Aug 18 '18 at 20:34
  • Will do, not sure if "giving feedback " is OK since this forum is all about "answers" not about discussion. – Jan Hus Aug 19 '18 at 01:43
  • @JanHus This format is to optimize questions and answers. That is what the comments are for. Giving feedback if it works is 100% OK. For discussion we have the chat. Everyone with some reputation can open a chat room and invite others. – Ingo Aug 19 '18 at 08:02
  • Great if "chat" is not scrutinized / censored as this part of forum.I need to finish another project before I get back to using your procedure. – Jan Hus Aug 19 '18 at 16:39
  • I am currently putting your tutorial as FIRST debugging tool / process in my debug script. It is doing OK, but I need to figure out how to make it interactive since some of the commands get replies. – Jan Hus Aug 20 '18 at 01:12
  • 2
    @Ingo I think it is recommended to use `proto=WPA2` in the AP configuration. My phone, at least, complains about "weak security" without it. – Robin Dinse Mar 31 '19 at 00:21
  • 2
    @RobinDinse You are right, of course. I have overseen it. Thanks for the hint. I have added `proto=RSN`. That's what the docu prefers (naming `proto=WPA2` an alias). – Ingo Mar 31 '19 at 00:53
  • Would this work if I want my Pi to be AP and connect to two other networks at the same time? See my question: https://raspberrypi.stackexchange.com/questions/98599/connecting-the-pi-to-multiple-wifi-networks-simultaneously?noredirect=1#comment161321_98599 – Vin Shahrdar May 16 '19 at 13:31
  • @VinShahrdar No, it is not possible to have an access point and two **managed** client connections, as I explained in my answer there. Please refer to the **valid interface combinations** I have given in that answer. It exactly shows what combinations are possible. Having two managed client connections is only possible with an additional USB/wifi dongle. – Ingo May 16 '19 at 13:45
  • @Ingo, will you be posting an updated version for raspbian buster? I think I just tried it with the new buster and something wasn't going through. Similar with my ppp0 device was also not working. – Agustin Aug 08 '19 at 22:35
  • @Agustin Please look at the beginning of the answer. There you will find "*Tested with [Raspbian Buster Lite 2019-07-10](https://www.raspberrypi.org/downloads/raspbian/) updated on 2019-07-20*". – Ingo Aug 08 '19 at 22:43
  • @Ingo, noticed it a bit too late, couldn't delete my comment but thanks! I still had to add a sleep on my systemd unit service because my hotspot wasn't being detected or enabled on boot anymore. – Agustin Aug 09 '19 at 03:27
  • I'm using bridge mode. These instructions seem to work when the AP SSID is different to the router one but when they are the same it seems clients connect to the router in preference to the RasPi even when the latter's signal strength is much greater. Is this expected behaviour? – Nathan Phillips Sep 10 '19 at 07:22
  • @NathanPhillips I haven't thought about this possibility before, interesting. Can't say something about it at the moment but I will have a look at it and will come back. – Ingo Sep 10 '19 at 08:36
  • You might want to precise that that gateway 192.168.50.1 should be replaced with whatever our own router is using, typically 192.168.0.1 or 192.168.1.1, no? Also I've followed "Setting up an access point and with eth0, with routing" and my Android phone refuses to connect to it. (Using a laptop it connects alright, that's pretty strange) Any ideas what might be the issue? – Lery Mar 05 '21 at 13:03
  • 1
    @Lery Thanks for the hint. I have updated the answer. Your Android phone should at least connect to the access point on network 192.168.4.0/24. As far as I can see it has nothing to do with routing. Android needs a DHCP server. You may check that. But you should better ask new question if you need more information. – Ingo Mar 11 '21 at 18:23
7

An even EASIER way of setting up a Raspberry Pi as an AP is to use the pi-ap Github repo which automates configuration of a Pi 3B+/4 into an AP.

Connect the Pi to a free port in your Internet-connected router which has DHCP enabled (probably the case in most consumer routers).

Once connected, SSH into Pi on the DHCP assigned IP assigned to eth0 by router and then:

git clone https://github.com/f1linux/pi-ap

cd pi-ap

nano variables.sh   # Change default values for SSID & password

sudo ./install.sh

Drink tea and after waiting about 2 minutes the SSID you set invariables.sh will appear in your wireless networks list. Connect to the Pi's WLAN being advertised.

To SSH directly to AP itself on Pi's wlan0 interface, use default IP of 192.168.0.1

PLEASE NOTE: the default DHCP subnet pi-ap uses to assign WiFi clients IPs in variables.sh is 192.168.0.0/28. If you're already using that subnet on your network, set a different subnet in variables.sh for WiFi clients BEFORE executing install.sh.

No subnet calculator or even serious networking skills required to achieve good results. pi-ap even supports access restriction via MAC ACLs.

DISCLOSURE: I'm the developer of pi-ap.

F1Linux
  • 1,589
  • 1
  • 9
  • 28
  • This looks useful, but I've not tried it yet. I'm posting this comment mainly to ask if you intend to update your script at some point to cover `bullseye`? – Seamus Apr 02 '22 at 15:48
1

━━━ Check installation step by step with checkpoints ━━━

This answer is not thought for setup. For a stable setup look at the other answer Setting up an access point.

This answer is mainly for troubleshooting and to show how it works with detailed commands step by step and checkpoints but without background information. I suppose you have a monitor, keyboard and mouse attached to your Raspberry Pi. Ip addresses and other settings in this check up are examples. You have to use yours. You can always look at journalctl -b -e for logged information.

Download ZIP image Raspbian Stretch Lite 2018-11-13 to your linux pc.

Checkpoint 1: Compare the checksum with that on the download site.

pc ~$ sha256sum 2018-11-13-raspbian-stretch-lite.zip

47ef1b2501d0e5002675a50b6868074e693f78829822eef64f3878487953234d 2018-11-13-raspbian-stretch-lite.zip

Next step: Burn the image to an attached SD Card:

pc ~$ unzip -p 2018-11-13-raspbian-stretch-lite.zip | sudo dd of=/dev/sdb bs=4M conv=fsync

Checkpoint 2: check partitions on the SD Card:

pc ~$ sudo parted /dev/sdb print
Model: Mass Storage Device (scsi)
Disk /dev/sdb: 3965MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  50,2MB  46,0MB  primary  fat32        lba
 2      50,3MB  1866MB  1816MB  primary  ext4

Next step: Mount the boot partition and create a wpa_supplicant.conf file:

pc ~$ mkdir boot/
pc ~$ sudo mount /dev/sdb1 boot/
pc ~$ sudo -e boot/wpa_supplicant.conf

# insert this into the empty editor with your settings, save it and quit the editor
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="RPiNet"
    mode=2
    key_mgmt=WPA-PSK
    psk="password"
    frequency=2412
}

pc ~$ sudo umount boot/

Put the SD Card into your RasPi and boot.

Checkpoint 3: After login, check the wired connection. The eth0 interface must have an ip address:

rpi ~$ ip -4 addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 192.168.50.177/24 brd 192.168.50.255 scope global eth0
       valid_lft forever preferred_lft forever

rpi ~$ ping -I eth0 -c3 google.com
PING google.com (172.217.22.78) from 192.168.50.177 eth0: 56(84) bytes of data.
64 bytes from fra15s17-in-f14.1e100.net (172.217.22.78): icmp_seq=1 ttl=55 time=15.0 ms
64 bytes from fra15s17-in-f14.1e100.net (172.217.22.78): icmp_seq=2 ttl=55 time=14.7 ms
64 bytes from fra15s17-in-f14.1e100.net (172.217.22.78): icmp_seq=3 ttl=55 time=15.1 ms

--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 14.729/14.965/15.125/0.170 ms

This should work out of the box. If it doesn't work then you have a general problem with your network setup. Please fix it before continuing.

Checkpoint 4: Check the access point:

rpi ~$ sudo iw dev wlan0 info
Interface wlan0
        ifindex 3
        wdev 0x1
        addr b8:27:eb:06:e8:8b
        ssid RPiNet
        type AP
        wiphy 0
        channel 1 (2412 MHz), width: 20 MHz, center1: 2412 MHz
        txpower 31.00 dBm

The wlan0 interface shoud have an ip address. Because we haven't configured the interface it will have a Link-local address from 169.254.0.0/16.

rpi ~$ ip -4 addr show dev wlan0
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 169.254.210.182/16 brd 169.254.255.255 scope global wlan0
       valid_lft forever preferred_lft forever

You will see RPiNet in the list of acccess points on your mobile phone but you cannot connect to it yet.

Next step: Full upgrade and reboot:

rpi ~$ sudo apt update
rpi ~$ sudo apt full-upgrade
rpi ~$ sudo systemctl reboot

After reboot and login, switch over to systemd-networkd:

rpi ~$ sudo -Es
rpi ~# mkdir -p /var/log/journal
rpi ~# systemd-tmpfiles --create --prefix /var/log/journal #ignore warnings (*)

rpi ~# apt install rng-tools
rpi ~# systemctl mask networking.service
rpi ~# systemctl mask dhcpcd.service
rpi ~# sudo mv /etc/network/interfaces /etc/network/interfaces~
rpi ~# sed -i '1i resolvconf=NO' /etc/resolvconf.conf

rpi ~# systemctl enable systemd-networkd.service
rpi ~# systemctl enable systemd-resolved.service
rpi ~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

(*) You will get one or two confusing warnings "...Cannot set file attribute..." This are not errors and doesn't matter in this case.

Create these files for interfaces eth0 and wlan0 with your settings:

rpi ~# cat > /etc/systemd/network/04-eth0.network <<EOF
[Match]
Name=eth0
[Network]
Address=192.168.50.60/24
Gateway=192.168.50.1
DNS=84.200.69.80 84.200.70.40
IPForward=yes
EOF

rpi ~# cat > /etc/systemd/network/08-wlan0.network <<EOF
[Match]
Name=wlan0
[Network]
Address=192.168.4.1/24
DHCPServer=yes
[DHCPServer]
DNS=84.200.69.80 84.200.70.40
EOF

Rename /etc/wpa_supplicant/wpa_supplicant.conf so it matches the interface setting and reboot:

rpi ~# mv /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
rpi ~# systemctl disable wpa_supplicant@wlan0.service
rpi ~# systemctl reboot

Checkpoint 5: After reboot and login check wired connection eth0:

rpi ~$ ip -4 addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 192.168.50.60/24 brd 192.168.50.255 scope global eth0
       valid_lft forever preferred_lft forever

rpi ~$ ping -I eth0 -c3 google.com
PING google.com (172.217.10.14) from 192.168.50.60 eth0: 56(84) bytes of data.
64 bytes from lga34s12-in-f14.1e100.net (172.217.10.14): icmp_seq=1 ttl=51 time=93.5 ms
64 bytes from lga34s12-in-f14.1e100.net (172.217.10.14): icmp_seq=2 ttl=51 time=93.5 ms
64 bytes from lga34s12-in-f14.1e100.net (172.217.10.14): icmp_seq=3 ttl=51 time=93.5 ms

--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 93.519/93.551/93.592/0.030 ms

Checkpoint 6: Check wifi connection wlan0:

rpi ~$ sudo systemctl start wpa_supplicant@wlan0.service
rpi ~$ sudo iw dev wlan0 info
Interface wlan0
        ifindex 3
        wdev 0x1
        addr b8:27:eb:06:e8:8b
        ssid RPiNet
        type AP
        wiphy 0
        channel 1 (2412 MHz), width: 20 MHz, center1: 2412 MHz
        txpower 31.00 dBm

rpi ~$ ip -4 addr show dev wlan0
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 192.168.4.1/24 brd 192.168.4.255 scope global wlan0
       valid_lft forever preferred_lft forever

Check wifi on your mobile phone. You should find RPiNet and you can connect to it. Your mobile phone cannot get into the internet because routing isn't configured yet.

Next step: enable NAT for internet connection. To configure NAT you have to extend the wpa_supplicant service with:

rpi ~$ sudo systemctl edit wpa_supplicant@wlan0.service

In the empty editor insert these statements, save them and quit the editor:

[Service]
ExecStartPre=/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
ExecStopPost=-/sbin/iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

Then do:

rpi ~$ sudo systemctl daemon-reload
rpi ~$ sudo systemctl restart systemd-networkd.service
rpi ~$ sudo systemctl restart wpa_supplicant@wlan0.service

Checkpoint 7: Now you should be able to get into the internet with the mobile phone.

Ingo
  • 40,606
  • 15
  • 76
  • 189
  • @Wim You asked in a deleted answer: "How can this be done with the new Raspbian release Buster?" This answer "━━━ Check installation step by step with checkpoints ━━━" is not the right one if you want to setup an access point. For this you should use the other answer "━━━ Setting up an access point ━━━" here on this side. It also works with Raspbian Buster. I have it just verified. – Ingo Jul 20 '19 at 11:28