Package: neatplan
neatplannginx-style network configuration...pretty neat, huh?Why, for the love of integrated circuits why you ask? Because I can.DependenciesPython >= 3.6crossplaneiproute2dhclient (optional)FeaturesBoot-time configurationIPv4/IPv6 supportLoopback interface up by default (ip link set lo up)Set link up for a given interface (ip link set <iface> up)Set IP address for a given interface (ip addr add <ip/mask> dev <iface>)Set IP route for a given interface (ip ro add <ip> dev <iface>)Set default IP route for a given interface (ip ro add default via <ip> dev <iface>)Set via IP route for a given interface (ip ro add <ip> via <ip> dev <iface>)Set nameservers (/etc/resolv.conf)DHCP configuration (dhclient)Firewall configuration (iptables-restore,ip6tables-restore)Custom commands to run before and after for advanced and custom configurationConfigured interfaces are being stored in/run/neatplanInstallationNeatplan is intended for people who know what they are doing,
or at least for those aware that this may result
in the loss of access to the server over the network.
If you're afraid of breaking things, pick something else.
Although, returning to the previous network configuration method is trivial
because neatplan does not introduce any invasive changes to the system.
But before you start destroying your network configuration,
however enjoyable it is, make sure you have access to some kind
of remote (or local) console that will allow you to debug without direct SSH access.All the scripts must be run with root privileges,
as it is necessary to interact with network configuration.PyPIpipinstallneatplanGithubgitclonehttps://github.com/c0m4r/neatplan.git/opt/neatplancd/opt/neatplan
./deploy.shThe script will:create the Python venvcreate a symlink to the wrapper in/usr/local/bin/neatplancopy the respective init script if it's availablecreate a config file in/etc/neatplan/default.confAlpine LinuxTo replace networking with neatplan at boot time:rc-updatedelnetworkingboot
rc-updateaddneatplanbootVoid LinuxTo start neatplan as a runit service:ln-s/etc/sv/neatplan/var/service/UsageSimply runningneatplanwill immediately set the network using default config (if present).Dry-runIf you would like to test your configuration before actually executing it, use the dry-run mode:neatplan --dry-runNeatplan will only print a parsed configuration, so you can verify it before execution.Custom config pathYou can also point neatplan to a different config file using--configoption:neatplan --config /path/to/file.confHelpRun with--helpto see this help message:usage: neatplan [-h] [-c CONFIG] [-v] [--dry-run]

nginx-style network configuration

options:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        Config file absolute path
  -v, --version         Show version and exit
  --dry-run             Don't execute, only show what you've gotConfigurationConfig path/etc/neatplan/default.confQuick exampleIPv4 using DHCPStatic IPv6 addressIPv6-only CloudFlare DNSnetwork{backendiproute2;ethernet{eth0{dhcp4{enabletrue;}addresses{addressfe80:ffff:eeee:dddd::1/64;}routes{routefe80::1default;}}}dns{nameserver2606:4700:4700::1111;nameserver2606:4700:4700::1001;}}Note thatFull feature showcasenetwork{backendiproute2;before{command"touch/tmp/neatplan";}firewall{iptables/etc/iptables/iptables.rules;ip6tables/etc/iptables/ip6tables.rules;}ethernet{eth0{dhcp4{enabletrue;}dhcp6{enablefalse;}addresses{addressfe80:ffff:eeee:dddd::1/64;addressfe80:ffff:eeee:dddd::2/64;address192.168.0.10;address192.168.100.50/24;}routes{routefe80::1default;route192.168.0.1;route1.1.1.1via192.168.0.1;}}}dns{nameserver2606:4700:4700::1111;nameserver2606:4700:4700::1001;}after{command"echoI\'msocustom,wow";command"iplinkaddlinketh0nameeth0.1337typevlanid1337";}}Note thatdhcp6 { enable: false; }isn't actually necessary. It's not being run by default if not enabled explicitly.Additionally, the ability to execute custom commands within thebeforeandaftercontexts
can be used to run arbitrary code. Make sure only root has write access to the configuration.Writing init scriptsNeatplan saves all configured interfaces (includinglo) at boot time to/run/neatplan.
You can iterate through them or do whatever the hell you want with that information.When starting neatplan make sure it is started before services that rely on the network,
preferably within boot runlevel (thank you captain obvious)If you're about to use IPv6 you have to make sure thattentative statesare gone before ending a start jobWhen stopping neatplan make sure torm /run/neatplanat the end.Handle Python venv before executing neatplan with. /opt/neatplan/.venv/bin/activateor set thePATH=/opt/neatplan/.venv:$PATH.See exampleOpenRCandrunitinit scripts.DocumentationI'm not saying it's the worst documentation I wrote, but it's the worst documentation I wrote.Contextsnamecontextdescriptionnetworkroot of network configurationbeforenetworklist of commands to run before network configurationfirewallnetworkfirewall configurationethernetnetworkethernet configuration<iface>network → ethernetnetwork interface configurationdhcp4network → ethernet → <iface>DHCP v4 settingsdhcp6network → ethernet → <iface>DHCP v6 settingsaddressesnetwork → ethernet → <iface>IP addresses configurationroutesnetwork → ethernet → <iface>IP routes configurationdnsnetworklist of nameserversbeforenetworklist of commands to run after network configurationDirectivesnamecontextsyntaxdescriptionbackendnetworkbackend <name>;IP configuration backendcommandbefore, aftercommand "<command> <args>";Custom shell commandiptablesfirewalliptables <filepath>;Path to iptables rulesip6tablesfirewallip6tables <filepath>;Path to ip6tables rulesenabledhcp4, dhcp6option true | false;Enable or disable optionaddress<iface>address <ip/mask>;IPv4 or IPv6 addressroute<iface>route <ip> [default | via <ip>];IP routenameserverdnsnameserver <ip>;Nameserver addressLicenseneatplan - nginx-like network configuration
Copyright (C) 2024 c0m4r

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.FundingIf you found this software somewhat useful,
please considermaking a donationto acharityon my behalf.
Thank you.