【网络】nmcli 网络管理工具

目录

前提

实例

nmcli的命令参数

添加网卡到配置文件

Linux系统怎么查看网卡的UUID


原文:https://www.cnblogs.com/webmans/p/13736823.html

前提

NetworkManager 需要开启

查看NetworkManager 状态

systemctl status NetworkManager

开启NetworkManager

systemctl startNetworkManager

 

实例

查看网卡信息

nmcli

查看网络设备状态

nmcli device status

查看网络连接状态

nmcli connection 

查看UUID等网卡信息

nmcli connection show 

查看网络详细信息

nmcli device show ens32

设置静态ip

nmcli connection modify ens32 ipv4.addresses '192.168.1.10'

设置网关

nmcli connection modify ens32 ipv4.gateway '192.168.1.1'

设置DNS

nmcli connection modifly ens32 ipv4.dns '144.144.144.144'

ip地址设为手动

nmcli connection modify ens32 ipv4.method manual

ip地址设为自动获取

nmcli connection modify ens32 ipv4.method auto

设置开机自动连接 

nmcli connection modify ens32 connection.autoconnect yes

nmcli connection modify ens32 connection.autoconnect no

重新加载配置文件

nmcli connection reload

不重启系统网卡生效

nmcli connection up ens32

nmcli device connect ens32

nmcli device reapply ens32

查看DNS

cat /etc/resolv.conf

 

插曲

prefix 子网掩码

255.255.255.0用二进制表示为11111111.11111111.11111111.00000000,  24个1。所以说网络位是24位。PREFIX=24
255.255.255.192用二进制表示为11111111.11111111.11111111.11000000,  26个1。所以说网络位是26位。PREFIX=26
255.255.255.128用二进制表示为11111111.11111111.11111111.10000000,  26个1。所以说网络位是25位。PREFIX=25
255.255.255.224用二进制表示为11111111.11111111.11111111.11100000,  27个1。所以说网络位是27位。PREFIX=27
255.255.255.240用二进制表示为11111111.11111111.11111111.11110000,  28个1。所以说网络位是28位。PREFIX=28
255.255.255.248用二进制表示为11111111.11111111.11111111.11111000,  29个1。所以说网络位是29位。PREFIX=29

笔者配置文件中最后有一行 prefix = 32 ,无论如何设置子网掩码netlmask 都是255.255.255.255,删除后才恢复

 

 

nmcli的命令参数


[root@localhost ~]# nmcli --help
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }

OPTIONS
  -t[erse]                                   terse output
  -p[retty]                                  pretty output
  -m[ode] tabular|multiline                  output mode
  -f[ields] <field1,field2,...>|all|common   specify fields to output
  -e[scape] yes|no                           escape columns separators in values
  -n[ocheck]                                 don't check nmcli and NetworkManager versions
  -a[sk]                                     ask for missing parameters
  -w[ait] <seconds>                          set timeout waiting for finishing operations
  -v[ersion]                                 show program version
  -h[elp]                                    print this help

OBJECT
  g[eneral]       NetworkManager's general status and operations
  n[etworking]    overall networking control
  r[adio]         NetworkManager radio switches
  c[onnection]    NetworkManager's connections
  d[evice]        devices managed by NetworkManager
 

添加网卡到配置文件



添加网卡到配置文件,并且命名为eth1


[root@localhost ~]# nmcli connection add ifname eno33554992 con-name eth1 type ethernet 


Connection 'eth1' (5f1fde10-d2a2-4ea5-8213-7cdb53bb59bf) successfully added.


[root@localhost ~]# ip a


1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state 
UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:53 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.10/24 brd 192.168.10.255 scope global 
eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4d:bb53/64 scope link 
       valid_lft forever preferred_lft forever
3: eno33554992: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 

pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:5d brd ff:ff:ff:ff:ff:ff
    inet6 fe80::20c:29ff:fe4d:bb5d/64 scope link 
       valid_lft forever preferred_lft forever
 

修改网络配置文件添加MAC地址 (eno33554992) 、修改BOOTPROTO=static 修改设备名DEVICE=eth1
 

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1

TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth1
UUID=5f1fde10-d2a2-4ea5-8213-7cdb53bb59bf
DEVICE=eth1
ONBOOT=yes
HWADDR=00:0c:29:4d:bb:5d


重启network服务之后 查看ip
 

[root@localhost ~]# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state 
UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:53 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.10/24 brd 192.168.10.255 scope global
eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4d:bb53/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 

pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:5d brd ff:ff:ff:ff:ff:ff


添加ip地址


[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1 
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth1
UUID=5f1fde10-d2a2-4ea5-8213-7cdb53bb59bf
DEVICE=eth1
ONBOOT=yes
HWADDR=00:0c:29:4d:bb:5d
IPADDR0=192.168.1.101
PREFIX0=24
GATEWAY=192.168.1.254



重启网络服务并且查看ip

[root@localhost ~]# systemctl restart network
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state 
UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:53 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.10/24 brd 192.168.10.255 scope global 
eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4d:bb53/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc 
pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4d:bb:5d brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.101/24 brd 192.168.1.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4d:bb5d/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# nmcli connection show 
NAME         UUID                                  TYPE            DEVICE      
eth1         5f1fde10-d2a2-4ea5-8213-7cdb53bb59bf  802-3-ethernet  eth1        
eno16777736  ce1a55de-9427-4f08-9ff8-256ac08ebd78  802-3-ethernet  eno16777736 
 


原文链接:https://blog.csdn.net/qq_36783142/article/details/75353944

 

Linux系统怎么查看网卡的UUID


在linux系统下查看网卡的UUID需要nmcli命令,但是该命令系统没有提供。

1、首先要查看哪个软件包提供了该命令

[root@tpp ~]# yum provides "*/nmcli"
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.pubyun.com
 * extras: ftp.sjtu.edu.cn
 * updates: mirrors.pubyun.com
base/filelists_db                              | 5.2 MB     00:04
extras/filelists_db                            |  30 kB     00:00
updates/filelists_db                           | 829 kB     00:00
1:NetworkManager-0.8.1-99.el6.i686 : Network connection manager and user
                                   : applications
Repo        : base
Matched from:
Filename    : /usr/bin/nmcli

2、由上面的查看结果,我们知道是NetworkManager,下面我们先安装这个软件包

[root@tpp ~]# yum install -y NetworkManager

3、然后启动服务

[root@tpp ~]# service NetworkManager start

4、查看网卡的UUID

[root@tpp ~]# nmcli con

 

名称          UUID                                 类型            范围   真实时间戳
System eth0  d9a980b8-b4bd-4573-b966-77e0fcdd6205 802-3-ethernet  系统   2015年08月29日 星期六 22时07分43秒

 

posted on 2022-10-04 01:23  bdy  阅读(166)  评论(0编辑  收藏  举报

导航