NetworkManager

 20th August 2020 at 2:19pm

NetworkManager 有几个组件:

  • daemon,NetworkManager.service
  • nmcli,命令行工具
  • plasma-nm,Plasma 的桌面 GUI 工具
  • dispatcher,NetworkManager-dispatcher.service,提供 hook 到 interface 状态变化时的能力

Dispatcher

示例:

# Run as root
cd /etc/NetworkManager/dispatcher.d/

vim 00-remove-default-route.sh

#!/bin/bash

IF=$1
STATUS=$2

if [[ "$IF" == "enp2s0" && "$STATUS" == "up" ]]; then
    echo "Hey I am up"
fi

chown root:root 00-remove-default-route.sh
chmod 755 00-remove-default-route.sh

systemctl enable NetworkManager-dispatcher.service
systemctl start NetworkManager-dispatcher.service

Dispatch 的细节参考:

DNS 配置获取

NetworkManager 用 resolveconf 这个工具来发 DHCP(?) 请求并把获得的 DNS 服务器配置加到 /etc/resolv.conf 中。默认会把所有网卡的 DNS 配置都加进来。

可以在 /etc/resolveconf.conf 中写配置,比如如果你不想要 10.11.56.* 的 DNS 服务器被加进来,可以:

name_server_blacklist="10.11.56.* 10.14.0.*"

调试

systemctl restart NetworkManager
systemctl restart NetworkManager-dispatcher