得之我幸 失之我命

when someone abandons you,it is him that gets loss because he lost someone who truly loves him but you just lost one who doesn’t love you.

nmcli 配置静态 IP

不知道什么时候开始 network-manager 成了 debian 默认管理网络连接的工具,可能是因为我装了桌面环境吧

起初,连接 wifi 是用的 wpa_supplicant,后来 nm 出来以后,连同着命令行也要换了,成了 nmcli

最近,希望把 debian 的 ip 固定下来,方便每次连接 wifi 的时候自动分配到同一个 ip,以做家里的小服务器 ip

在搜索教程的时候,部分教程说 nmcli con 对设备(网卡)进行修改,其实是不对的,应该是对 connection(连接)对设置,而连接是属于某个特定设备的

NetworkManager stores all network configuration as “connections”, which are collections of data (Layer2 details, IP addressing, etc.) that describe how to create or connect to a network. A connection is “active” when a device uses that connection’s configuration to create or connect to a network. There may be multiple connections that apply to a device, but only one of them can be active on that device at any given time. The additional connections can be used to allow quick switching between different networks and configurations.

从上述官方手册的说明中也不难看出,nmcli connection 的命令是针对网络配置的,而不是针对设备去做配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ nmcli c  # 显示所有网络连接,当前设备保存的网络连接有两个,且都属于无线网卡 enp0s3 的
NAME UUID TYPE DEVICE
test 7c1b8444-cb65-440d-9bf6-ea0ad5e60bae wifi enp0s3
tes1 3020c41f-6b21-4d80-a1a6-7c1bd5867e6c wifi enp0s3

# nmcli con/nmcli connection/nmcli c show 与上述命令等效

$ nmcli con mod test ipv4.addresses 192.168.1.4/24 # 设置静态 ip

$ nmcli con mod test ipv4.gateway 192.168.1.1 # 设置网关

$ nmcli con mod test ipv4.method manual # 设置手动配置(从 dhcp 到 static)

$ nmcli con mod test ipv4.dns 8.8.8.8 # 设置 DNS

$ nmcli con up test # 保存上述更改并重新加载

be slow to promise and quick to perform.