0

I am trying to set up my raspberry pi to act as a router. The set up is the following:

  • The Raspi receives its connection to the internet through Ethernet, with a static IP address setting. The subnet mask for this connection is supposed to be 255.255.255.252, however on other devices it also works with 255.255.255.0.
  • I have set up my Raspi to act as a wireless acce point by following this guide: Link
  • I have 4-5 devices that connect to the Wifi network generated by the Raspberry Pi.

Once set up, the WiFI access point works for maybe a minute or two. Then, devices connected lose access to the internet, and if they disconnect from the wifi, they cannot reconnect.

I would like to know if anyone has either a solution for this issue, or a method for me to understand what is going on. For example, are there system logs I can look at to understand what is going on? Thanks everyone for the help :D

Dhcpd.conf:

interface eth0
static routers=41.221.98.113
static domain_name_servers=41.221.96.67
static domain_search=41.221.96.68
static ip_address=41.221.98.114/30

interface wlan0
static ip_address=49.221.98.114/24
nohook wpa_supplicant
static routers=
static domain_name_servers=41.221.96.67
static domain_search=41.221.96.68

/etc/sysctl.d/routed-ap.conf

net.ipv4.ip_forward=1

/etc/dnsmasq.conf

interface=wlan0 # Listening interface
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
                # Pool of IP addresses served via DHCP
domain=wlan     # Local wireless DNS domain
address=/gw.wlan/192.168.4.1
                # Alias for this router

/etc/hostapd/hostapd.conf

country_code=MW
interface=wlan0
ssid=ssid
hw_mode=g
channel=7
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=passphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
4
  • https://www.raspberrypi.org/documentation/confi ... -routed.md isn't a valid link Jun 15, 2020 at 23:01
  • Rather than letting us assume you followed the guide correctly, can you show, in the question the contents of the files you modified to try and get this to work Jun 15, 2020 at 23:57
  • Assuming you are referencing the Foundation link you didn't follow it - a "subnet mask" and 255.255.255.252 would give you 2 IP addresses.
    – Milliways
    Jun 16, 2020 at 0:11
  • Thanks for your feedback - I edited the original post !
    – Barth
    Jun 16, 2020 at 12:30

1 Answer 1

3

You can try to use systemd-networkd that do not need additional helper programs which all must respect your uncommon network mask. You can set it in one configuration file and it should do. You can look at Setting up a Raspberry Pi as an access point - the easy way how to do it. You have to use section ♦ Setting up an access point and with eth0, with NAT (recommended). There you will find the configuration file for the wired ethernet uplink interface:

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

Just use instead this configuration for the example. Of course you have to use your own ip address settings:

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

The netmask 255.255.255.252 is noted here with the equivalent bitmask /30 on the ip address 192.168.50.2/30. This netmask/bitmask defines a subnet with only two ip addresses 192.168.50.1 and 192.168.50.2. You have to ensure that the internet router uses the other ip address.

In a comment you wrote that the ip address of your internet router is 41.221.98.113. This is the public ip address of your router seen from the internet. It cannot be used with your private network. The RasPi is connected with an ethernet cable to your router. The port on the router where the cable is connected has also a private ip address. If you want to use a static ip address on the RasPi, you must know the private ip address of the router. It is very uncommon that an internet router does not serve DHCP. So you should really try to enable DHCP on the RasPi as shown in the first version of the configuration file.

5
  • Thank you ! Does the IP address have to be on the same network as the eth0 static IP configuration?
    – Barth
    Jun 16, 2020 at 12:16
  • Just tried this set up - I am able to generate a network, connect devices to it, and ping the RaspPi, but still no access to the connection. I have changed only the eth0 settings and the Raspi can access the internet. I do not have access to the router, my connection comes directly by ethernet cable, so I'm not able to set a route on the router to the Raspi.
    – Barth
    Jun 16, 2020 at 13:06
  • @Barth "Does the IP address have to be on the same network as the eth0 static IP configuration?" I do not understand the question. You have two subnets 192.168.4.0/24 on the access point and 192.168.50.0/30 with eth0 of the RasPi and the interface of the internet router. Routing is enabled between these two subnets. What ip address has your internet router? The simplest way to avoid problems is to use DHCP as shown in the first version of the config file.
    – Ingo
    Jun 16, 2020 at 13:13
  • Ok, this clears it up ! The ip address of the router is 41.221.98.113. I do not have access to the router and I believe it does not use DHCP - hence, I have to set up a static IP address for my ethernet connection.
    – Barth
    Jun 16, 2020 at 13:17
  • @Barth I have updated the answer with the last paragraph.
    – Ingo
    Jun 16, 2020 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.