The cloud images that we provide use cloud-init and DHCP to configure your instance network interfaces. There may be a situation where you want to disable cloud-init and/or DHCP and set your IP addresses statically. This can be accomplished a variety of ways. Feel free to use the configuration examples below as desired:
Example Netplan Configuration
- Log into your server.
- Get root:
sudo -i - Create a new cloud-init configuration file
/etc/cloud/cloud.cfg.d/99-disable-network-config.cfgwith contents:network: {config: disabled} - Edit
/etc/netplan/50-cloud-init.yaml. Remove thedhcp4anddhcp6lines and replace with:addresses:
- <your IPv4 address>/24
- "<your IPv6 address>/64"
nameservers:
addresses: [8.8.8.8, 8.8.4.4, 2001:4860:4860::8888, 2001:4860:4860::8844]
gateway4: <your IPv4 gateway>
gateway6: "<your IPv6 gateway>" - Apply your changes:
netplan apply(netplan tryto verify first) - Reboot to confirm cloud-init no longer configures networking (check for no new netplan file changes).
Other example configurations can be found on the Netplan website. DHCP (4 and 6) can be combined with static address configuration as well.
Example Interfaces Configuration (Debian)
- Log into your server.
- Create a new cloud-init configuration file
/etc/cloud/cloud.cfg.d/95-debian-network-config.cfgwith contents:network: {config: disabled} - Edit
/etc/network/interfaces.d/50-cloud-init.cfgand comment all lines related to eth0 (or any interface you want to statically configure). - Edit
/etc/network/interfaces. Replaceiface eth0 inet dhcpwith:iface eth0 inet staticaddress <your IPv4 address>/24gateway <your IPv4 gateway>
You can add IPv6 the same way:iface eth0 inet6 staticaddress <your IPv6 address>/64gateway <your IPv6 gateway> - Save and close the file. Then run
ifdown eth0;ifup eth0or reboot.
Example Sysconfig Configuration (CentOS 7)
- Log into your server.
- Replace the contents of
/etc/cloud/cloud.cfg.d/90-centos-networking.cfgwith:network: {config: disabled} - Replace the contents of
/etc/sysconfig/network-scripts/ifcfg-eth0with:BOOTPROTO=staticDEVICE=eth0ONBOOT=yesTYPE=EthernetIPADDR=<your IPv4 address>PREFIX=24GATEWAY=<your IPv4 gateway>IPV6ADDR=<your IPv6 address>/64IPV6_DEFAULTGW=<your IPv6 gateway> - Run the following commands to apply the changes:
systemctl disable dhclient6.serviceifdown eth0;ifup eth0(or reboot)
