O bonding é uma técnica que está se tornando cada vez mais popular entre os usuários do Linux, já que permite que o usuário use várias interfaces de rede em uma única interface lógica.
Como configurar um Network Bonding no CentOS 7
No exemplo abaixo, serão utilizadas três interfaces de rede do CentOS 7, nomeadas de:
- enp0s3;
- enp0s8;
- enp0s9.
Serão combinadas duas delas, (enp0s8 e enp0s9) e elas serão transformadas em outra interface, chamada bond0.
Configurando a interface bond0
No CentOS 7, o módulo para a realização do bonding não é carregado por padrão, então é necessário habilita-lo através do comando:
modprobe --first-time bonding
Para ver mais informações, você deverá usar o comando:
modinfo bonding
Exemplo:
filename: /lib/modules/3.10.0-123.el7.x86_64/kernel/drivers/net/bonding/bonding.ko alias: rtnl-link-bond author: Thomas Davis, tadavis@lbl.gov and many others description: Ethernet Channel Bonding Driver, v3.7.1 version: 3.7.1 license: GPL srcversion: E52AE00A79EA6FEFB5BF718 depends: intree: Y vermagic: 3.10.0-123.el7.x86_64 SMP mod_unload modversions signer: CentOS Linux kernel signing key sig_key: BC:83:D0:FE:70:C6:2F:AB:1C:58:B4:EB:AA:95:E3:93:61:28:FC:F4 sig_hashalgo: sha256 parm: max_bonds:Max number of bonded devices (int) parm: tx_queues:Max number of transmit queues (default = 16) (int) parm: num_grat_arp:Number of peer notifications to send on failover event (alias of num_unsol_na) (int) parm: num_unsol_na:Number of peer notifications to send on failover event (alias of num_grat_arp) (int) parm: miimon:Link check interval in milliseconds (int) parm: updelay:Delay before considering link up, in milliseconds (int) parm: downdelay:Delay before considering link down, in milliseconds (int) parm: use_carrier:Use netif_carrier_ok (vs MII ioctls) in miimon; 0 for off, 1 for on (default) (int) parm: mode:Mode of operation; 0 for balance-rr, 1 for active-backup, 2 for balance-xor, 3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, 6 for balance-alb (charp) parm: primary:Primary network device to use (charp) parm: primary_reselect:Reselect primary slave once it comes up; 0 for always (default), 1 for only if speed of primary is better, 2 for only on active slave failure (charp) parm: lacp_rate:LACPDU tx rate to request from 802.3ad partner; 0 for slow, 1 for fast (charp) parm: ad_select:803.ad aggregation selection logic; 0 for stable (default), 1 for bandwidth, 2 for count (charp) parm: min_links:Minimum number of available links before turning on carrier (int) parm: xmit_hash_policy:balance-xor and 802.3ad hashing method; 0 for layer 2 (default), 1 for layer 3+4, 2 for layer 2+3 (charp) parm: arp_interval:arp interval in milliseconds (int) parm: arp_ip_target:arp targets in n.n.n.n form (array of charp) parm: arp_validate:validate src/dst of ARP probes; 0 for none (default), 1 for active, 2 for backup, 3 for all (charp) parm: fail_over_mac:For active-backup, do not set all slaves to the same MAC; 0 for none (default), 1 for active, 2 for follow (charp) parm: all_slaves_active:Keep all frames received on an interfaceby setting active flag for all slaves; 0 for never (default), 1 for always. (int) parm: resend_igmp:Number of IGMP membership reports to send on link failure (int)
Agora, é a hora de criar a configuração. Vá até o diretório de lojas nos arquivos de configuração do CentOS. Por padrão, RHEL. Encontre o arquivo /etc/sysconfig/network-scripts/ e faça login como usuário administrador.
Crie o arquivo de configuração bond0:
vi /etc/sysconfig/network-scripts/ifcfg-bond0
E então, adicione as seguintes linhas:
DEVICE=bond0 NAME=bond0 TYPE=Bond BONDING_MASTER=yes IPADDR=192.168.1.150 PREFIX=24 ONBOOT=yes BOOTPROTO=none BONDING_OPTS="mode=1 miimon=100"
Nota: Aqui, BONDING_OPTS descreve o modo bonding. No seu caso, você estará configurando o mode1(backup-ativo). Salve e feche o arquivo. 192.168.1.150 é o endereço IP de bond0.
Configurando interfaces de rede
Agora, é a hora de modificar enp0s8 & enp0s9. Começando com enp0s8.
Edite o arquivo /etc/sysconfig/network-scripts/ifcfg-enp0s8:
vi /etc/sysconfig/network-scripts/ifcfg-enp0s8
Modifique inserindo as informações apresentadas abaixo:
HWADDR="08:00:27:04:03:86" TYPE="Ethernet" BOOTPROTO="none" DEFROUTE="yes" PEERDNS="yes" PEERROUTES="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_PEERDNS="yes" IPV6_PEERROUTES="yes" IPV6_FAILURE_FATAL="no" NAME="enp0s8" UUID="a97b23f2-fa87-49de-ac9b-39661ba9c20f" ONBOOT="yes" MASTER=bond0 SLAVE=yes
Então, edite o arquivo /etc/sysconfig/network-scripts/ifcfg-enp0s9,
vi /etc/sysconfig/network-scripts/ifcfg-enp0s9
Modifique-o com as informações apresentadas abaixo:
HWADDR=08:00:27:E7:ED:8E TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=enp0s9 UUID=e2352c46-e1f9-41d2-98f5-af24b127b3e7 ONBOOT=yes MASTER=bond0 SLAVE=yes
Salve e feche os arquivos.
Agora, é hora de ativar as interfaces. Use os comandos:
ifup ifcfg-enp0s8
ifup ifcfg-enp0s9
Agora, entre com o comando para recarregar e atualizar para aceitar as mudanças.
nmcli con reload
Reinicie o serviço de rede para que as mudanças tenham efeito.
systemctl restart network
Testando Network Bonding
Agora é hora de usar um comando para checar se a interface bond0 está funcionando:
cat /proc/net/bonding/bond0
Exemplo:
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: enp0s8 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: enp0s8 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 08:00:27:5d:ad:75 Slave queue ID: 0 Slave Interface: enp0s9 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 08:00:27:48:93:cd Slave queue ID: 0
Como é possível ver, a interface está funcionando e ativa, como apresentado em active-backup(mode1).
Para listar as interfaces de rede e seus IPS, entre com o comando:
ip addr
Exemplo:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:1f:3b:20 brd ff:ff:ff:ff:ff:ff inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic enp0s3 valid_lft 86130sec preferred_lft 86130sec inet6 fe80::a00:27ff:fe1f:3b20/64 scope link valid_lft forever preferred_lft forever 3: enp0s8: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000 link/ether 08:00:27:5d:ad:75 brd ff:ff:ff:ff:ff:ff 4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000 link/ether 08:00:27:5d:ad:75 brd ff:ff:ff:ff:ff:ff 5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether 08:00:27:5d:ad:75 brd ff:ff:ff:ff:ff:ff inet 192.168.1.150/24 brd 192.168.1.255 scope global bond0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe5d:ad75/64 scope link valid_lft forever preferred_lft forever
E é isso.
Configurando múltiplos IPs para bond0
Se desejar configurar vários IPs para a interface bond0, o processo é bastante simples. Deve ser criado um alias para bond0, copiando a configuração existente em ifcfg-bond0 para um novo arquivo de configurações em ifcfg-bond0:1.
cp /etc/sysconfig/network-scripts/ifcfg-bond0 /etc/sysconfig/network-scripts/ifcfg-bond0:1
Então, edite o arquivo /etc/sysconfig/network-scripts/ifcfg-bond0:1,
vi /etc/sysconfig/network-scripts/ifcfg-bond0:1
Modifique as opções "device" e IPADDR" mostradas como no exemplo abaixo:
DEVICE=bond0:1 NAME=bond0 TYPE=Bond BONDING_MASTER=yes IPADDR=192.168.1.151 PREFIX=24 ONBOOT=yes BOOTPROTO=none BONDING_OPTS="mode=1 miimon=100"
- bond0:1 – Nome do dispositivo
- 192.168.1.151 – Endereço IP de bond0:1
Salve e feche o arquivo. Reinicie o sistema para que as alterações tenham efeito.
systemctl restart network
Agora, é possível acessar a list das interfaces de rede e seus IPS através do comando:
ip addr
Exemplo:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:1f:3b:20 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic enp0s3
valid_lft 86388sec preferred_lft 86388sec
inet6 fe80::a00:27ff:fe1f:3b20/64 scope link
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
link/ether 08:00:27:5d:ad:75 brd ff:ff:ff:ff:ff:ff
4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
link/ether 08:00:27:5d:ad:75 brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 08:00:27:5d:ad:75 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.150/24 brd 192.168.1.255 scope global bond0
valid_lft forever preferred_lft forever
inet 192.168.1.151/24 brd 192.168.1.255 scope global secondary bond0:1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe5d:ad75/64 scope link
valid_lft forever preferred_lft forever