Debian 8 and 9 use
systemd as the default init system, so the commands needed to disable the GUI interface immediately & persistently are:
systemctl set-default multi-user.target
systemctl isolate multi-user.target
The first command sets the text mode as the new default system state (so it will take effect on next and subsequent boots), and the second command enforces the new state immediately.
To re-enable graphics mode, respectively:
systemctl set-default graphical.target
systemctl isolate graphical.target
If you've opted to use the classic SysVinit instead, you'll need to do something like
update-rc.d -f gdm remove ; update-rc.d gdm stop 99 1 2 3 4 5 6. Replace gdm with whatever display manager you're using: Debian has had at least
sddm. Unlike most other distributions, Debian did not separate runlevel 3 for text mode and 5 for GUI mode.