4 # Required-Start: $network $remote_fs $syslog
5 # Required-Stop: $network $remote_fs $syslog
6 # Default-Start: 2 3 4 5
8 # Description: DHCP and DNS server
11 set +e
# Don't exit on error status
13 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/bin
:/usr
/sbin
:/usr
/bin
14 DAEMON
=/usr
/sbin
/dnsmasq
16 DESC
="DNS forwarder and DHCP server"
18 # Most configuration options in /etc/default/dnsmasq are deprecated
21 if [ -r /etc
/default
/$NAME ]; then
25 # Get the system locale, so that messages are in the correct language, and the
26 # charset for IDN is correct
27 if [ -r /etc
/default
/locale
]; then
32 # /etc/dnsmasq.d/README is a non-conffile installed by the dnsmasq package.
33 # Should the dnsmasq package be removed, the following test ensures that
34 # the daemon is no longer started, even if the dnsmasq-base package is
36 test -e /etc
/dnsmasq.d
/README ||
exit 0
38 test -x $DAEMON ||
exit 0
40 # Provide skeleton LSB log functions for backports which don't have LSB functions.
41 if [ -f /lib
/lsb
/init-functions
]; then
42 .
/lib
/lsb
/init-functions
59 elif [ $1 -eq 255 ]; then
60 /bin
/echo -e " (warning)."
62 /bin
/echo -e " failed!"
68 # If the resolvconf package is installed then use the resolv conf file
69 # that it provides as the default. Otherwise use /etc/resolv.conf as
72 # If IGNORE_RESOLVCONF is set in /etc/default/dnsmasq or an explicit
73 # filename is set there then this inhibits the use of the resolvconf-provided
76 # Note that if the resolvconf package is installed it is not possible to
77 # override it just by configuration in /etc/dnsmasq.conf, it is necessary
78 # to set IGNORE_RESOLVCONF=yes in /etc/default/dnsmasq.
80 if [ ! "$RESOLV_CONF" ] &&
81 [ "$IGNORE_RESOLVCONF" != "yes" ] &&
82 [ -x /sbin
/resolvconf
]
84 RESOLV_CONF
=/var
/run
/dnsmasq
/resolv.conf
87 for INTERFACE
in $DNSMASQ_INTERFACE; do
88 DNSMASQ_INTERFACES
="$DNSMASQ_INTERFACES -i $INTERFACE"
91 for INTERFACE
in $DNSMASQ_EXCEPT; do
92 DNSMASQ_INTERFACES
="$DNSMASQ_INTERFACES -I $INTERFACE"
95 if [ ! "$DNSMASQ_USER" ]; then
96 DNSMASQ_USER
="dnsmasq"
99 # This tells dnsmasq to ignore DNS requests that don't come from a local network.
100 # It's automatically ignored if --interface --except-interface, --listen-address
101 # or --auth-server exist in the configuration, so for most installations, it will
102 # have no effect, but for otherwise-unconfigured installations, it stops dnsmasq
103 # from being vulnerable to DNS-reflection attacks.
105 DNSMASQ_OPTS
="$DNSMASQ_OPTS --local-service"
110 # 0 if daemon has been started
111 # 1 if daemon was already running
112 # 2 if daemon could not be started
114 # /var/run may be volatile, so we need to ensure that
115 # /var/run/dnsmasq exists here as well as in postinst
116 if [ ! -d /var
/run
/dnsmasq
]; then
117 mkdir
/var
/run
/dnsmasq ||
return 2
118 chown dnsmasq
:nogroup
/var
/run
/dnsmasq ||
return 2
121 start-stop-daemon
--start --quiet --pidfile /var
/run
/dnsmasq
/$NAME.pid
--exec $DAEMON --test > /dev
/null ||
return 1
122 start-stop-daemon
--start --quiet --pidfile /var
/run
/dnsmasq
/$NAME.pid
--exec $DAEMON -- \
123 -x /var
/run
/dnsmasq
/$NAME.pid \
124 ${MAILHOSTNAME:+ -m $MAILHOSTNAME} \
125 ${MAILTARGET:+ -t $MAILTARGET} \
126 ${DNSMASQ_USER:+ -u $DNSMASQ_USER} \
127 ${DNSMASQ_INTERFACES:+ $DNSMASQ_INTERFACES} \
128 ${DHCP_LEASE:+ -l $DHCP_LEASE} \
129 ${DOMAIN_SUFFIX:+ -s $DOMAIN_SUFFIX} \
130 ${RESOLV_CONF:+ -r $RESOLV_CONF} \
131 ${CACHESIZE:+ -c $CACHESIZE} \
132 ${CONFIG_DIR:+ -7 $CONFIG_DIR} \
133 ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} \
139 # If interface "lo" is explicitly disabled in /etc/default/dnsmasq
140 # Then dnsmasq won't be providing local DNS, so don't add it to
141 # the resolvconf server set.
142 for interface
in $DNSMASQ_EXCEPT
144 [ $interface = lo
] && return
147 if [ -x /sbin
/resolvconf
] ; then
148 echo "nameserver 127.0.0.1" |
/sbin
/resolvconf
-a lo.
$NAME
156 # 0 if daemon has been stopped
157 # 1 if daemon was already stopped
158 # 2 if daemon could not be stopped
159 # other if a failure occurred
160 start-stop-daemon
--stop --quiet --retry=TERM
/30/KILL
/5 --pidfile /var
/run
/dnsmasq
/$NAME.pid
--name $NAME
165 if [ -x /sbin
/resolvconf
] ; then
166 /sbin
/resolvconf
-d lo.
$NAME
174 # 0 if daemon is running
175 # 1 if daemon is dead and pid file exists
176 # 3 if daemon is not running
177 # 4 if daemon status is unknown
178 start-stop-daemon
--start --quiet --pidfile /var
/run
/dnsmasq
/$NAME.pid
--exec $DAEMON --test > /dev
/null
180 0) [ -e "/var/run/dnsmasq/$NAME.pid" ] && return 1 ; return 3 ;;
188 test "$ENABLED" != "0" ||
exit 0
189 log_daemon_msg
"Starting $DESC" "$NAME"
198 log_success_msg
"(already running)"
209 if [ "$ENABLED" != "0" ]; then
210 log_daemon_msg
"Stopping $DESC" "$NAME"
214 if [ "$ENABLED" = "0" ]; then
216 0) log_daemon_msg
"Stopping $DESC" "$NAME"; log_end_msg
0 ;;
221 0) log_end_msg
0 ; exit 0 ;;
222 1) log_warning_msg
"(not running)" ; exit 0 ;;
223 *) log_end_msg
1; exit 1 ;;
226 restart|force-reload
)
227 test "$ENABLED" != "0" ||
exit 1
228 $DAEMON --test ${CONFIG_DIR:+ -7 $CONFIG_DIR} ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} >/dev
/null
2>&1
229 if [ $?
-ne 0 ]; then
230 NAME
="configuration syntax check"
237 log_daemon_msg
"Restarting $DESC" "$NAME"
261 log_daemon_msg
"Checking $DESC" "$NAME"
264 0) log_success_msg
"(running)" ; exit 0 ;;
265 1) log_success_msg
"(dead, pid file exists)" ; exit 1 ;;
266 3) log_success_msg
"(not running)" ; exit 3 ;;
267 *) log_success_msg
"(unknown)" ; exit 4 ;;
271 kill -s USR1
`cat /var/run/dnsmasq/$NAME.pid`
273 systemd-start-resolvconf
)
276 systemd-stop-resolvconf
)
280 # /var/run may be volatile, so we need to ensure that
281 # /var/run/dnsmasq exists here as well as in postinst
282 if [ ! -d /var
/run
/dnsmasq
]; then
283 mkdir
/var
/run
/dnsmasq ||
return 2
284 chown dnsmasq
:nogroup
/var
/run
/dnsmasq ||
return 2
286 exec $DAEMON -x /var
/run
/dnsmasq
/$NAME.pid \
287 ${MAILHOSTNAME:+ -m $MAILHOSTNAME} \
288 ${MAILTARGET:+ -t $MAILTARGET} \
289 ${DNSMASQ_USER:+ -u $DNSMASQ_USER} \
290 ${DNSMASQ_INTERFACES:+ $DNSMASQ_INTERFACES} \
291 ${DHCP_LEASE:+ -l $DHCP_LEASE} \
292 ${DOMAIN_SUFFIX:+ -s $DOMAIN_SUFFIX} \
293 ${RESOLV_CONF:+ -r $RESOLV_CONF} \
294 ${CACHESIZE:+ -c $CACHESIZE} \
295 ${CONFIG_DIR:+ -7 $CONFIG_DIR} \
296 ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}
299 echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|dump-stats|status}" >&2