1. 程式人生 > >網絡配置多會話實驗

網絡配置多會話實驗

3.1 自動獲取 scrip 網卡 sse cfg roo method 網絡配置

  • nmcli配置多會話
  • 綁定兩塊網卡

    • 實驗1
      網卡支持多會話功能,由於工作環境不同,需要配置不同的網絡:如在家裏使用使用DHCP獲取,在公司使用固定ip,如果使用修改方式比較麻煩,配置多會話功能,在不同場景激活即可。
      實驗環境:
      centos7、home:DHCP、company:static,自動連接
      配置過程:配置信息會保存至/etc/sysconfig/network-scripts/ifcfg-name

      • 添加會話
        [root@xt ~]# nmcli connection add con-name company autoconnect yes ifname ens36 type ethernet 
        Connection ‘company‘ (46f14092-152e-4af3-9273-5acbf573b2a2) successfully added.
        [root@xt ~]# nmcli connection add con-name home autoconnect no ifname ens36 type ethernet 
        Connection ‘home‘ (d3c8a326-e494-47b9-b6ea-92f18998b9b6) successfully added.
        [root@xt ~]# nmcli connection show 
        NAME         UUID                                  TYPE            DEVICE      
        eno16777736  2361aff4-2de8-4868-9fd6-5d30ccdada02  802-3-ethernet  eno16777736 
        home         d3c8a326-e494-47b9-b6ea-92f18998b9b6  802-3-ethernet  --          
        company      46f14092-152e-4af3-9273-5acbf573b2a2  802-3-ethernet  ens36       
        [root@xt ~]# nmcli device status 
        DEVICE       TYPE      STATE      CONNECTION  
        eno16777736  ethernet  connected  eno16777736 
        ens36        ethernet  connected  company     
        lo           loopback  unmanaged  --          
      • 修改IP地址
        如果不修改默認為自動分配;
        [root@xt ~]# nmcli connection modify company ipv4.addresses 172.16.0.10/16 ipv4.method manual
        還可以配置DNS、gateway...

      • 查看效果
    [root@xt ~]# systemctl restart network #重啟服務 
    [root@xt ~]# nmcli device status  #ens36當前自動連接至company會話
    DEVICE       TYPE      STATE      CONNECTION  
    eno16777736  ethernet  connected  eno16777736 
    ens36        ethernet  connected  company     
    lo           loopback  unmanaged  --          
    
    [root@xt ~]# ifconfig ens36 #ens36的ip信息配置正常
    ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 172.16.0.10  netmask 255.255.0.0  broadcast 172.16.255.255
            inet6 fe80::20c:29ff:fe20:b507  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:20:b5:07  txqueuelen 1000  (Ethernet)
            RX packets 187  bytes 23730 (23.1 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 88  bytes 10998 (10.7 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    [root@xt ~]# nmcli connection up home  #將網卡會話切換至home會話
    Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
    
    [root@xt ~]# nmcli device status 
    DEVICE       TYPE      STATE      CONNECTION  
    eno16777736  ethernet  connected  eno16777736 
    ens36        ethernet  connected  home        #ens36當前會話狀態
    lo           loopback  unmanaged  --          
    
    [root@xt ~]# ifconfig ens36 #此時ip信息是自動獲取
    ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.175.133  netmask 255.255.255.0  broadcast 192.168.175.255
            inet6 fe80::20c:29ff:fe20:b507  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:20:b5:07  txqueuelen 1000  (Ethernet)
            RX packets 190  bytes 24476 (23.9 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 98  bytes 12306 (12.0 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    網絡配置多會話實驗