0

I am using Raspbian (like Debian) and I used this tutorial https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/ to setup my Raspbian as a wifi access point. Clients can connect to AP successfuly. But how can I do this - client should be able to open page http://local and it should point to my apache on AP. I don't want to set /etc/hosts on clients (they can vary) so I need to set it on AP directly and it should serve the right IP to clients when they open http://local.

I followed dnsmasq this How to make a machine accessible from the LAN using its hostname but it is not working (it worked for a while but then it stopped working)

How should I set my AP to serve the right name IP translation?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
peter
  • 925

2 Answers2

2

I have my LAN connected through an asus rt-ac66u router, but most routers should work. Go to the router configuration and under section LAN (static dhcp Manually Assigned IP) assign the IP address and hostname, as well as MAC address of the raspberry pi you want to reach inside your LAN. Doing so your raspberry pi will get always the same ip address from the DHCP server (my asus router in this precise case).
Now, from where you are trying to connect (another computer in your LAN for instance?), check the /etc/resolv.conf file and if not present, then just add the ip address of your router inside your LAN (gateway). In my case:

nameserver 192.168.1.1

Now you should be able to ping it using the hostname of your raspberry...


Extending answer regarding comment of peter

In your raspberry pi AP:

    You can use the /etc/hosts.dnsmasq file to add hostnames linked to ip addresses:

   192.168.1.10 host_1
   192.168.1.11 host_2 

    Dont forget to add this line to /etc/dnsmasq.conf:

   addn-hosts=/etc/hosts.dnsmasq

    Now in your /etc/hosts of your AP:

   127.0.0.1 localhost.localdomain localhost
   192.168.1.1 raspberry-pi

You should be able to access by using hostname from anywhere in your LAN:

  • raspberry-pi
  • host_1
  • host_2
marc
  • 2,427
  • but I am trying to create AP directly in my Raspberry with build-in wifi module. I am not using router. Clients are connecting to RPi. – peter Mar 15 '16 at 20:41
  • thanks @mmmint. I tried exactly the same steps. I have no idea why it stopped working. Now it is working again. – peter Mar 15 '16 at 21:54
  • And again it didn't work. But when I manually run "sudo /etc/init.d/dnsmasq restart" in console then when I open http://mymachine.local it works ok. But when open "http://mymachine" this is not working. Strange. (I have both 192.168.0.2 for mymachine and mymachine.local in /etc/hosts) – peter Mar 16 '16 at 07:17
  • Please extend your primary question with all this information and the contents of your configuration files. The more detailed you present it, the better we can try to help. – marc Mar 16 '16 at 08:30
2

It is possible to define a local domain in dnsmasq; and define your hosts in /etc/hosts of the server/Linux running dnsmasq.

AS per the dnsmasq - ArchWiki

Adding a custom domain
It is possible to add a custom domain to hosts in your (local) network:

local=/home.lan/  
domain=home.lan  

In this example it is possible to ping a host/device (e.g. defined in your hosts file) as hostname.home.lan.
Uncomment expand-hosts to add the custom domain to hosts entries:

expand-hosts  

Without this setting, you'll have to add the domain to entries of /etc/hosts.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232