nmcli命令和etc/sysconfig/network-scripts/ifcfg-*配置文件对应关系
nmcli
/etc/sysconfig/network-scripts/ifcfg-*
意思
ipv4.method manual
BOOTPROTO=none
不指定协议
ipv4.method auto
BOOTPROTO=dhcp
指定DHCP协议
ipv4.address “192.168.1.1/24”
IPADDR0=192.168.1.1 PREFIX0=24 GATEWAY0=192.16.1.254
设置IP,子网掩码和网关
ipv4.dns 8.8.8.8
DNS1=8.8.8.8
设置DNS服务器
ipv4.dns-search example.com
DOMAIN=example.com
设置域
ipv4.igore-auto-dns ture
PEERDNS=no
防止从 DHCP 服务器接收的 DNS 服务器更新
connection.autoconnect yes
ONBOOT=yes
系统启动时是否开启
connection.id eth0
NAME=eth0
设置名字
connection.interface-name eth0
DEVICE=eth0
网卡名称
802-3-ethernet.mac-address
HWADDR
网卡设备MAC地址
查看网卡设备连接情况
nmcli device
查看网卡信息
nmcli connection show
nmcli connection show --active //显示活动的网卡
查看具体信息
nmcli connection show ens33
重启网络
systemctl restart network
nmcli connetion reload
删除一个网卡
nmcli connection delete ens33
添加一个网卡
nmcli connection add type ethernet eth0 ifname ens33
开启和关闭网卡
nmcli connection down ethernet-ens33
nmcli connection up ethernet-ens33
设置网卡IP和子网掩码和网关
nmcli connection modify eth0 ipv4.address 192.168.1.10/24 ipv4.gateway 192.168.1.254
nmcli connection modify eth0 +ipv4.address 192.168.1.11/24 //添加一个ip
nmcli connection modify eth0 -ipv4.address 192.168.1.11/24 //删除一个ip
IP获取方式设置为手动或DHCP
nmcli connection modify eth0 ipv4.method manual
nmcli connection modify eth0 ipv4.method auto
设置DNS
nmcli connection modify eth0 ipv4.dns 8.8.8.8 //添加一个DNS
nmcli connection modify eth0 -ipv4.dns 8.8.8.8 //删除一个DNS
综合设置
nmcli connection modify eth0 ipv4.address 192.168.1.10/24 ipv4.gateway 192.168.1.254 ipv4.dns 8.8.8.8 ipv4.dns-search example.com ipv4.method manual connection.autoconnect yes connection,interface-name eth0