systemd-networkd.service
通过一个简单的 ini 风格的文本文件,对网络配置进行编码以匹配网络接口
介绍
- 配置文件在
/etc/systemd/network
目录下 - 修改配置文件后,需要重启服务
systemctl restart systemd-networkd.service
示例
配置静态 IP
- /etc/systemd/network/50-static.network
[Match]
Name=enp2s0
[Network]
Address=192.168.0.15/24
Gateway=192.168.0.1
配置 DHCP
- /etc/systemd/network/80-dhcp.network
[Match]
Name=en*
[Network]
DHCP=yes
IPv6 Prefix Delegation (DHCPv6 PD)
- /etc/systemd/network/55-dhcpv6-pd-upstream.network
[Match]
Name=enp1s0
[Network]
DHCP=ipv6
- /etc/systemd/network/55-dhcpv6-pd-downstream.network
[Match]
Name=enp2s0
[Network]
DHCPPrefixDelegation=yes
IPv6SendRA=yes
网桥配置
- /etc/systemd/network/25-bridge-static.netdev
[NetDev]
Name=bridge0
Kind=bridge
- /etc/systemd/network/25-bridge-static.network
[Match]
Name=bridge0
[Network]
Address=192.168.0.15/24
Gateway=192.168.0.1
DNS=192.168.0.1
- /etc/systemd/network/25-bridge-slave-interface-1.network
[Match]
Name=enp2s0
[Network]
Bridge=bridge0
- /etc/systemd/network/25-bridge-slave-interface-2.network
[Match]
Name=wlp3s0
[Network]
Bridge=bridge0
网桥与 VLAN
- /etc/systemd/network/25-bridge-slave-interface-1.network
[Match]
Name=enp2s0
[Network]
Bridge=bridge0
[BridgeVLAN]
VLAN=1-32
PVID=42
EgressUntagged=42
[BridgeVLAN]
VLAN=100-200
[BridgeVLAN]
EgressUntagged=300-400
隧道
# /etc/systemd/network/25-tunnels.network
[Match]
Name=ens1
[Network]
Tunnel=ipip-tun
Tunnel=sit-tun
Tunnel=gre-tun
Tunnel=vti-tun
# /etc/systemd/network/25-tunnel-ipip.netdev
[NetDev]
Name=ipip-tun
Kind=ipip
# /etc/systemd/network/25-tunnel-sit.netdev
[NetDev]
Name=sit-tun
Kind=sit
# /etc/systemd/network/25-tunnel-gre.netdev
[NetDev]
Name=gre-tun
Kind=gre
# /etc/systemd/network/25-tunnel-vti.netdev
[NetDev]
Name=vti-tun
Kind=vti
bond 设备
# /etc/systemd/network/30-bond1.network
[Match]
Name=bond1
[Network]
DHCP=ipv6
# /etc/systemd/network/30-bond1.netdev
[NetDev]
Name=bond1
Kind=bond
# /etc/systemd/network/30-bond1-dev1.network
[Match]
MACAddress=52:54:00:e9:64:41
[Network]
Bond=bond1
# /etc/systemd/network/30-bond1-dev2.network
[Match]
MACAddress=52:54:00:e9:64:42
[Network]
Bond=bond1
扩展
- linux 网络配置软件包括
- network
- NetworkManager
- netctl
- netplan
- systemd-networkd 等