ArieLevs / Raspberry-WiFi-Repeater

Guide to set raspberry pi as wifi access point - bridge
MIT License
60 stars 11 forks source link

Name-serve DHCP-assigned addresses #12

Closed autarkper closed 2 years ago

autarkper commented 3 years ago

Since the repeater acts as a DHCP server it would be great if it could serve as a simple name server, to provide the addresses of the attached devices by name, only forwarding requests it cannot handle upstream to the router.

Scenario: 1) Device "barbara" is assigned IP address 10.0.1.36. 2) Device "berber" is assigned IP address 10.0.1.63. The router is configured to assign berber address 192.168.1.199. 3) User on device "barbara" tries to ping device "berber"

Current behavior:

PING berber.mydomain.example (192.168.1.199) 56(84) bytes of data.
From raspberrypi.mydomain.example (192.168.1.26) icmp_seq=1 Destination Host Unreachable

Desired behavior:

PING berber (10.0.1.63) 56(84) bytes of data.
64 bytes from 10.0.1.63: icmp_seq=1 ttl=64 time=263 ms
autarkper commented 3 years ago

It looks like this could be achieved by tweaking the settings in dnsmasq.conf.

autarkper commented 3 years ago

I have got it more or less working by adding the following directly to /etc/dnsmasq.conf:

domain-needed
bogus-priv
addn-hosts=/etc/dnsmasq_static_hosts.conf
local=/mydomain.example/
domain=mydomain.example
expand-hosts

The "mydomain.example" stuff is a dirty hack to make it work with the ping command:

 $ ping berber
PING berber.mydomain.example (10.0.1.63) 56(84) bytes of data.
64 bytes from berber.mydomain.example (10.0.1.63): icmp_seq=1 ttl=64 time=184 ms
autarkper commented 3 years ago

I have discovered a problem: the router still seems to be involved in DHCP, as hinted by the output of dhclient

 $ sudo dhclient -v -r
[sudo] password for pang: 
Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wwp0s20u4i6/36:bd:ad:0b:04:4d
Sending on   LPF/wwp0s20u4i6/36:bd:ad:0b:04:4d
Listening on LPF/wlan0/e0:9d:31:0d:1c:a8
Sending on   LPF/wlan0/e0:9d:31:0d:1c:a8
Listening on LPF/eth0/3c:97:0e:e8:38:6d
Sending on   LPF/eth0/3c:97:0e:e8:38:6d
Sending on   Socket/fallback
DHCPRELEASE on wlan0 to 192.168.1.1 port 67 (xid=0x444e5d05)

I had expected 10.0.1.1 instead of 192.168.1.1 on the last line

I don't know whether this is due to my changes.

ArieLevs commented 3 years ago

Hi @autarkper I was not able to reproduce your scenario.

I've tested a setup like this:

autarkper commented 3 years ago

Hi @ArieLevs,

Are you saying that you cannot recreate my initial scenario? My problems might be due to my router having been set up to serve my devices specific addresses in the 192.168.1.x range. If you don't have that setup this could perhaps work out of the box. With my changes to dnsmasq.conf I am now more or less satisfied. I even got the dhclient issue sorted, somehow.