diff --git a/.gitignore b/.gitignore
index 23f1148..3bfdebb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+src/dnsmasq.service
 src/*.o
 src/*.mo
 src/dnsmasq.pot
diff --git a/Makefile b/Makefile
index dd0513b..624047c 100644
--- a/Makefile
+++ b/Makefile
@@ -51,6 +51,8 @@ top!=pwd
 # GNU make way.
 top?=$(CURDIR)
 
+systemd_system_unit_dir = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_SYSTEMD $(PKG_CONFIG) --variable=systemdsystemunitdir systemd`
+dbus_sysconfdir = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --variable=sysconfdir dbus-1`
 dbus_cflags =   `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --cflags dbus-1` 
 dbus_libs =     `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --libs dbus-1` 
 idn_cflags =    `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --cflags libidn` 
@@ -84,7 +86,7 @@ all : $(BUILDDIR)
  top="$(top)" \
  build_cflags="$(version) $(dbus_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags)" \
  build_libs="$(dbus_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs)" \
- -f $(top)/Makefile dnsmasq 
+ -f $(top)/Makefile dnsmasq
 
 mostly_clean :
 	rm -f $(BUILDDIR)/*.mo $(BUILDDIR)/*.pot 
@@ -94,14 +96,21 @@ clean : mostly_clean
 	rm -f $(BUILDDIR)/dnsmasq_baseline
 	rm -f core */core
 	rm -f *~ contrib/*/*~ */*~
+	rm -f $(BUILDDIR)/dnsmasq.service
 
-install : all install-common
+install : all install-common install-dbus install-systemd
 
 install-common :
 	$(INSTALL) -d $(DESTDIR)$(BINDIR) -d $(DESTDIR)$(MANDIR)/man8
 	$(INSTALL) -m 644 $(MAN)/dnsmasq.8 $(DESTDIR)$(MANDIR)/man8 
 	$(INSTALL) -m 755 $(BUILDDIR)/dnsmasq $(DESTDIR)$(BINDIR)
 
+install-dbus :
+	if [ "x${dbus_sysconfdir}" != "x" ]; then $(INSTALL) $(top)/dbus/dnsmasq.conf -D $(DESTDIR)$(dbus_sysconfdir)/dbus-1/system.d/dnsmasq.conf ; fi
+
+install-systemd :
+	if [ "x${systemd_system_unit_dir}" != "x" ]; then $(INSTALL) $(BUILDDIR)/dnsmasq.service -D $(DESTDIR)$(systemd_system_unit_dir)/dnsmasq.service ; fi
+
 all-i18n : $(BUILDDIR)
 	@cd $(BUILDDIR) && $(MAKE) \
  top="$(top)" \
@@ -156,8 +165,8 @@ $(objs): $(copts_conf) $(hdrs)
 .c.o:
 	$(CC) $(CFLAGS) $(COPTS) $(i18n) $(build_cflags) $(RPM_OPT_FLAGS) -c $<	
 
-dnsmasq : $(objs)
-	$(CC) $(LDFLAGS) -o $@ $(objs) $(build_libs) $(LIBS) 
+dnsmasq : $(objs) dnsmasq.service
+	$(CC) $(LDFLAGS) -o $@ $(objs) $(build_libs) $(LIBS)
 
 dnsmasq.pot : $(objs:.o=.c) $(hdrs)
 	$(XGETTEXT) -d dnsmasq --foreign-user --omit-header --keyword=_ -o $@ -i $(objs:.o=.c)
@@ -165,4 +174,12 @@ dnsmasq.pot : $(objs:.o=.c) $(hdrs)
 %.mo : $(top)/$(PO)/%.po dnsmasq.pot
 	$(MSGMERGE) -o - $(top)/$(PO)/$*.po dnsmasq.pot | $(MSGFMT) -o $*.mo -
 
-.PHONY : all clean mostly_clean install install-common all-i18n install-i18n merge baseline bloatcheck
+dnsmasq.service :
+	sed \
+		$(top)/$(SRC)/dnsmasq.service.in \
+		-e "s|BusName=.*|`echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS echo '\0'`|" \
+		-e "s|\@dbusopts\@|`echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS echo '-1'`|" \
+		-e "s|\@bindir\@|$(BINDIR)|" \
+		 > $(top)/$(SRC)/dnsmasq.service
+
+.PHONY : all clean mostly_clean install install-common install-dbus install-systemd all-i18n install-i18n merge baseline bloatcheck
diff --git a/src/dnsmasq.service.in b/src/dnsmasq.service.in
new file mode 100644
index 0000000..54d3b18
--- /dev/null
+++ b/src/dnsmasq.service.in
@@ -0,0 +1,31 @@
+# It's not recommended to modify this file in-place, because it will be
+# overwritten during upgrades.  If you want to customize, the best
+# way is to create a file "/etc/systemd/system/dnsmasq.service",
+# containing
+#   .include /lib/systemd/system/dnsmasq.service
+#   ...make your changes here...
+# See https://www.freedesktop.org/software/systemd/man/systemd.service.html
+# for detailed information about available options.
+
+[Unit]
+Description=A lightweight DHCP and caching DNS server
+After=network.target
+
+[Service]
+BusName=uk.org.thekelleys.dnsmasq
+PIDFile=/run/dnsmasq/dnsmasq.pid
+ExecStartPre=@bindir@/dnsmasq --test
+ExecStart=@bindir@/dnsmasq @dbusopts@ -k -x /run/dnsmasq/dnsmasq.pid --user=dnsmasq --group=dnsmasq
+ExecReload=/bin/kill -HUP $MAINPID
+RuntimeDirectory=dnsmasq
+CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_ADMIN
+AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_ADMIN
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectSystem=full
+ProtectHome=yes
+NoNewPrivileges=yes
+
+[Install]
+WantedBy=multi-user.target
+
