네트워크 본딩(Network Bonding)을 해보고 실제 본딩된 slave 인터페이스를 끊어도 네트워크가 잘 되는지 확인해보자.


환경

  • CentOS 7.7.1908
  • Ubuntu 18.04
  • VirtualBox
  • Bash shell(/bin/bash)


기본 네트워크 구조

  • NIC 2개를 본딩
  • 호스트 전용 어댑터(Host-only Adapter)를 통해 각 VM의 2개의 NIC는 vboxnet0에 연결됨
  • VirtualBox에서 설정-네트워크에서 어댑터1에는 기존 NAT를 연결
  • VirtualBox에서 설정-네트워크에서 어댑터2와 어댑터3를 새로 연결


시나리오

  1. Client에서 Server에 Bonding된 IP주소로 Ping을 보낸다.
  2. Server의 active slave를 Down으로 만든다.
  3. 끊기지 않고 Ping이 계속 가는지 확인한다.


네트워크 본딩 설정

CentOS

centos-client

  • bond0
  • /etc/sysconfig/network-scripts/ifcfg-bond0
TYPE=Bond
BOOTPROTO=static
DEFROUTE=no
NAME=bond0
DEVICE=bond0
ONBOOT=yes
PREFIX=24
IPADDR=192.168.99.101
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1"
  • enp0s8
  • /etc/sysconfig/network-scripts/ifcfg-enp0s8
NAME=enp0s8
DEVICE=enp0s8
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
  • enp0s9
  • /etc/sysconfig/network-scripts/ifcfg-enp0s9
NAME=enp0s9
DEVICE=enp0s9
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes

centos-server

  • bond0
  • /etc/sysconfig/network-scripts/ifcfg-bond0
TYPE=Bond
BOOTPROTO=static
DEFROUTE=no
NAME=bond0
DEVICE=bond0
ONBOOT=yes
PREFIX=24
IPADDR=192.168.99.102
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1"
  • enp0s8
  • /etc/sysconfig/network-scripts/ifcfg-enp0s9
NAME=enp0s8
DEVICE=enp0s8
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
  • enp0s9
  • /etc/sysconfig/network-scripts/ifcfg-enp0s9
NAME=enp0s9
DEVICE=enp0s9
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes


Ubuntu

  • 18.04는 netplan을 이용해 네트워크를 세팅한다.
  • yaml 파일을 만들고 sudo netplan apply를 통해서 네트워크 설정들을 적용

ubuntu-client

  • /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            dhcp4: true
        enp0s8:
            dhcp4: false
        enp0s9:
            dhcp4: false
    version: 2
    bonds:
        bond0:
            dhcp4: false
            addresses:
                - 192.168.225.101/24
            gateway4: 192.168.225.1
            interfaces:
                - enp0s8
                - enp0s9
            parameters:
                mode: active-backup
                primary: enp0s8
                fail-over-mac-policy: active
                mii-monitor-interval: 100

ubuntu-server

  • /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            dhcp4: true
        enp0s8:
            dhcp4: false
        enp0s9:
            dhcp4: false
    version: 2
    bonds:
        bond0:
            dhcp4: false
            addresses:
                - 192.168.225.102/24
            gateway4: 192.168.225.1
            interfaces:
                - enp0s8
                - enp0s9
            parameters:
                mode: active-backup
                primary: enp0s8
                fail-over-mac-policy: active
                mii-monitor-interval: 100


테스트

각각 active slave 확인

  • 명령어: cat /proc/net/bonding/bond0
  • 왼쪽이 Client 오른쪽이 Server
  • Active slave: enp0s8


Client -> Server ping 시작



Ping이 끊기지 않고 제대로 가는지 확인


Server에서 active slave가 누군지 확인

  • enp0s8 -> enp0s9


참고자료

Make network bonding and test if it is still work even though active slave is down.


Environment and Prerequisite

  • CentOS 7.7.1908
  • Ubuntu 18.04
  • VirtualBox
  • Bash shell(/bin/bash)


Basic Network Structure

  • Bond two NICs
  • By using Host-only Adapter, each VM’s two NICs are connected to vboxnet0
  • In VirtualBox Settings-Network, Adapter 1 is connected to default NAT.
  • In VirtualBox Settings-Network, add new two adapters Adapter 2 and Adapter 3.


Scenario

  1. Ping to bonding interface’s IP address from Client to Server.
  2. Make active slave to Down in Server.
  3. Check ping is still going well.


Network Bonding Setting

CentOS

centos-client

  • bond0
  • /etc/sysconfig/network-scripts/ifcfg-bond0
TYPE=Bond
BOOTPROTO=static
DEFROUTE=no
NAME=bond0
DEVICE=bond0
ONBOOT=yes
PREFIX=24
IPADDR=192.168.99.101
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1"
  • enp0s8
  • /etc/sysconfig/network-scripts/ifcfg-enp0s8
NAME=enp0s8
DEVICE=enp0s8
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
  • enp0s9
  • /etc/sysconfig/network-scripts/ifcfg-enp0s9
NAME=enp0s9
DEVICE=enp0s9
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes

centos-server

  • bond0
  • /etc/sysconfig/network-scripts/ifcfg-bond0
TYPE=Bond
BOOTPROTO=static
DEFROUTE=no
NAME=bond0
DEVICE=bond0
ONBOOT=yes
PREFIX=24
IPADDR=192.168.99.102
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1"
  • enp0s8
  • /etc/sysconfig/network-scripts/ifcfg-enp0s9
NAME=enp0s8
DEVICE=enp0s8
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
  • enp0s9
  • /etc/sysconfig/network-scripts/ifcfg-enp0s9
NAME=enp0s9
DEVICE=enp0s9
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes


Ubuntu

  • 18.04 use netplan to set network.
  • Make yaml file and apply it using sudo netplan apply command

ubuntu-client

  • /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            dhcp4: true
        enp0s8:
            dhcp4: false
        enp0s9:
            dhcp4: false
    version: 2
    bonds:
        bond0:
            dhcp4: false
            addresses:
                - 192.168.225.101/24
            gateway4: 192.168.225.1
            interfaces:
                - enp0s8
                - enp0s9
            parameters:
                mode: active-backup
                primary: enp0s8
                fail-over-mac-policy: active
                mii-monitor-interval: 100

ubuntu-server

  • /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            dhcp4: true
        enp0s8:
            dhcp4: false
        enp0s9:
            dhcp4: false
    version: 2
    bonds:
        bond0:
            dhcp4: false
            addresses:
                - 192.168.225.102/24
            gateway4: 192.168.225.1
            interfaces:
                - enp0s8
                - enp0s9
            parameters:
                mode: active-backup
                primary: enp0s8
                fail-over-mac-policy: active
                mii-monitor-interval: 100


Test

Check each active slave

  • Command: cat /proc/net/bonding/bond0
  • Left is Client and right is Server
  • Active slave: enp0s8


Start ping Client -> Server



Check ping is going well


Check which one is active slave in Server

  • enp0s8 -> enp0s9


Reference

네트워크 본딩(Network Bonding)을 할 때 active-backup 모드에서 fail_over_mac 옵션에 대해 알아보자


환경

  • CentOS 7.7.1908
  • Bash shell(/bin/bash)
  • Network bonding


fail_over_mac 옵션

fail_over_mac 옵션이란


fail_over_mac 옵션 종류

  • none or 0: (Default) bond된 인터페이스와 모든 slave 인터페이스들의 MAC이 같은 값으로 설정되는 옵션으로 보통 가장 첫번째 slave 인터페이스의 MAC 주소를 모든 bond된 인터페이스와 slave 인터페이스들이 갖는다.
  • active or 1: active 상태인 slave 인터페이스의 MAC 주소를 bond된 인터페이스의 MAC으로 설정하는 옵션으로 failover된 상황에서 active 상태인 slave에 따라에 bond된 인터페이스의 MAC 주소가 달라진다.
  • follow or 2: bond된 인터페이스의 MAC 주소는 고정이고(보통 첫번째 slave 인터페이스의 MAC 주소를 갖는다.) active 상태가 되는 slave 인터페이스 MAC 주소에 해당 MAC 주소를 부여하는 방식이다. failover가 일어날때 새로 active 상태가 될 인터페이스의 MAC 주소를 이전의 active 상태였던 인터페이스에 부여하고 bond된 인터페이스의 MAC을 받는다.


fail_over_mac 옵션 예제

예제 실행 환경

  • 해당 예제의 Bonding 설정은 하단 (참고) Bonding 설정에 있습니다.
  • Host OS: Mac OS
  • Guest OS: CentOS 7.7.1908
  • Hypervisor: VirtualBox


none or 0 옵션 예제

  • Default option
  • fail_over_mac=0
  • VirtualBox에서는 해당 옵션으로 설정하면 active-backup이 잘 안되는 이슈가 있음.
[root@centos-client ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 | grep fail_over_mac
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=0"
  • bond0와 slave들(enp0s8과 enp0s9)의 MAC 주소가 동일
[root@centos-client ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:2b:04:6e brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
8: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff


active or 1 옵션 예제

  • fail_over_mac=1
[root@centos-client ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 | grep fail_over_mac
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1"
  • bond0의 MAC 주소와 첫번째 slave인 enp0s8의 MAC 주소가 동일
[root@centos-client ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:2b:04:6e brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:27:a9:2d brd ff:ff:ff:ff:ff:ff
9: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
  • enp0s8 인터페이스 Down
ip link set dev enp0s8 down
  • bond0의 MAC 주소가 enp0s9의 MAC 주소로 변경됨
[root@centos-client ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:2b:04:6e brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:27:a9:2d brd ff:ff:ff:ff:ff:ff
9: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:27:a9:2d brd ff:ff:ff:ff:ff:ff


follow or 2 옵션 예제

  • fail_over_mac=2
  • VirtualBox에서는 해당 옵션으로 설정하면 active-backup이 잘 안되는 이슈가 있음.
[root@centos-client ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 | grep fail_over_mac
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=2"
  • bond0의 MAC 주소와 첫번째 slave인 enp0s8의 MAC 주소가 동일
[root@centos-client ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:2b:04:6e brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:27:a9:2d brd ff:ff:ff:ff:ff:ff
10: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
  • enp0s8 인터페이스 Down
ip link set dev enp0s8 down
  • bond0의 MAC 주소는 이전과 동일
  • 새로 active 상태가 된 enp0s9 인터페이스에 bond0의 MAC 주소가 할당됨
  • fail이 일어난 enp0s8 인터페이스에는 새로 active 상태가 된 enp0s9 인터페이스의 예전 MAC 주소가 할당됨
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:2b:04:6e brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 08:00:27:27:a9:2d brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
10: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff


(참고) Bonding 설정

  • 기본적인 본딩 설정은 아래와 같습니다.

Interfaces

  • Bonding Interface: bond0
  • Slave Interfaces: enp0s8, enp0s9

bond0

  • /etc/sysconfig/network-scripts/ifcfg-bond0
  • IPADDRPREFIX는 환경에 따라 다를 수 있습니다.
  • fail_over_mac 옵션은 0~2까지 다르게 설정 가능합니다.
TYPE=Bond
BOOTPROTO=static
DEFROUTE=no
NAME=bond0
DEVICE=bond0
ONBOOT=yes
PREFIX=24
IPADDR=192.168.99.101
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1"

enp0s8, enp0s9

  • /etc/sysconfig/network-scripts/ifcfg-enp0s8
NAME=enp0s8
DEVICE=enp0s8
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
  • /etc/sysconfig/network-scripts/ifcfg-enp0s9
NAME=enp0s9
DEVICE=enp0s9
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes


참고자료

About fail_over_mac option in network bonding active-backup mode


Environment and Prerequisite

  • CentOS 7.7.1908
  • Bash shell(/bin/bash)
  • Network bonding


fail_over_mac option

About fail_over_mac option


fail_over_mac option types

  • none or 0: (Default) This setting disables fail_over_mac and sets all of the bond and slave interfaces to the same MAC address. Usually first slave’s MAC address is allocated to all bond and slave interfaces.
  • active or 1: The bond interface’s MAC address is always the MAC address of the active slave interface. If the active slave interface is changed during a failover, the bond interface’s MAC address is then changed to match the new active slave’s MAC address.
  • follow or 2: The bond interface’s MAC address is fixed(Usually first slave’s MAC address is allocated) and it gives its MAC address to newly active slave interface. If the slave is changed during a failover, the active slave will get the MAC address of the bond interface and the formerly active slave interface receives the newly active slave’s MAC address.


fail_over_mac option examples

Example running environment

  • Example bonding setting is in (Ref) Bonding Setting
  • Host OS: Mac OS
  • Guest OS: CentOS 7.7.1908
  • Hypervisor: VirtualBox


none or 0 option example

  • Default option
  • fail_over_mac=0
  • In VirtualBox environment, it is not work well.
[root@centos-client ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 | grep fail_over_mac
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=0"
  • bond0’s and slaves’(enp0s8 and enp0s9) MAC addresses are same.
[root@centos-client ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:2b:04:6e brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
8: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff


active or 1 option example

  • fail_over_mac=1
[root@centos-client ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 | grep fail_over_mac
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1"
  • bond0’s MAC address and first slave’s(enp0s8) MAC address are same.
[root@centos-client ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:2b:04:6e brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:27:a9:2d brd ff:ff:ff:ff:ff:ff
9: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
  • Link down enp0s8 interface
ip link set dev enp0s8 down
  • bond0’s MAC address is changed to enp0s9’s MAC address.
[root@centos-client ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:2b:04:6e brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:27:a9:2d brd ff:ff:ff:ff:ff:ff
9: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:27:a9:2d brd ff:ff:ff:ff:ff:ff


follow or 2 option example

  • fail_over_mac=2
  • In VirtualBox environment, it is not work well.
[root@centos-client ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0 | grep fail_over_mac
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=2"
  • bond0’s MAC address and first slave’s(enp0s8) MAC address are same.
[root@centos-client ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:2b:04:6e brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:27:a9:2d brd ff:ff:ff:ff:ff:ff
10: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
  • Link down enp0s8 interface
ip link set dev enp0s8 down
  • bond0’s MAC address is same as before.
  • bond0’s MAC address is allocated to newly active slave(enp0s9)
  • enp0s9’s previous MAC address is moved to enp0s8’s MAC address which is failed.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:2b:04:6e brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,SLAVE> mtu 1500 qdisc pfifo_fast master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 08:00:27:27:a9:2d brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff
10: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:e8:26:58 brd ff:ff:ff:ff:ff:ff


(Ref) Bonding Setting

  • Basic bonding settings are like below.

Interfaces

  • Bonding Interface: bond0
  • Slave Interfaces: enp0s8, enp0s9

bond0

  • /etc/sysconfig/network-scripts/ifcfg-bond0
  • IPADDR and PREFIX could be different.
  • fail_over_mac can set be from 0 to 2.
TYPE=Bond
BOOTPROTO=static
DEFROUTE=no
NAME=bond0
DEVICE=bond0
ONBOOT=yes
PREFIX=24
IPADDR=192.168.99.101
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1"

enp0s8, enp0s9

  • /etc/sysconfig/network-scripts/ifcfg-enp0s8
NAME=enp0s8
DEVICE=enp0s8
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
  • /etc/sysconfig/network-scripts/ifcfg-enp0s9
NAME=enp0s9
DEVICE=enp0s9
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes


Reference

vi 또는 vim에서 문자열들을 원하는 문자열로 바꿔보자.


환경

  • Linux 기반 시스템
  • Bash shell(/bin/bash)
  • vi 또는 vim


vi(또는 vim) 문자열 치환

기본형

형식

:%s/[원래문자열]/[바꿀문자열]/[옵션]
  • 위와 같은 형식으로 다양한 옵션과 함께 사용 가능
  • 옵션은 하나만 사용하는게 아니라 혼합해서 같이 사용 가능
  • 위 명령어에서 %를 제외하면 현재 커서가 위치한 줄에서만 치환을 합니다.

옵션

  • g: 해당 문자열에 해당하는 문자열들을 모두 치환하는 옵션
ThisThisThis -> testtesttest
:%s/This/test/g
  • c: 치환하기 전에 매번 치환할지 확인하는 옵션
ThisThisThis -> testThisThis
~
replace with test (y/n/a/q/l/^E/^Y)?y
:%s/This/test/c
  • i: 대소문자를 구분하지 않는 옵션
ThistHisthIs -> testtesttest
:%s/This/test/ig


예제

  • 테스트에 사용할 예제 작성
$ vi test.txt
This is test string. This is it!
This is second string.

예제 0 - 현재 줄에서 첫 ‘This’를 ‘tHIS’로 치환

  • 다음 아래처럼 %를 제외하고 하면 됩니다.
tHIS is test string. This is it!
This is second string.
~
~
:s/This/tHIS

예제 1 - 각 줄의 첫 ‘This’를 ‘tHIS’로 치환

  • 아무 옵션이 없다면 하나의 줄에서 해당 문자열을 찾으면 치환하고 다음 문자열로 넘어갑니다. 즉, 뒤에 동일하게 맞는 문자열이 있더라도 넘어가게 됩니다.
tHIS is test string. This is it!
tHIS is second string.
~
~
:%s/This/tHIS

예제 2 - 문서 전체의 ‘This’를 ‘tHIS’로 치환

  • g 옵션을 이용해 전체에서 해당하는 문자열을 모두 치환할 수 있다.
tHIS is test string. tHIS is it!
tHIS is second string.
~
~
:%s/This/tHIS/g

예제 3 - 매번 치환할 때 확인해서 바꾸기

  • c 옵션을 사용해 매번 확인 가능
  • g 옵션을 함께 이용해 문서 전체에서 바꾸도록 설정
  • 해당 예제에서는 y->n->y로 입력해서 순서대로 치환
this is test string. This is it!
this is second string.
~
~
replace with test (y/n/a/q/l/^E/^Y)?y
:%s/This/tHIS/cg

예제 4 - 대소문자 구분없이 문서 전체에서 ‘This’를 ‘tHIS’로 치환

  • i 옵션을 이용해 대소문자를 구분하지 않으면서 g 옵션을 이용해 전체에서 해당하는 문자열을 모두 치환
tHIS is test string. tHIS is it!
tHIS is second string.
~
~
:%s/this/tHIS/ig


참고자료