1 Ubuntu网络配置
1.1 主机名
修改主机名 和centos7一样 修改后永久生效
root@ubuntu:~# hostnamectl set-hostname ubuntu2004.waluna.top
root@ubuntu:~# cat /etc/hostname
ubuntu2004.waluna.top
root@ubuntu:~# hostname
ubuntu2004.waluna.top
root@ubuntu:~# echo $HOSTNAME
ubuntu
root@ubuntu:~# exit
logout
ubuntu@ubuntu:~$ sudo -i
root@ubuntu2004:~# echo $HOSTNAME
ubuntu2004.waluna.top
1.2 网卡名称
默认ubuntu的网卡名称和centos7类似,如:ens33,ens38等
修改网卡名称为传统命名方式:
# 修改配置文件为下面形式
root@ubuntu2004:~# vim /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0"
# 或者sed修改
root@ubuntu2004:~# sed -i.bak '/^GRUB_CMDLINE_LINUX=/s#"$#net.ifnames=0"#' /etc/default/grub
# 生效新的grub.cfg文件
root@ubuntu2004:~# grub-mkconfig -o /boot/grub/grub.cfg
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-112-generic
Found initrd image: /boot/initrd.img-4.15.0-112-generic
done
# 或者
root@ubuntu2004:~# update-grub
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-112-generic
Found initrd image: /boot/initrd.img-4.15.0-112-generic
done
root@ubuntu2004:~# grep net.ifnames /boot/grub/grub.cfg
linux /boot/vmlinuz-4.15.0-112-generic root=UUID=eb982e5d-8588-4714-92ac-bb09908d16c8 ro net.ifnames=0
linux /boot/vmlinuz-4.15.0-112-generic root=UUID=eb982e5d-8588-4714-92ac-bb09908d16c8 ro net.ifnames=0
linux /boot/vmlinuz-4.15.0-112-generic root=UUID=eb982e5d-8588-4714-92ac-bb09908d16c8 ro recovery nomodeset net.ifnames=0
# 重启生效
root@ubuntu2004:~# reboot
1.3 Ubuntu网卡配置
官网文档:
https://ubuntu.com/server/docs/network-configuration
1.3.1 配置自动获取IP
网卡配置文件才用YAML格式,必须以/etc/netplan/xxx.yaml文件命名方式存放
可以每个网卡对应一个单独的配置文件,也可以将所有网卡都放在一个配置文件里
root@ubuntu2004:~# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
修改网卡配置文件后需执行命令生效:
root@ubuntu2004:~# netplan apply
1.3.2 配置静态IP
root@ubuntu2004:~# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresss: [192.168.8.10/24,10.0.0.10/8] # 或者用下面两行,两种格式不能混用
- 10.0.0.129/24
- 192.168.8.10/24
gateway4: 10.0.0.2
nameservers:
search: [waluna.top,waluna.xyz]
addresses: [114.114.114.114,8.8.8.8]
查看IP和gateway
root@ubuntu2004:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:93:a6:2e brd ff:ff:ff:ff:ff:ff
inet 10.0.0.129/24 brd 10.0.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe93:a62e/64 scope link
valid_lft forever preferred_lft forever
root@ubuntu2004:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
查看DNS
root@ubuntu2004:~# ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Mar 17 02:37 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
root@ubuntu2004:~# systemd-resolve --status
Global
DNSSEC NTA: 10.in-addr.arpa
16.172.in-addr.arpa
168.192.in-addr.arpa
17.172.in-addr.arpa
18.172.in-addr.arpa
19.172.in-addr.arpa
20.172.in-addr.arpa
21.172.in-addr.arpa
22.172.in-addr.arpa
23.172.in-addr.arpa
24.172.in-addr.arpa
25.172.in-addr.arpa
26.172.in-addr.arpa
27.172.in-addr.arpa
28.172.in-addr.arpa
29.172.in-addr.arpa
30.172.in-addr.arpa
31.172.in-addr.arpa
corp
d.f.ip6.arpa
home
internal
intranet
lan
local
private
test
Link 2 (eth0)
Current Scopes: DNS
LLMNR setting: yes
MulticastDNS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 114.114.114.114
8.8.8.8
1.3.3 配置多网卡静态IP和静态路由
root@ubuntu2004:~# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 10.0.0.129/24
gateway4: 10.0.0.2
nameservers:
addresses: [114.114.114.114,8.8.8.8]
eth1:
dhcp4: no
dhcp6: no
addresses: [10.20.0.100/16]
routes:
- to: 10.30.0.0/16
via: 10.20.0.1
- to: 10.40.0.0/16
via: 10.20.0.1
root@ubuntu2004:~# netplan apply
root@ubuntu2004:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.20.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
10.30.0.0 10.20.0.1 255.255.0.0 UG 0 0 0 eth1
10.40.0.0 10.20.0.1 255.255.0.0 UG 0 0 0 eth1
# 或者每个网卡各自一个配置文件
root@ubuntu2004:/etc/netplan# cat 01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 10.0.0.129/24
gateway4: 10.0.0.2
nameservers:
addresses: [114.114.114.114,8.8.8.8]
root@ubuntu2004:/etc/netplan# cat 02-eth1.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: no
dhcp6: no
addresses: [10.20.0.100/16]
routes:
- to: 10.30.0.0/16
via: 10.20.0.1
- to: 10.40.0.0/16
via: 10.20.0.1
1.3.4 单网卡桥接
root@ubuntu2004:~# apt install bridge-utils -y
root@ubuntu2004:~# dpkg -L bridge-utils
/.
/etc
/etc/default
/etc/default/bridge-utils
/etc/network
/etc/network/if-post-down.d
/etc/network/if-pre-up.d
/lib
/lib/bridge-utils
/lib/bridge-utils/bridge-utils.sh
/lib/bridge-utils/ifupdown.sh
/lib/udev
/lib/udev/bridge-network-interface
/lib/udev/rules.d
/lib/udev/rules.d/60-bridge-network-interface.rules
/sbin
/sbin/brctl
......
# 三个网卡使用一个配置文件
root@ubuntu2004:~# cat /etc/netplan/02-eth.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: no
eth2:
dhcp4: no
dhcp6: no
eth3:
dhcp4: yes
bridges:
br0:
dhcp4: no
dhcp6: no
addresses: [10.0.0.18/16]
gateway4: 10.0.0.2
nameservers:
addresses: [114.114.114.114]
interfaces:
- eth1
- eth2
# 桥接配置单独一个文件
root@ubuntu2004:~# cat /etc/netplan/02-eth.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: no
eth2:
dhcp4: no
dhcp6: no
bridges:
br0:
dhcp4: no
dhcp6: no
addresses: [10.0.0.18/16]
gateway4: 10.0.0.2
nameservers:
addresses: [114.114.114.114]
interfaces:
- eth1
- eth2
root@ubuntu2004:~# netplan apply
root@ubuntu2004:~# ifconfig br0
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.18 netmask 255.255.0.0 broadcast 10.0.255.255
inet6 fe80::d8fb:cbff:fe5b:bf07 prefixlen 64 scopeid 0x20<link>
ether da:fb:cb:5b:bf:07 txqueuelen 1000 (Ethernet)
RX packets 188260 bytes 13149506 (13.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 67 bytes 5754 (5.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@ubuntu2004:~# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.dafbcb5bbf07 no eth1
eth2
1.3.5 多网卡桥接
root@ubuntu2004:~# cat /etc/netplan/02-eth.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: no
eth2:
dhcp4: no
dhcp6: no
eth3:
dhcp4: yes
bridges:
br0:
dhcp4: no
dhcp6: no
addresses: [10.0.0.18/16]
gateway4: 10.0.0.2
nameservers:
addresses: [114.114.114.114]
interfaces:
- eth1
br1:
dhcp4: no
dhcp6: no
addresses: [10.10.0.18/16]
interfaces:
- eth2
routes:
- to: 10.4.0.0/16
via: 10.10.0.1
- to: 10.50.0.0/16
via: 10.10.0.1
root@ubuntu2004:~# netplan apply
root@ubuntu2004:~# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.dafbcb5bbf07 no eth1
br1 8000.9eff5dce92e5 no eth2
root@ubuntu2004:~# ifconfig br0
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.18 netmask 255.255.0.0 broadcast 10.0.255.255
inet6 fe80::d8fb:cbff:fe5b:bf07 prefixlen 64 scopeid 0x20<link>
ether da:fb:cb:5b:bf:07 txqueuelen 1000 (Ethernet)
RX packets 2346919 bytes 168095954 (168.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 318 bytes 27324 (27.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@ubuntu2004:~# ifconfig br1
br1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.10.0.18 netmask 255.255.0.0 broadcast 10.10.255.255
inet6 fe80::9cff:5dff:fece:92e5 prefixlen 64 scopeid 0x20<link>
ether 9e:ff:5d:ce:92:e5 txqueuelen 1000 (Ethernet)
RX packets 15 bytes 1206 (1.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 656 (656.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@ubuntu2004:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 br0
0.0.0.0 10.0.0.2 0.0.0.0 UG 100 0 0 eth3
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth3
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br0
10.0.0.2 0.0.0.0 255.255.255.255 UH 100 0 0 eth3
10.4.0.0 10.10.0.1 255.255.0.0 UG 0 0 0 br1
10.10.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br1
10.50.0.0 10.10.0.1 255.255.0.0 UG 0 0 0 br1
1.3.6 双网卡绑定
支持多网卡绑定七种模式
第一种模式: mod=0,即: (balance-rr) Round-robin policy(平衡抡循环策略)
特点:传输数据包顺序是依次传输〈即:第1个包走eth0,下一个包就走eth1...一直循环下去,直到最后一个传输完毕),此模式提供负载平衡和容错能力。
第二种模式: mod=1,即: (active-backup) Active-backup policy (主-备份策略)
特点:只有一个设备处于活动状态,当一个宕掉另一个马上由备份转换为主设备。mac地址是外部可见得,从外面看来,bond的MAc地址是唯一的,以避免switch(交换机)发生混乱。此模式只提供了容错能力;由此可见此算法的优点是可以提供网络连接的可用性,但是它的资源利用率较低,只有一个接口处于工作状态,在有N个网络接口的情况下,资源利用率为1/N.
第三种模式: mod=2,即:(balance-xor) xoR policy(平衡策略)
特点:基于指定的传输HASH策略传输数据包。缺省的策略是:(源MAc地址 XOR目标MAC地址)% slave数量。其他的传输策略可以通过xmit_hash_policy选项指定,此模式提供负载平衡和容错能力。
第四种模式: mod=3,即:broadcast(广播策略)
特点:在每个slave接口上传输每个数据包,此模式提供了容错能力。
第五种模式: mod=4,即:(802.3ad)IEEE 802. 3ad Dynamic link aggregation(IEEE802 .3ad动态链接聚合)
特点:创建一个聚合组,它们共享同样的速率和双工设定。根据802.3ad规范将多个slave工作在同一个激活的聚合体下。
必要条件:
条件1: ethtool持获取每个slave的速率和双工设定。
条件2: switch(交换机)支持IEEE 802.3ad Dynamic link aggregation.
条件3:多数switch(交换机)需要经过特定配置才能支持802.3ad模式。
第六种模式: mod=5,即: (balance-t1b) Adaptive transmit load balancing(适配器传输负载均衡)
特点:不需要任何特别的switch(交换机)支持的通道bonding。在每个slave上根据当前的负载〈根据速度计算〉分配外出流量。如果正在接受数据的slave出故障了,另一个slave接管失败的slave的MAC地址。该模式的必要条件:
ethtool支持获取每个slave的速率
第七种模式: mod=6,即: (balance-a7b) Adaptive load balancing(适配器适应性负载均衡)
特点:该模式包含了balance-tlb模式,同时加上针对IPV4流量的接收负载均衡(receive loadbalance, rlb),而且不需要任何switch(交换机)的支持。
root@ubuntu2004:~# cat /etc/netplan/02-eth.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: no
eth2:
dhcp4: no
dhcp6: no
eth3:
dhcp4: yes
bonds:
bond0:
interfaces:
- eth1
- eth2
addresses: [10.0.0.18/16]
gateway4: 10.0.0.2
nameservers:
addresses: [114.114.114.114]
parameters:
mode: active-backup
mii-monitor-interval: 100
root@ubuntu2004:~# netplan apply
root@ubuntu2004:~# ifconfig bond0
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 10.0.0.18 netmask 255.255.0.0 broadcast 10.0.255.255
inet6 fe80::2c1e:3fff:fe64:90e6 prefixlen 64 scopeid 0x20<link>
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 3 bytes 180 (180.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11 bytes 916 (916.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@ubuntu2004:~# ifconfig eth1
eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 1275352 bytes 109128147 (109.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1110015 bytes 94852081 (94.8 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@ubuntu2004:~# ifconfig eth2
eth2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 1134063 bytes 96642193 (96.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1251279 bytes 107335758 (107.3 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@ubuntu2004:~# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:93:a6:4c
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:93:a6:38
Slave queue ID: 0
1.3.7 双网卡绑定+桥接
网卡绑定用于提供网卡接口冗余以及高可用和端口聚合功能,桥接网卡再给需要桥接设备的服务使用
root@ubuntu2004:~# cat /etc/netplan/02-eth.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: no
eth2:
dhcp4: no
dhcp6: no
eth3:
dhcp4: yes
bonds:
bond0:
interfaces:
- eth1
- eth2
parameters:
mode: active-backup
mii-monitor-interval: 100
bridges:
br0:
dhcp4: no
dhcp6: no
addresses: [10.0.0.18/16]
gateway4: 10.0.0.2
nameservers:
addresses: [114.114.114.114]
interfaces:
- bond0
root@ubuntu2004:~# netplan apply
root@ubuntu2004:~# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.dafbcb5bbf07 no bond0
root@ubuntu2004:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 br0
0.0.0.0 10.0.0.2 0.0.0.0 UG 100 0 0 eth3
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth3
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br0
10.0.0.2 0.0.0.0 255.255.255.255 UH 100 0 0 eth3
root@ubuntu2004:~# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 1651 bytes 220133 (220.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 39 bytes 3106 (3.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.18 netmask 255.255.0.0 broadcast 10.0.255.255
inet6 fe80::d8fb:cbff:fe5b:bf07 prefixlen 64 scopeid 0x20<link>
ether da:fb:cb:5b:bf:07 txqueuelen 1000 (Ethernet)
RX packets 2347299 bytes 168132986 (168.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 348 bytes 29651 (29.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.129 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe93:a62e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:93:a6:2e txqueuelen 1000 (Ethernet)
RX packets 1942981 bytes 166833013 (166.8 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8182 bytes 1194068 (1.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 1275382 bytes 109132380 (109.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1110015 bytes 94852081 (94.8 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 1135681 bytes 96857913 (96.8 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1251306 bytes 107337878 (107.3 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.9 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe93:a642 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:93:a6:42 txqueuelen 1000 (Ethernet)
RX packets 1713222 bytes 147017250 (147.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 299 bytes 28288 (28.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 5591 bytes 434226 (434.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5591 bytes 434226 (434.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
1.3.8 网卡的多组绑定
可以实现网卡的多组绑定,比如:eth1,eth2绑定至bond0;eth3和eth4绑定至bond1
root@ubuntu2004:~# cat /etc/netplan/02-eth.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: no
eth2:
dhcp4: no
dhcp6: no
eth3:
dhcp4: no
eth4:
dhcp4: no
bonds:
bond0:
interfaces:
- eth1
- eth2
addresses: [10.0.0.18/16]
gateway4: 10.0.0.2
nameservers:
addresses: [114.114.114.114]
parameters:
mode: active-backup
mii-monitor-interval: 100
bond1:
interfaces:
- eth3
- eth4
addresses: [10.10.0.18/16]
parameters:
mode: active-backup
mii-monitor-interval: 100
routes:
- to: 10.20.0.0/16
via: 10.10.0.2
- to: 10.30.0.0/16
via: 10.10.0.2
root@ubuntu2004:~# netplan apply
root@ubuntu2004:~# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 10.0.0.18 netmask 255.255.0.0 broadcast 10.0.255.255
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 1825 bytes 246831 (246.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 42 bytes 3316 (3.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
bond1: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 10.10.0.18 netmask 255.255.0.0 broadcast 10.10.255.255
inet6 fe80::87d:c9ff:fe5e:e075 prefixlen 64 scopeid 0x20<link>
ether 0a:7d:c9:5e:e0:75 txqueuelen 1000 (Ethernet)
RX packets 1 bytes 60 (60.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 19 bytes 1556 (1.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.129 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe93:a62e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:93:a6:2e txqueuelen 1000 (Ethernet)
RX packets 1944424 bytes 166985833 (166.9 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9179 bytes 1396004 (1.3 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 1275384 bytes 109132500 (109.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1110015 bytes 94852081 (94.8 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 1135853 bytes 96884491 (96.8 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1251309 bytes 107338088 (107.3 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth3: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 0a:7d:c9:5e:e0:75 txqueuelen 1000 (Ethernet)
RX packets 1713224 bytes 147017370 (147.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 304 bytes 28658 (28.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth4: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 0a:7d:c9:5e:e0:75 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 19 bytes 1556 (1.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 5591 bytes 434226 (434.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5591 bytes 434226 (434.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@ubuntu2004:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 bond0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 bond0
10.10.0.0 0.0.0.0 255.255.0.0 U 0 0 0 bond1
10.20.0.0 10.10.0.2 255.255.0.0 UG 0 0 0 bond1
10.30.0.0 10.10.0.2 255.255.0.0 UG 0 0 0 bond1
root@ubuntu2004:~# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:93:a6:4c
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:93:a6:38
Slave queue ID: 0
root@ubuntu2004:~# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth4
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth4
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:93:a6:56
Slave queue ID: 0
Slave Interface: eth3
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:93:a6:42
Slave queue ID: 0
1.3.9 网卡多组绑定+多组桥接
root@ubuntu2004:~# cat /etc/netplan/02-eth.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: no
eth2:
dhcp4: no
dhcp6: no
eth3:
dhcp4: no
eth4:
dhcp4: no
bonds:
bond0:
interfaces:
- eth1
- eth2
parameters:
mode: active-backup
mii-monitor-interval: 100
bond1:
interfaces:
- eth3
- eth4
parameters:
mode: active-backup
mii-monitor-interval: 100
bridges:
br0:
dhcp4: no
addresses: [10.0.0.18/16]
gateway4: 10.0.0.2
nameservers:
addresses: [114.114.114.114]
interfaces:
- bond0
br1:
dhcp4: no
addresses: [10.10.0.18/16]
interfaces:
- bond1
routes:
- to: 10.20.0.0/16
via: 10.10.0.2
- to: 10.30.0.0/16
via: 10.10.0.2
root@ubuntu2004:~# netplan apply
root@ubuntu2004:~# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.dafbcb5bbf07 no bond0
br1 8000.9eff5dce92e5 no bond1
root@ubuntu2004:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 br0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br0
10.10.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br1
10.20.0.0 10.10.0.2 255.255.0.0 UG 0 0 0 br1
10.30.0.0 10.10.0.2 255.255.0.0 UG 0 0 0 br1
root@ubuntu2004:~# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 1952 bytes 262941 (262.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 50 bytes 3972 (3.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
bond1: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
ether 0a:7d:c9:5e:e0:75 txqueuelen 1000 (Ethernet)
RX packets 128 bytes 16170 (16.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 33 bytes 2652 (2.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.18 netmask 255.255.0.0 broadcast 10.0.255.255
inet6 fe80::d8fb:cbff:fe5b:bf07 prefixlen 64 scopeid 0x20<link>
ether da:fb:cb:5b:bf:07 txqueuelen 1000 (Ethernet)
RX packets 10 bytes 656 (656.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 656 (656.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
br1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.10.0.18 netmask 255.255.0.0 broadcast 10.10.255.255
inet6 fe80::9cff:5dff:fece:92e5 prefixlen 64 scopeid 0x20<link>
ether 9e:ff:5d:ce:92:e5 txqueuelen 1000 (Ethernet)
RX packets 11 bytes 732 (732.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 656 (656.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.129 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe93:a62e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:93:a6:2e txqueuelen 1000 (Ethernet)
RX packets 1945243 bytes 167073136 (167.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9844 bytes 1522130 (1.5 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 1275385 bytes 109132743 (109.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1110015 bytes 94852081 (94.8 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 2e:1e:3f:64:90:e6 txqueuelen 1000 (Ethernet)
RX packets 1135979 bytes 96900358 (96.9 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1251317 bytes 107338744 (107.3 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth3: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 0a:7d:c9:5e:e0:75 txqueuelen 1000 (Ethernet)
RX packets 1713225 bytes 147017613 (147.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 304 bytes 28658 (28.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth4: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 0a:7d:c9:5e:e0:75 txqueuelen 1000 (Ethernet)
RX packets 126 bytes 15867 (15.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 33 bytes 2652 (2.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 5591 bytes 434226 (434.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5591 bytes 434226 (434.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@ubuntu2004:~# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:93:a6:4c
Slave queue ID: 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:93:a6:38
Slave queue ID: 0
root@ubuntu2004:~# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth4
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth4
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:93:a6:56
Slave queue ID: 0
Slave Interface: eth3
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:93:a6:42
Slave queue ID: 0







Comments | 1 条评论
该评论为私密评论