Create, list and delete EC2 instance using AWS CLI


Environment and Prerequisite

  • Ubuntu 18.04
  • AWS CLI
  • Bash shell(/bin/bash)


Process

  1. Install AWS CLI
  2. Basic Setting(Configuration and Credential File Settings)
  3. EC2 Instance Create, List and Delete


Install AWS CLI

Package update and upgrade

sudo apt-get update -y && sudo apt-get upgrade -y

Install pip3

sudo apt-get install python3-pip

Install AWS CLI

  • Logout and login again if aws command is not work.
pip3 install awscli --upgrade --user

Check AWS CLI version

$ aws --version
aws-cli/1.16.310 Python/3.6.9 Linux/4.15.0-72-generic botocore/1.13.46


Basic Setting(Configuration and Credential File Settings)

Before setting

aws configure

$ aws configure
AWS Access Key ID [None]: [YOUR KEY]
AWS Secret Access Key [None]: [YOUR KEY]
Default region name [None]: ap-northeast-2
Default output format [None]: json

Check ~/.aws/credentials setting

$ cat ~/.aws/credentials
[default]
aws_access_key_id = [YOUR KEY]
aws_secret_access_key = [YOUR KEY]

Check ~/.aws/config 설정 확인 setting

$ cat ~/.aws/config
[default]
region = ap-northeast-2
output = json


EC2 Instance Create, List and Delete

Before setting

  • Consider that there is already made EC2 security group
  • You can make security group in aws website. My security group opens only ssh port in inbound and opens all ports in outbound.

Create key pair

  • Store key pair in your computer which is made from below command.
  • You can use your own key pair. However, public key should be in AWS and private key should be kept in your computer.
aws ec2 create-key-pair --key-name TestKeyPair --query 'KeyMaterial' --output text > TestKeyPair.pem

Create EC2 instance

  • --image-id: Instance image ID
  • ami-082bdb3b2d54d5a19: Ubuntu Server 16.04 LTS (HVM), SSD Volume Type
  • --count: Number of instances
  • --key-name: Key pair key
  • TestKeyPair: The key pair that we made above
  • --security-group-ids: Security group ID
aws ec2 run-instances --image-id ami-082bdb3b2d54d5a19 --count 1 --instance-type t2.micro --key-name TestKeyPair --security-group-ids [YOUR SECURITY GROUP ID]

List EC2 instances

  • --filters: It is filter for instances. In this example, it gets instances of which instance-type is t2.micro.
  • --query: It is option for showing results of instances. In this example, it shows only ID of instances.
aws ec2 describe-instances --filters "Name=instance-type,Values=t2.micro" --query "Reservations[].Instances[].InstanceId"

Connect to EC2 instance

  • Set key file permission
chmod 400 TestKeyPair.pem
  • Access to instance using ssh
ssh -i "TestKeyPair.pem" [USER NAME]@[PUBLIC IP or PUBLIC AWS DNS]

Delete EC2 instance

  • --instance-ids: Delete using instance ID
aws ec2 terminate-instances --instance-ids [YOUR INSTANCE ID]


Reference

네트워크 본딩(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