问题原文
原帖链接 · Torsten Bronger · CC BY-SA 4.0
My server has a file /etc/netplan/50-cloud-init.yaml with the following content:
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
ens3:
dhcp4: true
match:
macaddress: fa:**:**:**:**:**
set-name: ens3
This results in the following interface configuration:
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc fq_codel state UP group default qlen 1000
link/ether fa:**:**:**:**:** brd ff:ff:ff:ff:ff:ff
inet 10.0.0.5/24 brd 10.0.0.255 scope global dynamic ens3
...
So far, so good. But now I need to add 10.0.0.250 as an additional secondary static IP to this interface. What is the best way to do that? I created a new file /etc/netplan/60-service-ip.yaml with:
network:
version: 2
ethernets:
ens3:
addresses:
- 10.0.0.5/24
- 10.0.0.250/24
This seems to work, but it re-defines a dynamic IP as a static one.
社区高分解答
原帖链接 · Insan · CC BY-SA 4.0
I had a same issue where I have dhcp address as secondary and static as primary in Azure. Leaving dhcp address as primary is important because Azure virtual network provides gateway and nameserver information.
I found this workaround:
network:
version: 2
ethernets:
eth0:
dhcp4: true
addresses:
- 10.0.2.6/24 (IP acquired by DHCP)
- 10.0.2.21/24
match:
macaddress: 00:0d:3a:4f:45:f0
set-name: eth0
In Azure specifically, we assign static ip address on Azure Resource side and normally this is taken to Guest OS by dhcp.
Therefore, even though guest os treats it as a dynamic ip, it will always get same static ip from Azure.
Above, I forced to put dhcp IP ahead of secondary IP.
In my case, it worked as expected.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
