Linux上网络相关的守护进程
摘录自How exactly are NetworkManager, networkd, netplan, ifupdown2, and iproute2 interacting?
有一位答主梳理了网络管理的一些工具:
interfaces
configuration files &ifup
&ifdown
,老三件The /etc/network/interfaces network configuration file seems to be fairly old, but is still used by ifup, ifdown and ifquery.
- 经典命令
ifconfig
来自net-tools
:A collection of programs that form the base set of the NET-3 networking distribution for the Linux operating system。 参考wiki,如今相当部分被标记为obsolete。其替代套件为Iproute2program obsolete by arp ip neigh ifconfig ip addr ifmaddr ip maddr iftunnel ip tunnel route ip route nameif ifrename mii-tool ethtool ip
与ifup
/ifdown
的关系
暂略,似乎我的服务器没有ifup
了NetworkManager
(2004)
参考ManualNetworkManger.conf(5)
此时... Plugins ifupdown This plugin is used on the Debian and Ubuntu distributions, and reads Ethernet and Wi-Fi connections from /etc/network/interfaces. ...
ifup
/ifdown
已经成为了一个相对低层的配置方案了。systemd-networkd
(2010)
systemd-networkd(8)
属于 systemd的一部分,感觉像一种“釜底抽薪”式的终极方案。(毕竟systemd已经代替init成为linux下的System daemon)systemd-networkd will manage network addresses and routes for any link for which it finds a .network file with an appropriate [Match] section, see systemd.network(5). For those links, it will flush existing network addresses and routes when bringing up the device. Any links not matched by one of the .network files will be ignored.
配置静态IP
编辑本机配置实现静态IP
在前面的背景下,配置静态IP的方法就比较明确了。使用network manager,开启ifupdown插件,编辑/etc/network/interface文件
- 首先检查NetworkManger是否被使用
systemctl | grep -i networkmanager
- 开启ifupdown
cat /etc/NetworkManager/NetworkManager.conf >>> [main] plugins=ifupdown,keyfile
- 编辑/etc/network/interface文件
auto eth0 # 自动启动 iface eth0 inet static address 192.168.0.1 netmask 255.255.255.0
注意,本部分并未实际测试,ifdown
/ifup
在个人服务器上已经没有了,酌情取用。可以尝试networkmanager自身的方案。
利用DHCP协议实现静态IP
DHCP 服务可以配置静态IP分配(静态 DHCP 条目),将静态IP地址与目标设备的MAC地址绑定。这里需要对网关的访问权限。
其他问题
摘抄供内网使用的网段
RFC 1918 name | IP address range | Number of addresses | Largest CIDR block (subnet mask) | Host ID size | Mask bits | Classful description[Note 1] |
---|---|---|---|---|---|---|
24-bit block | 10.0.0.0 – 10.255.255.255 | 16777216 | 10.0.0.0/8 (255.0.0.0) | 24 bits | 8 bits | single class A network |
20-bit block | 172.16.0.0 – 172.31.255.255 | 1048576 | 172.16.0.0/12 (255.240.0.0) | 20 bits | 12 bits | 16 contiguous class B networks |
16-bit block | 192.168.0.0 – 192.168.255.255 | 65536 | 192.168.0.0/16 (255.255.0.0) | 16 bits | 16 bits | 256 contiguous class C networks |
DNS配置resolve.conf被NetworkManger覆盖
- 使用 man interface 发现 /etc/network/interface 并不支持 dns 设置
- 实际上 NetworkManager 的配置文件为 /etc/NetworkManager/NetworkManager.conf ,使用 man networkmanager.conf 可以找到关于dns的配置方法
- 简单起见,设置了dns mode为none,自定义 /etc/resolv.conf 文件,此时该文件不会被NetworkManger 覆盖