NOTICE: This article only talks about VPS. Assume you only have one network named eth0
.
If you want to add IP addresses on your Debian servers, there is a big bug.
Usually, we go to modify /etc/network/interfaces.d/50-cloud-init
file and then go to restart it by /etc/init.d/networking restart
or systemctl restart networking
. But you may find that it’s always to be failed on the screen. Editing the config file and restarting it is useless.
Why? I guess the VPS servers have its own genuine configs so that there are some conflicts. The worst is that the conflicts seem permanent and you even lose your IPv6 connections at all (maybe the IPv4 address still works, or you need to reinstall the system).
How to solve it?
First of all, use this command
ip address
to see the IP address config on your VPS. If you find that even though you have deleted the IP address in config file and have restarted the service, you still see the deprecated IP address, that’s it.
Then, modify the 50-cloud-init file using
nano /etc/network/interfaces.d/50-cloud-init
what you see is like the example file below:
auto lo
iface lo inet loopback
dns-nameservers *.*.*.*
auto eth0
iface eth0 inet static
address *.*.*.*/22
gateway *.*.*.*
iface eth0 inet6 static
address *:*::*:*/64
gateway *:*::*
delete everything except auto lo
field, like this:
# only keep "auto lo" field
auto lo
iface lo inet loopback
dns-nameservers *.*.*.*
Then
reboot
After rebooting, you’ll find the network has been reset as VPS provider’s default.
If you still want to add new IP address, just modify the config file again, only write new IP address config and reboot as soon as done. Don’t use systemctl restart networking
. After rebooting, the new IP address will take effect.
File sample is like this:
auto lo
iface lo inet loopback
dns-nameservers *.*.*.*
# put new IP address directly and reboot
auto eth0
iface eth0 inet6 static
address *:*::*:*/64
gateway *:*::*
If you don’t know how to write the config file, here are some references:
https://docs.ovh.com/gb/en/vps/configuring-ipv6/
https://docs.ovh.com/ca/en/dedicated/network-ipaliasing/
Conclusion
- Delete all the default IP address config written by VPS providers in the config file. Only keep the
auto lo
field and what you want to add. - Only use reboot, not network restart command.
Honestly to say, I think Ubuntu 18.04 or higher using netplan as default to manage network settings is a better solution.