微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux – 将IP地址传递给cloud-init元数据

我正在寻找一种将ip-address传递给cloud-init元数据的方法.因此,当我的qcow启动时,它不必等待120 – 180秒启动.

目前,我已经通过将IP地址信息添加到cloud-init的userdata部分来创建了一种解决方法.问题是,它确实需要一些时间,因为cloud-init userdata仅在引导VM后执行.

echo -e "
# This file describes the network interfaces available on your system
# and how to activate them. For more @R_847_4045@ion, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
\taddress $address
\tnetmask $netmask
\tgateway $gateway
\tdns-nameservers $dnsnameservers
" > /etc/network/interfaces

ifdown eth0; ifup eth0

目前要在cloud-init元数据中设置主机名,我已经获得了这个部分:

cat > $config_dir/Meta-data <<-EOF
instance-id: $uuid
hostname: $hostname
local-hostname: $hostname
EOF

但我需要更扎实,更具体的东西,因为cloud-init文档非常模糊

编辑:我已经看到它是可能的,因为Openstack可以做到这一点.

解决方法:

可以使用以下格式:

network-interfaces: |
  auto lo
  iface lo inet loopback

  iface eth0 inet static
    address xxx.xxx.xxx.xxx (static ip)
    netmask xxx.xxx.xxx.xxx
    gateway xxx.xxx.xxx.xxx (gateway ip, usually ip address of router)

您基本上写出了您希望接口具有的配置,因为只要您具有“network-interfaces:|”,接口文件就会显示出来.

希望这能回答你的问题!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐