Red Hat Enterprise Linux 7 与 CentOS 7 中默认的网络服务由 NetworkManager 提供,这是动态控制及配置网络的守护进程,它用于保持当前网络设备及连接处于工作状态,同时也支持传统的 ifcfg 类型的配置文件。
NetworkManager 可以用于以下类型的连接:Ethernet,VLANS,Bridges,Bonds,Teams,Wi-Fi,mobile boradband(如移动3G)以及 IP-over-InfiniBand。针对与这些网络类型,NetworkManager 可以配置他们的网络别名,IP 地址,静态路由,DNS,VPN连接以及很多其它的特殊参数。
可以用命令行工具 nmcli 来控制 NetworkManager
show显示网卡信息 status显示为谁工作的
nmcli device connect eth0 ##启用eth0网卡
nmcli device disconnect eth0 ##关闭eth0网卡
nmcli device show eth0 ##显示网卡信息
nmcli device status eth0 ##查看网卡服务接口信息
nmcli connection show ##显示网卡接口信息
nmcli connection down student ##关闭网卡接口信息
nmcli connection up student ##开启网卡接口信息
nmcli connection delete student ##删除网卡接口信息
nmcli connection add type ethernet
con-name westos ifname eth0 ip4 172.25.254.100/24
##添加一个类型为以太网接口名称为westos网卡名称为eth0使用静态网络ipv4为以上的网络
nmcli connection modify student
ipv4.method auto ##更改ipv4的网络连接方式为动态的
nmcli connection modify student
ipv4.method manual ##更改ipv4的网络连接方式为静态的
nmcli connection modify student
ipv4.addresses 172.25.254.210/24 ##更改ipv4的地址是172.25.254.210/24
7.管理网络配置文件(以编辑文件的方式)
(1)网络配置目录
/etc/sysconfig/network-scripts/
(2)网络配置文件的命名规则
ifcfg-xxx
DEVICE=eth0 ##设备名称
BOOTPROTO=dhcp(动态)|static|none(静态)
##设备的工作方式
ONBOOT=yes ##网络服务开启时自动激活网卡
IPADDR= ##IP地址
PREFIX=24 ##子网掩码
或者NETMASK=255.255.255.0 ##子网掩码
NAME= ##接口名称
示例:静态网络设定文件
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=172.25.254.10
PREFIX=24
NAME=student