Adding a second IP address on Debian with Netplan involves editing the Netplan configuration file. Here are the steps for this process:
Check for the Existence of a Network Interface
Ensure that you have a network interface installed, such as eth0. You can check this using the following command:
ifconfig
Look for the line corresponding to your network interface.
Backup the Netplan Configuration File
It's a good practice to create a backup of the current Netplan configuration. You can do this by copying the configuration file:
sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak
Edit the Netplan Configuration File
Open the Netplan configuration file for editing. For example, use the nano text editor:
sudo nano /etc/netplan/01-netcfg.yaml
Add the Second IP
Add a new address block for the second IP address. For instance, if you want to add the IP address 192.168.1.3:
network:
version: 2
ethernets:
eth0:
addresses:
- 192.168.1.2/24
- 192.168.1.3/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
Ensure to specify the correct interface (eth0), IP addresses, subnet mask, gateway, and DNS settings.
Apply the Netplan Configuration
Apply the changes made to the Netplan configuration:
sudo netplan apply
Check the New IP
Verify whether the second IP address has been added using the ifconfig or ip addr command:
ifconfig
or
ip addr
You should see the additional IP address associated with your network interface.
Prevent cloud-init from Modifying Network Settings
To avoid interference from cloud-init, which may alter network settings, follow the instructions on this page to restrict cloud-init from making network configuration changes.
