1、查看IP、网关、DNS:
nmcli device show
2、启用并停止网络
sudo systemctl startNetworkManager.service
sudo service network-manager start#停止
sudo systemctl stop NetworkManager.service
sudo service network-manager stop
3、常用命令
显示所有包括不活动连接
nmcli con show
显示所有活动连接
nmcli con show –active
显示网络连接配置
nmcli con show "System eth0“
显示设备状态
nmcli dev status
显示网络接口属性
nmcli dev show eno16777736
4.添加网络配置
nmcli connection add con-name test2 ipv4.method manual ifname ens33 autoconnect no type Ethernet ipv4.addresses 10.136.62.3/24 gw4 10.136.62.1
5、修改网络配置
nmcli connection modify eth0 ipv4.addresses 192.168.1.100/24
6.添加动态和静态配置
使用“dhcp”创建新的连接
[root@localhost ~]# nmcli connection add con-name "dhcp" type ethernet ifname eno16777736
这里,
connection add – 添加新的连接
con-name – 连接名
type – 设备类型
ifname – 接口名
这个命令会使用dhcp协议添加连接
示例输出:
Connection 'dhcp' (163a6822-cd50-4d23-bb42-8b774aeab9cb) successfully added.
不通过dhcp分配IP,使用“static”添加地址
[root@localhost ~]# nmcli connection add con-name "static" ifname eno16777736 autoconnect no type ethernet ip4 192.168.1.240 gw4 192.168.1.1
示例输出:
Connection 'static' (8e69d847-03d7-47c7-8623-bb112f5cc842) successfully added.
更新连接:
[root@localhost ~]# nmcli connection up eno1
再检查一遍,ip地址是否已经改变
[root@localhost ~]# ip addr show
添加DNS设置到静态连接中
[root@localhost ~]# nmcli connection modify "static" ipv4.dns 202.131.124.4
添加更多的DNS
[root@localhost ~]# nmcli connection modify "static" +ipv4.dns 8.8.8.8
注意:要使用额外的+符号,并且要是+ipv4.dns,而不是ip4.dns。
添加一个额外的ip地址
[root@localhost ~]# nmcli connection modify "static" +ipv4.addresses 192.168.200.1/24
使用命令刷新设置:
[root@localhost ~]# nmcli connection up eno1
7.通过/udev/rules将MAC与eth绑定
# 网络设备信息
--------------------------------------------------------------------------------------
name type MATCHADDR Bandwidth PCIID driver device
--------------------------------------------------------------------------------------
eth0 Ethernet 00:13:32:0e:2a:60 1000baseT/Full 0000:05:00.0 e1000e 8086:10d3
eth1 Ethernet 00:13:32:0e:2a:61 1000baseT/Full 0000:06:00.0 e1000e 8086:10d3
eth2 Ethernet 00:13:32:0e:2a:62 1000baseT/Full 0000:07:00.0 e1000e 8086:10d3
eth3 Ethernet 00:13:32:0e:2a:63 1000baseT/Full 0000:08:00.0 e1000e 8086:10d3
--------------------------------------------------------------------------------------
eth4 Ethernet 00:10:f3:5a:96:36 10000baseT/Full 0000:01:00.0 ixgbe 8086:10fb
eth5 Ethernet 00:10:f3:5a:96:37 10000baseT/Full 0000:01:00.1 ixgbe 8086:10fb
--------------------------------------------------------------------------------------
# 将设备MAC地址与ethN接口名称相关联
$ sudo vi cat 70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x8086:10d3 (e1000e) --- 05:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:13:32:0e:2a:60", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:10d3 (e1000e) --- 06:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:13:32:0e:2a:61", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x8086:10d3 (e1000e) --- 07:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:13:32:0e:2a:62", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
# PCI device 0x8086:10d3 (e1000e) --- 08:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:13:32:0e:2a:63", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"
# PCI device 0x8086:0x10fb (ixgbe) --- 01:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:10:f3:5a:96:36", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth4"
# PCI device 0x8086:0x10fb (ixgbe) --- 01:00.1
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:10:f3:5a:96:37", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth5"
# 将设备PCI总线地址与ethN接口名称相关联
$ sudo vi cat 70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x8086:10d3 (e1000e) --- 05:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:05:00.0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:10d3 (e1000e) --- 06:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:06:00.0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x8086:10d3 (e1000e) --- 07:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:07:00.0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
# PCI device 0x8086:10d3 (e1000e) --- 08:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:08:00.0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"
# PCI device 0x8086:0x10fb (ixgbe) --- 01:00.0
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:01:00.0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth4"
# PCI device 0x8086:0x10fb (ixgbe) --- 01:00.1
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", %B=="0000:01:00.1", ATTR{type}=="1", KERNEL=="eth*", NAME="eth5"
# 重新加载设备规则配置文件
$ sudo chmod a+x /etc/udev/rules.d/70-persistent-net.rules
$ sudo udevadm control --reload-rules 或 sudo service udev restart