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

網路配置多會話實驗

  • nmcli配置多會話
  • 繫結兩塊網絡卡

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

    • 新增會話
      [[email protected] ~]# nmcli connection add con-name company autoconnect yes ifname ens36 type ethernet 
      Connection 'company' (46f14092-152e-4af3-9273-5acbf573b2a2) successfully added.
      [
      [email protected]
      ~]# nmcli connection add con-name home autoconnect no ifname ens36 type ethernet Connection 'home' (d3c8a326-e494-47b9-b6ea-92f18998b9b6) successfully added. [[email protected] ~]# 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 [
      [email protected]
      ~]# nmcli device status DEVICE TYPE STATE CONNECTION eno16777736 ethernet connected eno16777736 ens36 ethernet connected company lo loopback unmanaged --
    • 修改IP地址
      如果不修改預設為自動分配;
      [[email protected] ~]# nmcli connection modify company ipv4.addresses 172.16.0.10/16 ipv4.method manual
      還可以配置DNS、gateway...

    • 檢視效果
      [[email protected] ~]# systemctl restart network #重啟服務 
      [[email protected] ~]# nmcli device status  #ens36當前自動連線至company會話
      DEVICE       TYPE      STATE      CONNECTION  
      eno16777736  ethernet  connected  eno16777736 
      ens36        ethernet  connected  company     
      lo           loopback  unmanaged  --          
      [[email protected] ~]# 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
      [[email protected] ~]# nmcli connection up home  #將網絡卡會話切換至home會話
      Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
      [[email protected] ~]# nmcli device status 
      DEVICE       TYPE      STATE      CONNECTION  
      eno16777736  ethernet  connected  eno16777736 
      ens36        ethernet  connected  home        #ens36當前會話狀態
      lo           loopback  unmanaged  --          
      [[email protected] ~]# 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