码迷,mamicode.com
首页 > Web开发 > 详细

[administrative][CentOS][NetworkManager] networkmanager (二)

时间:2018-04-10 17:44:56      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:cte   manage   ice   uuid   dea   设备   min   禁用   直接   

 

工程文档:

https://wiki.gnome.org/Projects/NetworkManager

RH admin 手册:

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/

nmcli使用手册:

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/sec-network_config_using_nmcli

 

基本理解之后,直接看help。主要是理解connect,device,等这些概念。

[root@D128 j]# nmcli help

 

接下来,做一个例子试一下:

增加一个tap设备:

[root@D128 j]# nmcli connection 
NAME   UUID                                  TYPE            DEVICE 
ens33  e4672331-0638-4db8-b818-d6ff50f901af  802-3-ethernet  ens33  
[root@D128 jcloud]# nmcli connection add type tun mode tap ifname tap-nlb con-name tap-nlb autoconnect yes save yes
Connection tap-nlb (b3e1db65-4821-4139-95f5-9cba4035ee08) successfully added.
[root@D128 j]# nmcli connection 
NAME     UUID                                  TYPE            DEVICE  
ens33    e4672331-0638-4db8-b818-d6ff50f901af  802-3-ethernet  ens33   
tap-nlb  b3e1db65-4821-4139-95f5-9cba4035ee08  tun             tap-nlb 
[root@D128 j]# 

 

生成的配置文件在这里:

[root@D128 j]# cat /etc/NetworkManager/system-connections/tap-nlb 
[connection]
id=tap-nlb
uuid=b3e1db65-4821-4139-95f5-9cba4035ee08
type=tun
interface-name=tap-nlb
permissions=

[tun]
mode=2

[ipv4]
dns-search=
method=auto

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto

修改禁用tap的DHCP:

[root@D128 ~]# nmcli connection modify tap-nlb ipv4.method link-local

删除tap连接设备:

[root@D128 ~]# nmcli connection delete tap-nlb 
Connection tap-nlb (b3e1db65-4821-4139-95f5-9cba4035ee08) successfully deleted.

连接在up/down的时候会自动增加或删除设备,可以用nmcli device 查看。

 

再来个例子,增加一个对外的网桥:

1。加网桥:

[root@D128 ~]# nmcli connection add type bridge ifname br-ext autoconnect yes save yes 
Connection bridge-br-ext (e886ae77-3a2c-4c93-aee0-4dea8b4d12a8) successfully added.
[root@D128 ~]# nmcli connection show
NAME           UUID                                  TYPE            DEVICE 
bridge-br-ext  e886ae77-3a2c-4c93-aee0-4dea8b4d12a8  bridge          br-ext 
ens33          e4672331-0638-4db8-b818-d6ff50f901af  802-3-ethernet  ens33  
[root@D128 ~]# nmcli device
DEVICE  TYPE      STATE                                  CONNECTION    
ens33   ethernet  connected                              ens33         
br-ext  bridge    connecting (getting IP configuration)  bridge-br-ext 
lo      loopback  unmanaged                              --      

 

2. 增加slave

[root@D128 ~]# nmcli connection add type bridge-slave ifname ens33 master br-ext

 

3. 切换连接,从网卡到bridge

[root@D128 jcloud]# nmcli connection down ens33
[root@D128 jcloud]# nmcli connection up bridge-slave-ens33

 

4.  删掉原理的connect

[root@D128 jcloud]# nmcli connection delete ens33 

5. reboot 测试

 

6 成功。networkmanager学会了还是蛮好用的

[root@D128 ~]# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br-ext state UP mode DEFAULT qlen 1000
    link/ether 00:0c:29:2f:cf:32 brd ff:ff:ff:ff:ff:ff
3: br-ext: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT qlen 1000
    link/ether 00:0c:29:2f:cf:32 brd ff:ff:ff:ff:ff:ff
[root@D128 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br-ext state UP qlen 1000
    link/ether 00:0c:29:2f:cf:32 brd ff:ff:ff:ff:ff:ff
3: br-ext: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether 00:0c:29:2f:cf:32 brd ff:ff:ff:ff:ff:ff
    inet 192.168.50.128/24 brd 192.168.50.255 scope global dynamic br-ext
       valid_lft 1771sec preferred_lft 1771sec
    inet6 fe80::1ecf:c3cc:4ff6:ef29/64 scope link 
       valid_lft forever preferred_lft forever
[root@D128 ~]# brctl show
bridge name    bridge id        STP enabled    interfaces
br-ext        8000.000c292fcf32    yes        ens33

 

另外:

  nmcli加的tap设备,在nmtui中是看不见的。也不能编辑。所以首选还是nmcli。

 

[administrative][CentOS][NetworkManager] networkmanager (二)

标签:cte   manage   ice   uuid   dea   设备   min   禁用   直接   

原文地址:https://www.cnblogs.com/hugetong/p/8780424.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!