This issue gave me a lot of trouble.
It is for CentOS 7.
First of all:
nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
By opening the file, we prevent it from automatically writing to the resolv.conf file.
Inside the file;
network:
config: disabled
Add this and save with Ctrl + X and then Y.
Then
/etc/sysconfig/network-scripts/ifcfg-eth0
We open the file above with nano and edit it again by writing your own IP in the place I made bold.
BOOTPROTO=static
DEVICE=eth0
DEFROUTE=yes
HWADDR=96:00:01:55:ce:3d
ONBOOT=yes
IPADDR=**sabitipadresiniz**
NETMASK=255.255.255.255
GATEWAY=172.31.1.1
DNS1=185.12.64.1
DNS2=185.12.64.2
TYPE=Ethernet
USERCTL=no
Then
we run the following 3 commands respectively.
cp /etc/host.conf /etc/sysconfig/network-scripts/route-eth0
perl -pi -e s/multi\\ on/172.31.1.1\\\\/32\\ dev\\ eth0\\\\ndefault\\ via\\ 172.31.1.1\\ dev\\ eth0/g /etc/sysconfig/network-scripts/route-eth0
service network restart
If we need to disable IPv6, we also disable IPv6 with the command below.
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
The resolv.conf I used for Hetzner Cloud CentOS 7 is below.
nameserver 185.12.64.1
nameserver 185.12.64.2
nameserver 1.1.1.1