Debian servers traditionally configure networking with ifupdown and the file /etc/network/interfaces. (Ubuntu uses netplan, and RHEL-family systems use NetworkManager.) The format is simple and readable, but a mistake can take the server offline, so on a VPS, edit it with a fallback ready.
Safety first: keep the VNC console of your VPS control panel open while changing network settings, or schedule an automatic revert with at. See VPS VNC console and at command.
Check what you’re using
ls /etc/network/interfaces /etc/network/interfaces.d/ 2>/dev/null
systemctl is-active networking systemd-networkd NetworkManager 2>/dev/null
ip addr; ip route
On some cloud images, cloud-init writes the network config into /etc/network/interfaces.d/50-cloud-init. Edit the file that’s actually in use. To stop cloud-init from overwriting your changes, see the note at the end.
A static IPv4 configuration
# /etc/network/interfaces
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 203.0.113.10/24
gateway 203.0.113.1
dns-nameservers 1.1.1.1 9.9.9.9
auto eth0: bring the interface up at boot.addresswith a prefix length (/24), or separateaddressandnetmasklines.dns-nameserversworks when theresolvconfpackage is installed. Otherwise, set DNS in/etc/resolv.conf.
Use the exact values from your VPS client area. Check the interface name with ip link (it may be ens3, enp1s0 or eth0).
DHCP instead:
auto eth0
iface eth0 inet dhcp
Add extra IP addresses
For multi-IP plans, add more address lines to the same stanza (ifupdown2, or recent ifupdown), or use an additional stanza:
auto eth0
iface eth0 inet static
address 203.0.113.10/24
gateway 203.0.113.1
iface eth0 inet static
address 203.0.113.11/24
Legacy alias syntax (eth0:1) also still works. See VPS IP addresses and multi-IP VPS.
Apply changes safely
sudo ifdown eth0 && sudo ifup eth0 # run both in ONE command over SSH
# or
sudo systemctl restart networking
Running ifdown alone over SSH disconnects you before ifup can run. Chaining with && (or using nohup / at) avoids that. Even safer: test with an automatic rollback:
sudo cp /etc/network/interfaces /root/interfaces.bak
echo "cp /root/interfaces.bak /etc/network/interfaces && systemctl restart networking" | sudo at now + 5 minutes
sudo systemctl restart networking
# if you can still connect in a new SSH session:
sudo atrm $(atq | tail -1 | cut -f1)
Verify
ip -4 addr show eth0
ip route
ping -c3 1.1.1.1
getent hosts debian.org
Troubleshooting
| Problem | Check |
|---|---|
| Interface doesn’t come up at boot | Missing auto eth0 line |
| “RTNETLINK answers: File exists” | Address or route already set. ip addr flush dev eth0, then ifup (from the console) |
| No DNS | resolvconf not installed: edit /etc/resolv.conf, or install it |
| Wrong interface name | ip link. Names like ens3 are predictable names |
| Changes lost after reboot | cloud-init regenerates the config |
Logs: journalctl -u networking.
cloud-init note
If cloud-init manages networking on your image, it may rewrite the configuration at boot. To keep manual changes, create /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg containing network: {config: disabled}. See cloud-init explained.
ifupdown, ifupdown2 or systemd-networkd?
Debian ships classic ifupdown by default. ifupdown2 (used by Proxmox, among others) reads the same file format, and adds features such as multiple address lines and ifreload -a to apply changes without taking interfaces down. systemd-networkd is an alternative that uses .network files in /etc/systemd/network/. All three work. Just make sure only one of them manages each interface, or they’ll fight over the configuration.
Quick reference
| Task | How |
|---|---|
| Config file | /etc/network/interfaces (+ interfaces.d/) |
| Static IP | iface eth0 inet static + address, gateway |
| DNS | dns-nameservers (with resolvconf) |
| Apply | ifdown eth0 && ifup eth0 (one command) |
| Safe test | at rollback job |
Related: nmcli (NetworkManager) and Debian VPS.