首頁>Club>
1
回覆列表
  • 1 # Wanggggjj

    linux相關網路介面配置

    在linux中網路介面的配置檔案一般都在一個檔案下,設定介面,裝置名,方案名,IP地址的獲取方式,開機時是否自動分配IP等等,這一切所有的設定都在配置檔案/etc/sysconfig/network-script下,想設定那個網絡卡找到其對應檔案即可編輯,說到網絡卡,在現實生活中為了提高網絡卡的冗餘性,以防單點故障的發生,我們通常要適應實際生活的需要,對網絡卡進行相關設定,接下來我們一起來熟悉一下相關命令。

    一、網絡卡本身相關命令

    ifconfig 檢視該虛擬機器上相關網絡卡的資訊

    如果ifconfig命令後什麼都不跟,那會顯示所有的網絡卡資訊,如果ifconfig後跟上裝置名,則顯示指定網絡卡的相關資訊。

    cd /etc/sysconfig/network-scripts 檢視該目錄下的配置檔案

    [root@localhost network-scripts]# cat ifcfg-eth0 eth0的詳細配置 DEVICE=eth0 裝置名 HWADDR=00:0C:29:6A:7A:68 該網絡卡的MAC地址 TYPE=Ethernet 裝置型別為Ethernet UUID=158888e2-4c5d-4859-8be8-903cee9f7c7a ONBOOT=yes 表示隨著網路服務的啟動,該網絡卡是否隨之啟動 NM_CONTROLLED=no 表示該網絡卡是否支援NetworkManager管理,預設yes表示支援,no代表不支援。 BOOTPROTO=dhcp|static|none 如刪除該行,則為手動設定 IPADDR=6.6.6.6 NETMASK=255.255.255.0 手動設定地址及掩碼 USERCTRL=yes 該網絡卡的開關是否被普通使用者所調整 PEERDNS=no 預設yes當該網絡卡啟動時,而PEERDNS=yes,則dns配置檔案中的dns會被該網絡卡的dns設定所覆蓋,若網絡卡是dhcp則被dhcp的設定覆蓋,若網絡卡是靜態地址,則被靜態配置的dns覆蓋

    給網絡卡設定別名

    [root@localhost network-scripts]# ifconfig eth0:0 172.17.2.241/24 [root@localhost network-scripts]# vim ifcfg-eth0:0 DEVICE=eth0:0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes HWADDR=00:0C:29:77:8E:C9 DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no IPADDR=172.17.2.241 NETMASK=255.255.255.0 NAME="System eth0"

    二、配置bond

    bond的配置主要是為了提高冗餘性,然而centos6上和centos7上bond的相關配置不太一樣,接下來分別展示。

    centos6上配置bond

    1、為虛擬機器再新增兩塊網絡卡。

    2、建立bond0檔案

    [root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-bond0 [root@localhost network-scripts]# vim ifcfg-bond0 DEVICE=bond0 裝置名修改為bond0 BONDING_OPTS="miimon=100 mode=1" bond此行是關鍵 TYPE=Ethernet IPADDR=20.20.20.6 NETMASK=255.255.255.0 ONBOOT=yes NM_CONTROLLED=no

    3、添加了兩塊網絡卡後,分別為eth2和eth3,它們是用來做slave的,複製後修改相關配置

    [root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-eth2 [root@localhost network-scripts]# vim ifcfg-eth2 DEVICE=eth2 TYPE=Ethernet ONBOOT=yes SLAVE=yes 重點行,同意為slave MASTER=bond0 管理者為bond0 NM_CONTROLLED=no [root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-eth3 [root@localhost network-scripts]# vim ifcfg-eth3 DEVICE=eth3 TYPE=Ethernet ONBOOT=yes SLAVE=yes 重點行,同意為slave MASTER=bond0 管理者為bond0 NM_CONTROLLED=no

    4、重啟網路服務

    [root@localhost network-scripts]# service network restart

    centos7配置bond

    1、增加兩個網絡卡

    2、增加bond的方案

    [root@localhost ~]#nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup

    3、增加slave的方案給兩塊新加的網絡卡

    [root@localhost ~]#nmcli connection add con-name slave-38 ifname ens38 type ethernet master bond0 [root@localhost ~]#nmcli connection add con-name slave-39 ifname ens39 type ethernet master bond0

    4、配置bond0

    [root@localhost ~]#nmcli connection modify bond0 ipv4.method manual connection.autoconnect yes ipv4.addresses 20.20.20.20/24 ipv4.dns 8.8.8.8 ipv4.gateway 20.20.20.1

    5、直接啟用bond0

    [root@localhost ~]#nmcli connection up bond0 Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/27) [root@localhost ~]#ifconfig bond0

    三、為一個網絡卡配置兩個方案

    1、修改舊的網絡卡名

    [root@localhost network-scripts]#nmcli connection modify ens33 connection.id class [root@localhost network-scripts]#mv ifcfg-ens33 ifcfg-class

    2、將class的方案設定自動獲取ipv4地址

    [root@localhost network-scripts]#nmcli connection modify class ipv4.method auto

    3、使方案生效

    [root@localhost network-scripts]#nmcli connection up class

    4、新增方案名為home

    [root@localhost network-scripts]#nmcli connection add con-name home type ethernet ifname ens33

    5、設定新增方案為靜態獲取地址

    [root@localhost network-scripts]#nmcli connection modify home ipv4.method manual connection.autoconnect yes ipv4.addresses 8.8.8.8/24 ipv4.gateway 8.8.8.1 ipv4.dns 4.4.4.4

    6、切換到新方案,使之生效

    [root@localhost network-scripts]#nmcli connection up home

    四、建立網路組(team)提高網絡卡效能

    1、建立team方案

    [root@localhost network-scripts]#nmcli connection add con-name team0 type team ifname team0 config "{"runner": {"name": "loadbalance"}}"

    2、建立slave的方案並指定master

    [root@localhost network-scripts]#nmcli connection add con-name slave-38 type team-slave ifname ens38 master team0 [root@localhost network-scripts]#nmcli connection add con-name slave-39 type team-slave ifname ens39 master team0

    3、設定team0的ip

    [root@localhost network-scripts]#nmcli connection modify team0 ipv4.method manual connection.autoconnect yes ipv4.addresses 20.20.20.20/24

    4、啟用team0及slave

    [root@localhost network-scripts]#nmcli connection up team0 [root@localhost network-scripts]#nmcli connection up slave-38 [root@localhost network-scripts]#nmcli connection up slave-39

    此時team已經建立成功。網絡卡配置相關介紹到此結束。

  • 中秋節和大豐收的關聯?
  • 惠而浦AWE8323的電腦板出現F5是什麼意思?