network.ncd 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # An example NCD script for network configuration.
  2. #
  3. # The first three processes demonstrate different kinds of interfaces
  4. # and configurations. They are all disabled by default.
  5. #
  6. # The last process waits for one of the interfaces to come up
  7. # and sets up routes and DNS entries to use that interface for
  8. # Internet access.
  9. #
  10. # Be sure to change the dependency list in the last process to name
  11. # the interfaces you use.
  12. # Example wired interface with static configuration.
  13. process wired_example_static {
  14. if("false"); # remove/comment to enable
  15. # Set device.
  16. var("eth0") dev;
  17. # Wait for device.
  18. net.backend.waitdevice(dev);
  19. net.up(dev);
  20. net.backend.waitlink(dev);
  21. # Static configuration.
  22. var("192.168.111.116") addr;
  23. var("24") addr_prefix;
  24. var("192.168.111.1") gateway;
  25. var({"192.168.111.14", "193.2.1.66"}) dns_servers;
  26. # Assign IP address.
  27. net.ipv4.addr(dev, addr, addr_prefix);
  28. # Go on configuring the network.
  29. concat("NET-", dev) provide_name;
  30. multiprovide(provide_name);
  31. }
  32. # Example wired interface with DHCP configuration.
  33. process wired_example_dhcp {
  34. if("false"); # remove/comment to enable
  35. # Set device.
  36. var("eth1") dev;
  37. # Wait for device.
  38. net.backend.waitdevice(dev);
  39. net.up(dev);
  40. net.backend.waitlink(dev);
  41. # DHCP configuration.
  42. net.ipv4.dhcp(dev) dhcp;
  43. ip_in_network(dhcp.addr, "127.0.0.0", "8") test_local;
  44. ifnot(test_local);
  45. var(dhcp.addr) addr;
  46. var(dhcp.prefix) addr_prefix;
  47. var(dhcp.gateway) gateway;
  48. var(dhcp.dns_servers) dns_servers;
  49. # Assign IP address.
  50. net.ipv4.addr(dev, addr, addr_prefix);
  51. # Go on configuring the network.
  52. concat("NET-", dev) provide_name;
  53. multiprovide(provide_name);
  54. }
  55. # Example wireless interface with DHCP configuration.
  56. # This will use the wpa_supplicant configuration file /etc/wpa_supplicant/all.conf
  57. # which should specify the wireless networks and other options.
  58. process wireless_example_dhcp {
  59. if("false"); # remove/comment to enable
  60. # Set device.
  61. var("wlan0") dev;
  62. # Wait for device and rfkill.
  63. net.backend.waitdevice(dev);
  64. net.backend.rfkill("wlan", dev);
  65. # Connect to wireless network.
  66. net.backend.wpa_supplicant(dev, "/etc/wpa_supplicant/all.conf", "/usr/sbin/wpa_supplicant", {});
  67. # DHCP configuration.
  68. net.ipv4.dhcp(dev) dhcp;
  69. ip_in_network(dhcp.addr, "127.0.0.0", "8") test_local;
  70. ifnot(test_local);
  71. var(dhcp.addr) addr;
  72. var(dhcp.prefix) addr_prefix;
  73. var(dhcp.gateway) gateway;
  74. var(dhcp.dns_servers) dns_servers;
  75. # Assign IP address.
  76. net.ipv4.addr(dev, addr, addr_prefix);
  77. # Go on configuring the network.
  78. concat("NET-", dev) provide_name;
  79. multiprovide(provide_name);
  80. }
  81. # This process sets up routes and DNS servers for at most one of
  82. # the working interfaces. It will change the configuration of a more
  83. # important interface comes up after one is already up.
  84. process NETCONF {
  85. # Choose devices and priorities; put preferred devices to the front.
  86. var({"NET-eth0", "NET-eth1", "NET-wlan0"}) provide_names;
  87. # Wait for one of the interfaces (and deinit/switch appropriately).
  88. multidepend(provide_names) ifdep;
  89. # Alias device values.
  90. var(ifdep.dev) dev;
  91. var(ifdep.addr) addr;
  92. var(ifdep.addr_prefix) addr_prefix;
  93. var(ifdep.gateway) gateway;
  94. var(ifdep.dns_servers) dns_servers;
  95. # Add default route.
  96. net.ipv4.route("0.0.0.0", "0", gateway, "20", dev);
  97. # Configure DNS servers.
  98. net.dns(dns_servers, "20");
  99. }