# 创建connection,配置静态ip(等同于配置ifcfg,其中BOOTPROTO=none,并ifup启动) nmcli c add type ethernet con-name ethX ifname ethX ipv4.addr 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.method manual
nmcli c add type ethernet con-name ethX-test ifname ethX ipv4.addresses '192.168.1.100/24,192.168.1.101/32' ipv4.routes '10.0.0.0/8 192.168.1.10,192.168.0.0/16 192.168.1.11' ipv4.gateway 192.168.1.254 ipv4.dns '8.8.8.8,4.4.4.4' ipv4.method manual # type ethernet:创建连接时候必须指定类型,类型有很多,可以通过nmcli c add type -h看到,这里指定为ethernet。 # con-name ethX ifname ethX:第一个ethX表示连接(connection)的名字,这个名字可以任意定义,无需和网卡名相同;第二个ethX表示网卡名,这个ethX必须是在nmcli d里能看到的。 # ipv4.addresses ‘192.168.1.100/24,192.168.1.101/32’:配置2个ip地址,分别为192.168.1.100/24和192.168.1.101/32 # ipv4.gateway 192.168.1.254:网关为192.168.1.254 # ipv4.dns ‘8.8.8.8,4.4.4.4’:dns为8.8.8.8和4.4.4.4 # ipv4.method manual:配置静态IP
# 创建connection,配置动态ip(等同于配置ifcfg,其中BOOTPROTO=dhcp,并ifup启动) nmcli c add type ethernet con-name ethX ifname ethX ipv4.method auto
# 修改ip(非交互式) nmcli c modify ethX ipv4.addr '192.168.1.200/24' nmcli c up ethX
# 修改ip(交互式) nmcli c edit ethX nmcli> goto ipv4.addresses nmcli ipv4.addresses> change Edit 'addresses' value: 192.168.1.200/24 Do you also want to set'ipv4.method' to 'manual'? [yes]: yes nmcli ipv4> save nmcli ipv4> activate nmcli ipv4> quit
# 启用connection(相当于ifup) nmcli c up ethX
# 停止connection(相当于ifdown) nmcli c down
# 删除connection(类似于ifdown并删除ifcfg) nmcli c delete ethX
# 查看connection列表 nmcli c show
# 查看connection详细信息 nmcli c show ethX
# 重载所有ifcfg或route到connection(不会立即生效) nmcli c reload
# 重载指定ifcfg或route到connection(不会立即生效) nmcli c load /etc/sysconfig/network-scripts/ifcfg-ethX nmcli c load /etc/sysconfig/network-scripts/route-ethX
# 立即生效connection,有3种方法 nmcli c up ethX nmcli d reapply ethX nmcli d connect ethX