0% found this document useful (0 votes)
8 views5 pages

Setting Up Apache and DNS On Ubuntu (Step-by-Step)

This document provides a step-by-step guide for setting up Apache and DNS on Ubuntu, including assigning static IPs, installing Apache and BIND9, and configuring DNS records. It details the necessary commands and configurations for both the web server and DNS server, ensuring they are on the same subnet and can communicate. Finally, it explains how to verify the setup by testing DNS resolution and accessing the web server through a browser.

Uploaded by

jebbari.marouane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Setting Up Apache and DNS On Ubuntu (Step-by-Step)

This document provides a step-by-step guide for setting up Apache and DNS on Ubuntu, including assigning static IPs, installing Apache and BIND9, and configuring DNS records. It details the necessary commands and configurations for both the web server and DNS server, ensuring they are on the same subnet and can communicate. Finally, it explains how to verify the setup by testing DNS resolution and accessing the web server through a browser.

Uploaded by

jebbari.marouane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Setting up Apache and DNS on Ubuntu (Step-by-

Step)
1. Assign Static IPs on Servers
On both the web server and the DNS server, configure a static IP on the same subnet (e.g. 10.10.10.0/24).
Edit the netplan config (e.g. /etc/netplan/00-installer-config.yaml or a new file) and set the
desired address, gateway, and DNS. For example, on the web server (10.10.10.7):

network:
version: 2
renderer: networkd
ethernets:
eth0: # replace with your interface name
addresses: [10.10.10.7/24]
gateway4: 10.10.10.1
nameservers:
addresses: [10.10.10.6] # local DNS server as resolver

And on the DNS server (10.10.10.6) similarly:

network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses: [10.10.10.6/24]
gateway4: 10.10.10.1
nameservers:
addresses: [10.10.10.6]

After editing, apply the settings:

sudo netplan apply

This configures each machine with its static IP and makes 10.10.10.6 the DNS resolver (you can also point
DNS to another resolver if needed). The format follows Ubuntu’s netplan examples 1 . Verify connectivity
(e.g. ping 10.10.10.6 and ping 10.10.10.7 ) to ensure both are on the same subnet and reachable.

1
2. Install and Test Apache on the Web Server
On the web server (10.10.10.7), update apt and install Apache2:

sudo apt update


sudo apt install -y apache2

This installs the latest Apache ( apache2 meta-package) 2 . By default, Apache serves content from /
var/www/html . Enable and start Apache:

sudo systemctl enable --now apache2

If a firewall is enabled, allow HTTP/S (for example, sudo ufw allow 'Apache' ). Test Apache by
navigating (from any client) to the server’s IP address or http://10.10.10.7 ; you should see the Apache
default page. The default site config and docroot are in /etc/apache2/sites-enabled/000-
default.conf and /var/www/html 3 . You can replace the index.html in /var/www/html/ with
your own content if desired.

3. Install and Configure BIND9 DNS Server


On the DNS server (10.10.10.6), install BIND9:

sudo apt update


sudo apt install -y bind9 bind9utils bind9-doc

This installs BIND9 and related utilities. Make sure BIND is listening on the correct interface (by default it
listens on all interfaces).

Edit /etc/bind/named.conf.local to define your new zone dns.local as a master zone. For
example:

sudo nano /etc/bind/named.conf.local

Add:

zone "dns.local" {
type master;
file "/etc/bind/zones/db.dns.local";
};

2
This tells BIND that it is authoritative for dns.local and the records are in /etc/bind/zones/
db.dns.local 4 .

Now create the zone file. First make the zones directory and copy a template:

sudo mkdir -p /etc/bind/zones


sudo cp /etc/bind/db.local /etc/bind/zones/db.dns.local
sudo nano /etc/bind/zones/db.dns.local

Edit the file so it defines the SOA, NS, and the desired A records. For example:

$TTL 604800
@ IN SOA dns.local. root.dns.local. (
1 ; serial (increment on changes)
604800 ; refresh
86400 ; retry
2419200 ; expire
604800 ; negative cache TTL
)
@ IN NS ns.dns.local. ; name server for the zone
ns IN A 10.10.10.6 ; bind9 server itself
www IN A 10.10.10.7 ; web server

In this example, ns.dns.local is used as the nameserver (pointing to 10.10.10.6), and www.dns.local
points to 10.10.10.7. (Ensure the @ IN NS target ends with a . and increment the serial whenever you
change the file.) This format (NS and A records) follows the usual BIND zone syntax 5 . Save the file.

Check the BIND configuration and zone syntax, then restart:

sudo named-checkconf
sudo named-checkzone dns.local /etc/bind/zones/db.dns.local
sudo systemctl restart bind9

This reloads BIND with your new zone. If UFW is running, allow DNS traffic:

sudo ufw allow 53/tcp


sudo ufw allow 53/udp

(or simply sudo ufw allow Bind9 on Ubuntu) 6 . Now the DNS server is authoritative for
dns.local .

3
4. Add DNS Record for www.dns.local
The www.dns.local record has already been added in the zone file above. (If you need more
subdomains, just add additional A records in /etc/bind/zones/db.dns.local in the same way,
incrementing the serial.) For example, the snippet above ensures that a DNS query for www.dns.local
will resolve to 10.10.10.7, the Apache server’s IP.

If you change the zone file later, remember to bump the serial in the SOA line and reload BIND ( sudo
systemctl reload bind9 ).

5. Configure DNS on the Client and Verify


On any client machine (on the same network) that will browse the site, configure it to use the local DNS
server (10.10.10.6). For Ubuntu clients, you can do this via netplan or systemd-resolved:

• Netplan method: Edit (or create) a netplan file under /etc/netplan/ and add the DNS server
under nameservers . For example:

network:
version: 2
ethernets:
eth0: # replace with the client’s interface
addresses: [10.10.10.100/24] # example client IP
gateway4: 10.10.10.1
nameservers:
addresses: [10.10.10.6]

Then run sudo netplan apply .

• systemd-resolved method: Edit /etc/systemd/resolved.conf and set under [Resolve] :

DNS=10.10.10.6

Save and restart the resolver: sudo systemctl restart systemd-resolved . You may also
verify by checking /etc/resolv.conf (often a symlink to systemd’s stub resolver) contains the
new server. In general, Ubuntu’s resolv.conf is managed by systemd-resolved 7 .

After setting the DNS, test it on the client. For example:

dig @10.10.10.6 www.dns.local

4
or simply ping www.dns.local . It should resolve to 10.10.10.7 . Finally, open a browser or use
curl to access the web site:

curl http://www.dns.local

You should see the Apache default page (the same content as http://10.10.10.7). This confirms that DNS is
correctly resolving the name to your web server and that Apache is serving the page 8 . All steps
complete, you have a working Apache site at www.dns.local with local DNS resolution.

Sources: Configuration examples are based on Ubuntu’s netplan and BIND documentation 1 5 and
tutorials 2 9 .

1 7 Configuring networks - Ubuntu Server documentation


https://documentation.ubuntu.com/server/explanation/networking/configuring-networks/

2 3 8 Install and Configure Apache | Ubuntu


https://ubuntu.com/tutorials/install-and-configure-apache

4 5 BIND9ServerHowto - Community Help Wiki


https://help.ubuntu.com/community/BIND9ServerHowto

6 9 How To Configure BIND as a Private Network DNS Server on Ubuntu 22.04 | DigitalOcean
https://www.digitalocean.com/community/tutorials/how-to-configure-bind-as-a-private-network-dns-server-on-ubuntu-22-04

You might also like