CentOS7 网络管理相关命令

contos7 网卡配置文件自动识别ifcfg开头的文件(包括目录)

CentOS7网卡命名规则:

CentOS 7 开始对于网卡的编号则有另一套规则, 网卡的界面代号现在与网卡的来源有关,基本上的网卡名称会是这样分类的:

eno1 : 代表由主板 BIOS 内置的网卡

ens1 : 代表由主板 BIOS 内置的 PCI-E 界面的网卡

enp2s0 : 代表 PCI-E 界面的独立网卡, 可能有多个插孔, 因此会有 s0, s1... 的编号

eth0 : 如果上述的名称都不适用, 就回到原本的默认网卡编号

一个网卡设备(device)可以包含多个连接(conn),但同时只能有一个连接(conn)正在使用。

显示NetworkManage状态:

[root@CentOS7 ~]# nmcli general status

STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN

connected full enabled enabled enabled enabled

查看设备状态:

[root@CentOS7 ~]# nmcli device status

DEVICE TYPE STATE CONNECTION

eno16777736 ethernet connected Wired connection 2

eno33554984 ethernet connected System eno33554984

eno50332208 ethernet connected System eno50332208

eno67109432 ethernet connected Wired connection 1

team0 team connected Team team0

lo loopback unmanaged --

查看某个设备的信息:

[root@CentOS7 ~]# nmcli device show team0

GENERAL.DEVICE: team0

GENERAL.TYPE: team

GENERAL.HWADDR: 00:0C:29:65:D1:DA

GENERAL.MTU: 1500

GENERAL.STATE: 100 (connected)

GENERAL.CONNECTION: Team team0

GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/6

IP4.ADDRESS[1]: 192.168.1.71/24

IP4.GATEWAY: 192.168.1.1

IP6.ADDRESS[1]: fe80::20c:29ff:fe65:d1da/64

IP6.GATEWAY:

查看连接状态:

[root@CentOS7 ~]# nmcli conn show

NAME UUID TYPE DEVICE

Team team0 702de3eb-2e80-897c-fd52-cd0494dd8123 team team0

System eno50332208 d2665055-8e83-58f1-e9e3-49a5fb133641 802-3-ethernet eno50332208

team0-port1 4233d75c-ff88-4897-a357-db8e7392c829 802-3-ethernet --

Wired connection 2 2d4efd88-8eb5-4f32-a445-a7c5f272eba1 802-3-ethernet eno16777736

Wired connection 1 68ee33fa-d1ab-4a68-aad7-b0a281740831 802-3-ethernet eno67109432

team0-port2 94440fc0-a654-4225-9307-ea8effe21a80 802-3-ethernet --

System eno33554984 fb67dbad-ec81-39b4-42b1-ebf975c3ff13 802-3-ethernet eno33554984

[root@CentOS7 ~]# nmcli conn show -a

接口相关统计数据:

[root@CentOS7 ~]# watch -n 1 "ip -s link show team0"

[root@CentOS7 ~]# ip -s link show team0

7: team0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT

link/ether 00:0c:29:65:d1:da brd ff:ff:ff:ff:ff:ff

RX: bytes packets errors dropped overrun mcast

18670 324 0 148 0 0

TX: bytes packets errors dropped carrier collsns

1244 18 0 0 0 0

查看路由配置:

[root@CentOS7 ~]# ip route

default via 192.168.1.1 dev eno67109432 proto static metric 100

default via 192.168.1.1 dev eno16777736 proto static metric 103

default via 192.168.1.1 dev team0 proto static metric 350

192.168.1.0/24 dev eno67109432 proto kernel scope link src 192.168.1.102 metric 100

192.168.1.0/24 dev eno16777736 proto kernel scope link src 192.168.1.103 metric 101

192.168.1.0/24 dev eno16777736 proto kernel scope link src 192.168.1.103 metric 102

192.168.1.0/24 dev eno16777736 proto kernel scope link src 192.168.1.103 metric 103

192.168.1.0/24 dev team0 proto kernel scope link src 192.168.1.71 metric 350

路由配置:

[root@CentOS7 ~]# ip route add 10.10.100.0/24 via 192.168.1.1 dev team0

                  目标地址 网关 接口

删除路由:

[root@CentOS7 ~]# ip route del 10.10.100.0/24 via 192.168.1.1 dev team0 #方法一

[root@CentOS7 ~]# ip route del 10.10.100.0/24 #方法二

重启设备:ifdown ,ifup

nmcli dev disconn eno33554984 && nmcli dev conn eno33554984

重启网络服务:

[root@CentOS7 ~]# systemctl restart network.service

添加一块网卡:

  1、ip addr show 命令查看接口信息(获取添加网卡的名称)

  2、进入/etc/sysconfig/network-scripts/ 目录,创建一个ifcfg-网卡名字 )的网卡配置文件。

  3、 systemctl restart network.service

添加删除ip:(一个网卡中可以添加多个ip)

nmcli connection modify eno16777736 +ipv4.addresses 10.10.10.100/24

nmcli connection modify eno16777736 -ipv4.addresses 10.10.10.100/24

添加一个静态ip地址(会自动创建配置文件)

[root@CentOS7 ~]# nmcli conn add type ethernet con-name eno16777736 ifname eno16777736 ip4 192.168.1.222 gw4 192.168.1.1

Connection 'eno16777736' (0ec4472e-11cd-44b7-99f7-86397c340d0d) successfully added.

启动:

[root@CentOS7 ~]# nmcli conn up eno16777736 ifname eno16777736