参考(https://coreos.com/os/docs/lat ... d.html)文件的这段networkd and DHCP behavior,原文提到
> By default, even if you've already set a static IP address and you have a working DHCP server in your network, systemd-networkd will nevertheless assign IP address using DHCP. If you would like to remove this address, you have to use the following cloud-config example:
大致说如果你的网路环境下有DHCP服务器,即使你手动设置的静态ip地址,那systemd-networkd还是先用DHCP分发的ip地址. 这是个坑呀!!!
这是我安装coreos的cloud-init.yaml档案的截取内容
以下过程执行了
<ol><li>先停止systemd-networkd</li><li>利用00-enp0s3.network配置一个静态ip</li><li>down-interfaces.service用来重置网卡设备</li><li>再重新启动systemd-networkd</li></ol>
<pre>
units:
- name: "systemd-networkd.service"
command: "stop"
- name: "00-enp0s3.network"
runtime: true
content: |
Name=enp0s3 #确认自己的网卡名称
DNS=192.168.31.1 #自行修改
Address=192.168.31.244/24 #修改成你的
Gateway=192.168.31.1 #自行修改
- name: "down-interfaces.service"
command: "start"
content: |
Type=oneshot
ExecStart=/usr/bin/ip link set enp0s3 down #确认自己的网卡名称
ExecStart=/usr/bin/ip addr flush dev enp0s3 #确认自己的网卡名称
- name: "systemd-networkd.service"
command: "restart"
</pre>
期望能帮到你,如有不正确之处也请订正