rhel7(centOS7)NetworkManager网络链接配置的基本使用

RHEL 7 与 CentOS 7 中默认的网络服务由 NetworkManager 提供,这是动态控制及配置网络的守护进程,之前通过修改下面配置文件管理网络,然后systemctl restart network使其生效;

/etc/sysconfig/network-scripts/ifcfg-enp125s0f0

NetworkManager网络链接配置的基本使用

用命令行工具 nmcli 来控制 NetworkManager。

nmcli[ OPTIONS ] OBJECT { COMMAND | help }

事例:nmcli 配置两个网络地址链接

  • 查看所有网络链接
[root@localhost ~]# nmcli con show
NAME               UUID                                  TYPE      DEVICE
ens33   		   c96bc909-188e-ec64-3a96-6a90982b08ad  ethernet  ens33
enp125s0f2-static  67bd4764-8bb3-4f24-bac9-96846bb82da5  ethernet  enp125s0f2
enp195s0           32f13ac1-36b9-3bc8-a309-cab4e7bec22b  ethernet  enp195s0
enp125s0f0         083b6b6a-846a-383c-abc6-fef31bfdd5a2  ethernet  --
enp125s0f1         5e22ac44-6b93-3184-8057-3dca7bc6eae6  ethernet  --
enp125s0f2         518df144-9803-375b-bb9b-5de133b0afef  ethernet  --
enp125s0f3         a7b87189-1fe5-3cbc-ab12-3ace8e0b4768  ethernet  --
enp196s0           e59e0bec-2929-34e1-86a4-63716bf5328a  ethernet  --
enp197s0           0da38851-6036-3fc8-8ba7-4b371ca8875f  ethernet  --
enp198s0           7acde3cd-c62e-3aad-b190-111b94a6b3a0  ethernet  --
enp221s0f0         bfa541f6-3fa2-3808-92dd-356536c29681  ethernet  --

  • 配置自动获取IP地址的网络链接
[root@localhost ~]# nmcli connection add con-name ens33-dhcp type Ethernet ifname end33
连接“ens33-dhcp”(feda3ec2-e772-44f5-818b-74054c029ad4) 已成功添加。
  • 再次查看网络链接(#新添加的链接出现)
[root@localhost ~]# nmcli con show
NAME        UUID                                  TYPE      DEVICE 
ens33       c96bc909-188e-ec64-3a96-6a90982b08ad  ethernet  ens33  
ens33-dhcp  feda3ec2-e772-44f5-818b-74054c029ad4  ethernet  -- 
...
  • 测试这个IP是否可用
[root@localhost network-scripts]# nmcli connection down ens33 
成功取消激活连接 'ens33'(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/7)
[root@localhost network-scripts]# nmcli connection up ens33-dhcp 
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/9)
[root@localhost network-scripts]# ping www.baidu.com
PING www.baidu.com (61.135.169.125) 56(84) bytes of data.
64 bytes from www.baidu.com (61.135.169.125): icmp_seq=1 ttl=128 time=4.45 ms
64 bytes from www.baidu.com (61.135.169.125): icmp_seq=2 ttl=128 time=8.03 ms
64 bytes from www.baidu.com (61.135.169.125): icmp_seq=3 ttl=128 time=4.31 ms
64 bytes from www.baidu.com (61.135.169.125): icmp_seq=4 ttl=128 time=4.26 ms
^C
--- www.baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 4.264/5.267/8.035/1.601 ms
  • 进行静态网络地址链接的的设置和测试
[root@localhost network-scripts]# nmcli connection add con-name ens33-static ifname ens33 autoconnect yes type Ethernet ip4 192.168.19.254 gw4 192.168.19.2 ipv4.dns 114.114.114.114
连接“ens33-static”(989533fa-909f-47ea-82e7-38574535484c) 已成功添加。
  • 测试是否可用
[root@localhost network-scripts]# nmcli connection down ens33-dhcp 
成功取消激活连接 'ens33-dhcp'(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/9)

[root@localhost network-scripts]# nmcli connection up ens33-static 
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/11)
[root@localhost network-scripts]# ping www.baidu.com
PING www.baidu.com (61.135.169.121) 56(84) bytes of data.
64 bytes from www.baidu.com (61.135.169.121): icmp_seq=1 ttl=128 time=4.00 ms
64 bytes from www.baidu.com (61.135.169.121): icmp_seq=2 ttl=128 time=4.27 ms
...
# 静态网络链接成功

nmcli详细讲解请点击该链接

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值