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
Barth
  • 1
  • 1
  • 2

1 Answers1

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.

Ingo
  • 42,961
  • 20
  • 87
  • 207