How to add a static secondary IP to a DHCP interface using netplan?
It's actually way easier, you just add dhcp4: true
to your static configuration like this (and disable v6 if you don't need it):
network:
version: 2
ethernets:
ens3:
dhcp4: yes
dhcp6: no
addresses:
- 10.0.0.250/24
Answered on Ask Ubuntu
Copy:
The solution was quite simple, just set a static IP address and enable DHCP. Basically you just have to add dhcp4: yes
to your configuration.
This configuration gave me a primary static IP address and a secondary DHCP assigned IP address:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
dhcp6: no
addresses:
- 10.1.2.15/24
gateway4: 10.1.2.1
nameservers:
search:
- example.com
addresses: [10.1.2.10]
The result of ip address show enp0s3 gave me:
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:ab:cd:ef brd ff:ff:ff:ff:ff:ff
inet 10.1.2.15/24 brd 10.0.1.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet 10.1.2.96/24 brd 10.0.1.255 scope global secondary dynamic enp0s3
valid_lft 3224sec preferred_lft 3224sec
inet6 fe80::a00:27ff:fe20:2c40/64 scope link
valid_lft forever preferred_lft forever
The address 10.1.2.96 is the secondary DHCP assigned address as indicated by the secondary dynamic keywords.