netnsplan
is a tool for easily setting up and managing complex network environments using Linux's network namespaces (netns). Network configurations are defined using YAML files, and the netnsplan
command is used to apply and manage these configurations.
- Configuration via YAML: Network settings are defined in a YAML file, enabling high readability and manageability. The configuration file is similar to netplan, allowing for easy network configuration.
- Network Namespace Management: Supports the creation, configuration, and deletion of multiple network namespaces.
- Flexible Network Configuration: Supports configuration of physical devices, dummy interfaces (dummy devices), and Veth devices, as well as address assignment and routing settings.
- Execution of Arbitrary Scripts: Allows for the execution of any script on the network namespace after applying network settings.
Network settings are defined by YAML files. By default, netnsplan reads all YAML files (*.yaml) under /etc/netnsplan
, merges them, and applies the settings based on the merged result.
Below is an example of the configuration. The file name is set as /etc/netnsplan/example.yaml
.
# /etc/netnsplan/example.yaml
netns:
ns1:
ethernets:
eth0:
addresses:
- 10.1.0.1/24
dummy-devices:
dummy0:
addresses:
- 10.2.0.1/24
veth-devices:
veth0:
addresses:
- 10.3.0.1/24
peer:
name: veth1
netns: ns2
addresses:
- 10.3.0.2/24
In this configuration, two network namespaces, ns1
and ns2
, are created, each with different network interfaces configured.
To apply network namespaces and network settings based on the configuration file, execute the following command:
netnsplan apply
To delete the created network namespaces, execute the following command:
netnsplan destroy
VERSION=$(wget -q -O- https://api.github.com/repos/buty4649/netnsplan/releases/latest | grep tag_name | cut -d '"' -f 4 | tr -d v)
case $(uname -m) in x86_64) ARCH=amd64;; aarch64) ARCH=arm64;; esac
wget https://github.com/buty4649/netnsplan/releases/download/v${VERSION}/netnsplan_${VERSION}_linux_${ARCH}.deb
sudo apt install ./netnsplan_${VERSION}_linux_${ARCH}.deb
VERSION=$(wget -q -O- https://api.github.com/repos/buty4649/netnsplan/releases/latest | grep tag_name | cut -d '"' -f 4 | tr -d v)
case $(uname -m) in x86_64) ARCH=amd64;; aarch64) ARCH=arm64;; esac
yum install https://github.com/buty4649/netnsplan/releases/download/v${VERSION}/netnsplan_${VERSION}_linux_${ARCH}.rpm
VERSION=$(wget -q -O- https://api.github.com/repos/buty4649/netnsplan/releases/latest | grep tag_name | cut -d '"' -f 4 | tr -d v)
case $(uname -m) in x86_64) ARCH=amd64;; aarch64) ARCH=arm64;; esac
wget https://github.com/buty4649/netnsplan/releases/download/v${VERSION}/netnsplan_${VERSION}_linux_${ARCH}.tar.gz
tar xvf netnsplan_${VERSION}_linux_${ARCH}.tar.gz netnsplan
chmod +x netnsplan
sudo chown root: netnsplan
sudo mv netnsplan /usr/local/sbin/netnsplan