我想看看是否有表达网络配置的语言。我可以使用M4和YAML对一些配置进行宏观操作,但是使用条件语句,它们似乎会崩溃。
有什么建议吗?
谢谢, 尼尔
答案 0 :(得分:0)
我的NCD programming language可能正是您所寻找的。 p>
以下是使用DHCP配置有线网络接口的示例程序(与wiki相同):
process lan {
# Set device.
var("eth0") dev;
# Wait for device, set it up, and wait for network cable.
net.backend.waitdevice(dev);
net.up(dev);
net.backend.waitlink(dev);
# DHCP configuration.
# net.ipv4.dhcp() will block here until it obtaines an IP address.
# Note that it will only obtain the IP address, and *not* assign it;
# we do that with a separate command below.
net.ipv4.dhcp(dev) dhcp;
# Check IP address - make sure it's not local.
# If you have other reserved subnets around, check for those too.
ip_in_network(dhcp.addr, "127.0.0.0", "8") test_local;
ifnot(test_local);
# Assign IP address, as obtained by DHCP.
net.ipv4.addr(dev, dhcp.addr, dhcp.prefix);
# Add default route, as obtained by DHCP.
net.ipv4.route("0.0.0.0", "0", dhcp.gateway, "20", dev);
# Configure DNS servers, as obtained by DHCP.
net.dns(dhcp.dns_servers, "20");
}
请务必阅读整个NCD维基页面。 NCD的能力远远超过它最初的样子(例如,条件,循环,未知设备的动态配置......)。它甚至可以执行一些与网络无关的任务,例如报告输入设备(键盘,鼠标)事件。