linux中nmcli命令使用及网络配置 nmcli命令与配置文件对应关系

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

 主机名:

如果说你没有设置主机名的话,默认是localhost.localdomain

修改配置文件的主机名

# hostnamectl  set-hostname www.djl.cc

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

查看网卡信息

# nmcli connection

# nmcli con show

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

 显示具体的网络接口信息

# nmcli connection show eth0

 linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

显示所有设配状态

# nmcli device status 

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

修改配置文件执行生效

# systemctl restart network

# nmcli connection reload 

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

显示所有活动连接

# nmcli connection show --active 

删除一个网卡连接

# nmcli connection delete eth0 

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

添加一个网卡连接

# nmcli connection add type ethernet con-name eth0 ifname eno33554992

 linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

网络接口的启用与停用:

停用:

# nmcli connection down eth0 

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

启用:

# nmcli connection up eth0 

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

给eth0添加一个IP(IPADDR)

# nmcli connection modify eth0 ipv4.addresses 192.168.0.58

给eth0添加一个子网掩码(NETMASK)

# nmcli connection modify eth0 ipv4.addresses 192.168.0.58/24

IP获取方式设置成手动(BOOTPROTO=static/none)

# nmcli connection modify eth0 ipv4.method manual

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

添加一个ipv4

# nmcli connection modify eth0 +ipv4.addresses 192.168.0.59/24

删除一个ipv4

# nmcli connection modify eth0 -ipv4.addresses 192.168.0.59/24

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

添加DNS

# nmcli connection modify eth0 ipv4.dns 114.114.114.114

删除DNS

# nmcli connection modify eth0 -ipv4.dns 114.114.114.114

添加一个网关(GATEWAY)

 # nmcli connection modify eth0 ipv4.gateway 192.168.0.2

可一块写入:

nmcli connection modify eth0 ipv4.dns 114.114.114.114 ipv4.gateway 192.168.0.2

修改网卡名称

删除网卡连接

# nmcli connection delete eno16777736

修改内核参数配置文件

# vi /etc/default/grub 

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

植入内核

# grub2-mkconfig -o /boot/grub2/grub.cfg 

linux中nmcli命令使用及网络配置
nmcli命令与配置文件对应关系

重启

#reboot

添加网卡

# nmcli connection add type ethernet con-name eth0