I'm trying to invoke iptables-restore in a systemd.service script. I have several rules that require DNS lookup. I included After=bind9.service in the Unit section for the firewall. However, systemd thinks that bind9 is started when it forks, not when named is ready to serve requests. It kicks off the iptables-restore before it can resolve the hostname and therefore fails. Here is the pertinent section of the syslog:
Dec 13 21:29:02 fw systemd: Started BIND Domain Name Server. Dec 13 21:29:02 fw systemd: Reached target Host and Network Name Lookups. Dec 13 21:29:02 fw systemd: Starting Load iptables Rules... Dec 13 21:29:02 fw systemd: Started Homebridge HomeKit bridge. Dec 13 21:29:02 fw systemd: Starting OpenBSD Secure Shell server... Dec 13 21:29:02 fw sh: iptables-restore v1.6.0: host/network `example.com' not found Dec 13 21:29:02 fw sh: Error occurred at line: 24 Dec 13 21:29:02 fw sh: Try `iptables-restore -h' or 'iptables-restore --help' for more information. Dec 13 21:29:02 fw named: starting BIND 9.10.3-P4-Ubuntu <id:ebd72b3> -f -4 -u bind
Here's the service file:
[Unit] Description=Load iptables Rules After=bind9.service [Install] WantedBy=multi-user.target WantedBy=network-online.target [Service] Type=oneshot RemainAfterExit=yes ExecStart=/bin/sh -c "/sbin/iptables-restore < /etc/iptables.up.rules"
What is the best way to have the iptables-restore command execute on boot, but wait for named to be active?