85 lines
1.3 KiB
Markdown
85 lines
1.3 KiB
Markdown
# Systemd-Netowrkd 说明
|
||
|
||
## 1. 服务控制
|
||
|
||
可以使用标准 systemctl 命令对该服务进行控制。
|
||
|
||
```bash
|
||
sudo systemctl start systemd-networkd
|
||
sudo systemctl enable systemd-networkd
|
||
sudo systemctl stop systemd-networkd
|
||
sudo systemctl disable systemd-networkd
|
||
```
|
||
|
||
## 2. 配置
|
||
|
||
Systemd-Netowrkd 的配置文件在 /etc/systemd/network/ 目录下。
|
||
|
||
扩展名为 .network 是网络配置文件(IP 地址,网关等);扩展名为 .netdev 的是虚拟设备配置文件(如网桥)。
|
||
|
||
以下列举了一些常用配置模板:
|
||
|
||
### 2.1. Wired adapter using DHCP
|
||
|
||
可以使用通配符匹配多个网络接口。
|
||
|
||
/etc/systemd/network/20-wired.network
|
||
|
||
```bash
|
||
[Match]
|
||
Name=eth*
|
||
|
||
[Network]
|
||
DHCP=yes
|
||
```
|
||
|
||
### 2.2. Wired adapter using a static IP
|
||
|
||
/etc/systemd/network/20-wired.network
|
||
|
||
```bash
|
||
[Match]
|
||
Name=eth0
|
||
|
||
[Network]
|
||
Address=10.1.10.9/24
|
||
Gateway=10.1.10.1
|
||
DNS=10.1.10.1
|
||
```
|
||
|
||
### 2.3. Network bridge
|
||
|
||
需要先创建网桥虚拟设备:
|
||
|
||
/etc/systemd/network/25-br0.netdev
|
||
|
||
```bash
|
||
[NetDev]
|
||
Name=br0
|
||
Kind=bridge
|
||
```
|
||
|
||
对网桥网络进行配置:
|
||
|
||
/etc/systemd/network/25-br0.network
|
||
|
||
```bash
|
||
[Match]
|
||
Name=br0
|
||
|
||
[Network]
|
||
DHCP=yes
|
||
```
|
||
|
||
将网络接口添加进网桥:
|
||
|
||
/etc/systemd/network/25-br0-eth.network
|
||
|
||
```bash
|
||
[Match]
|
||
Name=eth*
|
||
|
||
[Network]
|
||
Bridge=br0
|
||
```
|