I have a website running on Apache. When users connect to the Raspberry AP, they can access to the website using the Raspberry's IP.

But what I want to do is type an speific direction (like "Mywebsite.com"), and this will redirect me to the Raspberry's IP.

I've used hostapd and dnsmasq, but I don´t know how to configure the last one to do this.

  • So, do you plan to setup a closed loop network (no internet) with a Raspi AP and nodes connected to that?
    – vaha
    Oct 17 '16 at 23:12

First you need to configure dnsmasq correctly, add the A records private class IPv4 only, I denoted three methods for resolving hosts (without using upstream servers for sure), example :

NOTE: Assume is the dnsmasq IPv4 listen address for the DNS server

You must find associated parameters for choose a method how to serve the dns response What you did not specify correctly in your question.(upstream server ? -S, --local, --server ?) , the best choice is to read the dnsmasq configuration file.

no-resolv # tell dnsmasq don't read the /etc/resolv.conf dns server system file.
no-hosts # tell dnsmasq don't read /etc/hostname system file.
log-queries # log the dns queries
log-facility=/tmp/dnsmasq.queries.txt #log the queries into specified file

1) Using address=/domain/ipaddr' in dnsmasq configuration file:

# A records (can probably be simplified in one line if the same server is used)

2) Using your own host file in dnsmasq configuration file:


and create a file /tmp/myhosts.conf containing :  myvhost1.org  myvhost2.org  myvhost3.org

3) Using the Linux /etc/hostname file:

If you comment no-hosts dnsmasq parameter , then the daemon read /etc/hostname file, then you can add each records into this hostname file :   myvhost1.org   myvhost2.org   myvhost3.org

Finally associate each hostnames in your apache2 vhosts conf files:

    ServerName myvhost1.org
    DocumentRoot "/www/domain/myvhost1"

    ServerName myvhost2.org
    DocumentRoot "/www/domain/myvhost2"

    ServerName myvhost3.org
    DocumentRoot "/www/domain/myvhost3"

And enable ALL vhosts and restart ALL daemons.

Note that the dns server for the client is normally specified in the dhcp configuration, if you use dnsmasq as the dhcp server you must specify the necessary dhcp option:


where is always your dns server (dnsmasq) listen address or else configure manually the client dns.

Somes steps:

# is the dnsmasq IPv4 listen address for the DNS server , else adapting... 
~$ ip a add dev wlan0
~$ ip a #ensure your interface have the dns server correct IPv4    

~$ sudo a2ensite myvhost1.conf
~$ sudo a2ensite myvhost2.conf
~$ sudo a2ensite myvhost3.conf     
~$ sudo systemctl reload apache2.service

~$ sudo systemctl reload dnsmasq.service
~$ nslookup myvhost1.org  # Must return a correct response :
~$ dig myvhost1.org @  # Must return a correct response :
~$ sudo cat /tmp/dnsmasq.queries.txt
~$ sudo cat /etc/hostname
~$ sudo cat /etc/resolv.conf
# Global
~$ sudo journalctl
~$ ss -ln #show listening addr and port

Be careful because here I use the temporary folder /tmp for the development and it is emptied at each restart by Linux so you will lose your log files or configuration. Adapt according to your needs. Also, I do not mean here any privilege or right on the folders and files, so be sure to do the necessary on this side.

  • Much taken effort but where does this answer a question about Raspberry Pi? I haven't found any word about Raspberry Pi.
    – Ingo
    May 25 '19 at 17:23
  • apache2 and dnsmasq run on raspberry , no ? he say: "I have a website running on apache"... I do not understand the meaning of your remark.
    – Ephemeral
    May 25 '19 at 17:46
  • Apache2 and dnsmasq run on many computer including Raspberry Pi. There are many other programs are running on Raspberry Pi. But only that they are running but having general problems doesn't say that's a specific problem for Raspberry Pi. Please have a look at our policies at How do I write a good answer?. There you will find "..avoid trying to answer questions which... are not about raspberry pi as defined in the help center".
    – Ingo
    May 25 '19 at 18:14
  • @Ingo, I see, yes is not really related to the raspberry-pi, exact...
    – Ephemeral
    May 25 '19 at 18:15
  • I delete this answer...
    – Ephemeral
    May 25 '19 at 18:15

You should be able to access the Pi with hostname.local - default hostname is raspberrypi.

Each device should have a unique hostname.


On the Raspi AP,

  • Setup a DNS server. I prefer bind. sudo apt-get install bind9
  • Create a zone for your site mywebsite.com
  • Create an A record such as www (resolving the raspi LAN IP) for your site.

It will be hard for you to complete the last 2 steps via command line. I suggest you to use a GUI for bind. Here, there are many alternatives.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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