给新添加的网卡配置IP地址
现有新添加的两张网卡eno33554992和eno50332216
在server1上使用nmcli
[root@server_1 network-scripts]# nmcli connection add con-name eth1 type ethernet ifname eno33554992 ip4 192.168.19.102/24 gw4 192.168.19.1
Connection ‘eth1’ (8099abb8-2a30-4d11-a3ae-ce4c5c534d8b) successfully added.[root@server_1 network-scripts]# nmcli connection add con-name eth2 type ethernet ifname eno50332216 ip4 192.168.19.103/24 gw4 192.168.19.1
Connection ‘eth2’ (f127ca55-37d3-4913-8b62-1969ceabaacd) successfully added.[root@server_1 network-scripts]# ip addr
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:1c:2a:5b brd ff:ff:ff:ff:ff:ff
inet 192.168.19.101/24 brd 192.168.19.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe1c:2a5b/64 scope link
valid_lft forever preferred_lft forever
3: eno33554992: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:1c:2a:65 brd ff:ff:ff:ff:ff:ff
inet 192.168.19.102/24 brd 192.168.19.255 scope global eno33554992
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe1c:2a65/64 scope link
valid_lft forever preferred_lft forever
4: eno50332216: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:1c:2a:6f brd ff:ff:ff:ff:ff:ff
inet 192.168.19.103/24 brd 192.168.19.255 scope global eno50332216
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe1c:2a6f/64 scope link
valid_lft forever preferred_lft forever
删除使用nmcli con delete eth1
在server2上手工写配置文件
[root@server_2 ~]# cd /etc/sysconfig/network-scripts/
[root@server_2 network-scripts]# vim ifcfg-eth1
NAME=eth1
DEVICE=eno33554992
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.19.202
PREFIX=24
GATEWAY=192.168.19.1
[root@server_2 network-scripts]# vim ifcfg-eth2
NAME=eth2
DEVICE=eno50332216
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.19.203
PREFIX=24
GATEWAY=192.168.19.1
[root@server_2 network-scripts]# systemctl restart network
[root@server_2 network-scripts]# ip addr
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:36:ce:06 brd ff:ff:ff:ff:ff:ff
inet 192.168.19.201/24 brd 192.168.19.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe36:ce06/64 scope link
valid_lft forever preferred_lft forever
3: eno33554992: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:36:ce:10 brd ff:ff:ff:ff:ff:ff
inet 192.168.19.202/24 brd 192.168.19.255 scope global eno33554992
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe36:ce10/64 scope link
valid_lft forever preferred_lft forever
4: eno50332216: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:36:ce:1a brd ff:ff:ff:ff:ff:ff
inet 192.168.19.203/24 brd 192.168.19.255 scope global eno50332216
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe36:ce1a/64 scope link
valid_lft forever preferred_lft forever
[root@server_2 network-scripts]# ping 192.168.19.102
PING 192.168.19.102 (192.168.19.102) 56(84) bytes of data.
64 bytes from 192.168.19.102: icmp_seq=1 ttl=64 time=0.665 ms
64 bytes from 192.168.19.102: icmp_seq=2 ttl=64 time=0.377 ms
^C
--- 192.168.19.102 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.377/0.521/0.665/0.144 ms
一张网卡配置多个IP地址
[root@server_1 network-scripts]# nmcli connection modify eth1 +ipv4.addresses 192.168.20.2/24
[root@server_1 network-scripts]# systemctl restart network
[root@server_2 network-scripts]# nmcli connection modify eth1 +ipv4.addresses 192.168.20.4/24
[root@server_2 network-scripts]# systemctl restart network
[root@server_2 network-scripts]# ping 192.168.20.2 -I 192.168.20.4
PING 192.168.20.2 (192.168.20.2) from 192.168.20.4 : 56(84) bytes of data.
64 bytes from 192.168.20.2: icmp_seq=1 ttl=64 time=0.577 ms
64 bytes from 192.168.20.2: icmp_seq=2 ttl=64 time=0.461 ms
64 bytes from 192.168.20.2: icmp_seq=3 ttl=64 time=0.442 ms
64 bytes from 192.168.20.2: icmp_seq=4 ttl=64 time=0.463 ms
^C
--- 192.168.20.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3001ms
rtt min/avg/max/mdev = 0.442/0.485/0.577/0.059 ms
链路聚合
将新的两张网卡聚合为一个team
server1使用nmcli
删除之前的配置的两张网卡[root@server_1 network-scripts]# nmcli connection delete eth1
Connection ‘eth1’ (8099abb8-2a30-4d11-a3ae-ce4c5c534d8b) successfully deleted.[root@server_1 network-scripts]# nmcli connection delete eth2
Connection ‘eth2’ (f127ca55-37d3-4913-8b62-1969ceabaacd) successfully deleted.[root@server_1 network-scripts]# nmcli connection add con-name team0 ifname team0 type team config '{"runner": {"name": "loadbalance"}}'
Connection ‘team0’ (72a24350-f7fb-4909-b8d9-b0e4d63d4a3b) successfully added.[root@server_1 network-scripts]# nmcli connection modify team0 ipv4.addresses 192.168.19.102/24 ipv4.gateway 192.168.19.1 ipv4.method manual
[root@server_1 network-scripts]# nmcli connection add con-name team0-port1 type team-slave ifname eno33554992 master team0
Connection ‘team0-port1’ (be929ed1-410a-4f40-ac94-1f12b7c0322a) successfully added.[root@server_1 network-scripts]# nmcli connection add con-name team0-port2 type team-slave ifname eno50332216 master team0
Connection ‘team0-port2’ (13972926-e23a-48aa-9e9f-c72e59300942) successfully added.[root@server_1 network-scripts]# nmcli connection up team0-port1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)[root@server_1 network-scripts]# nmcli connection show --active
NAME UUID TYPE DEVICE
team0-port1 be929ed1-410a-4f40-ac94-1f12b7c0322a 802-3-ethernet eno33554992
team0 72a24350-f7fb-4909-b8d9-b0e4d63d4a3b team team0
team0-port2 13972926-e23a-48aa-9e9f-c72e59300942 802-3-ethernet eno50332216
server2手工写配置文件
删除之前的配置的两张网卡[root@server_2 network-scripts]# nmcli connection delete eth1
Connection ‘eth1’ (8099abb8-2a30-4d11-a3ae-ce4c5c534d8b) successfully deleted.[root@server_2 network-scripts]# nmcli connection delete eth2
Connection ‘eth2’ (f127ca55-37d3-4913-8b62-1969ceabaacd) successfully deleted.[root@server_2 network-scripts]# vim ifcfg-team0
DEVICE=team0
NAME=team0
DEVICETYPE=Team
TEAM_CONFIG="{\"runner\": {\"name\": \"activebackup\"}}"
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.19.202
PREFIX=24
GATEWAY=192.168.19.1
[root@server_2 network-scripts]# vim ifcfg-team0-port1
NAME=team0-port1
DEVICE=eno33554992
ONBOOT=yes
TEAM_MASTER=team0
DEVICETYPE=TeamPort
[root@server_2 network-scripts]# vim ifcfg-team0-port2
NAME=team0-port2
DEVICE=eno50332216
ONBOOT=yes
TEAM_MASTER=team0
DEVICETYPE=TeamPort
[root@server_2 network-scripts]# systemctl restart network
[root@server_2 network-scripts]# ip addr
8: team0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 00:0c:29:36:ce:1a brd ff:ff:ff:ff:ff:ff
inet 192.168.19.202/24 brd 192.168.19.255 scope global team0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe36:ce1a/64 scope link
valid_lft forever preferred_lft forever
[root@server_2 network-scripts]# nmcli connection show --active
NAME UUID TYPE DEVICE
team0-port2 131891f6-d45a-42f7-0f6d-877668e7a054 802-3-ethernet eno50332216
team0-port1 52c7a66a-0fc6-dec3-3c0f-652871d89b75 802-3-ethernet eno33554992
team0 702de3eb-2e80-897c-fd52-cd0494dd8123 team team0
[root@server_2 network-scripts]# ping 192.168.19.102 -I team0
PING 192.168.19.102 (192.168.19.102) from 192.168.19.202 team0: 56(84) bytes of data.
64 bytes from 192.168.19.102: icmp_seq=10 ttl=64 time=0.776 ms
64 bytes from 192.168.19.102: icmp_seq=11 ttl=64 time=0.413 ms
64 bytes from 192.168.19.102: icmp_seq=12 ttl=64 time=0.424 ms
^C
--- 192.168.19.102 ping statistics ---
12 packets transmitted, 3 received, 75% packet loss, time 11001ms
rtt min/avg/max/mdev = 0.413/0.537/0.776/0.170 ms
网桥
server1使用nmcli
[root@server_1 ~]# nmcli connection delete team0
Connection ‘team0’ (72a24350-f7fb-4909-b8d9-b0e4d63d4a3b) successfully deleted.[root@server_1 ~]# nmcli connection delete team0-port1
Connection ‘team0-port1’ (be929ed1-410a-4f40-ac94-1f12b7c0322a) successfully deleted.[root@server_1 ~]# nmcli connection delete team0-port2
Connection ‘team0-port2’ (13972926-e23a-48aa-9e9f-c72e59300942) successfully deleted.[root@server_1 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
eno33554992 ethernet disconnected --
eno50332216 ethernet disconnected --
[root@server_1 ~]# nmcli connection add con-name br0 ifname br0 type bridge
Connection ‘br0’ (57e1d948-c13c-4b43-a1df-ae15b3dd7bcf) successfully added.[root@server_1 ~]# nmcli connection modify br0 ipv4.addresses 192.168.19.102/24 ipv4.gateway 192.168.19.1 ipv4.method manual
[root@server_1 ~]# nmcli connection add con-name br0-port1 ifname eno33554992 type bridge-slave master br0
Connection ‘br0-port1’ (48597166-ff58-41ca-adfe-47dac44c5aca) successfully added.[root@server_1 ~]# nmcli connection add con-name br0-port2 ifname eno50332216 type bridge-slave master br0
Connection ‘br0-port2’ (85936f31-7db6-431f-a165-e052df484431) successfully added.[root@server_1 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
br0 bridge connected br0
eno16777736 ethernet connected eno16777736
eno33554992 ethernet connected br0-port1
eno50332216 ethernet connected br0-port2
[root@server_1 ~]# ip addr
3: eno33554992: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
link/ether 00:0c:29:1c:2a:65 brd ff:ff:ff:ff:ff:ff
4: eno50332216: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
link/ether 00:0c:29:1c:2a:6f brd ff:ff:ff:ff:ff:ff
8: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 00:0c:29:1c:2a:65 brd ff:ff:ff:ff:ff:ff
inet 192.168.19.102/24 brd 192.168.19.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe1c:2a65/64 scope link
valid_lft forever preferred_lft forever
server2手工写配置文件
[root@server_2 network-scripts]# nmcli connection delete team0
Connection ‘team0’ (702de3eb-2e80-897c-fd52-cd0494dd8123) successfully deleted.[root@server_2 network-scripts]# nmcli connection delete team0-port1
Connection ‘team0-port1’ (52c7a66a-0fc6-dec3-3c0f-652871d89b75) successfully deleted.[root@server_2 network-scripts]# nmcli connection delete team0-port2
Connection ‘team0-port2’ (131891f6-d45a-42f7-0f6d-877668e7a054) successfully deleted.[root@server_2 network-scripts]# vim ifcfg-br0
DEVICE=br0
NAME=br0
STP=yes
TYPE=Bridge
BOOTPROTO=none
IPADDR=192.168.19.202
PREFIX=24
GATEWAY=192.168.19.1
ONBOOT=yes
BRIDGE_OPTS=priority=32768
[root@server_2 network-scripts]# vim ifcfg-br0-port1
TYPE=Ethernet
NAME=br0-port1
DEVICE=eno33554992
ONBOOT=yes
BRIDGE=br0
[root@server_2 network-scripts]# vim ifcfg-br0-port2
TYPE=Ethernet
NAME=br0-port2
DEVICE=eno50332216
ONBOOT=yes
BRIDGE=br0
[root@server_2 network-scripts]# systemctl restart network
[root@server_2 network-scripts]# nmcli device status
DEVICE TYPE STATE CONNECTION
br0 bridge connected br0
eno16777736 ethernet connected eno16777736
eno33554992 ethernet connected br0-port1
eno50332216 ethernet connected br0-port2
[root@server_2 network-scripts]# ip addr
3: eno33554992: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
link/ether 00:0c:29:36:ce:10 brd ff:ff:ff:ff:ff:ff
4: eno50332216: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
link/ether 00:0c:29:36:ce:1a brd ff:ff:ff:ff:ff:ff
8: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 00:0c:29:36:ce:10 brd ff:ff:ff:ff:ff:ff
inet 192.168.19.202/24 brd 192.168.19.255 scope global br0
valid_lft forever preferred_lft forever
[root@server_2 network-scripts]# ping -I br0 192.168.19.102
PING 192.168.19.102 (192.168.19.102) from 192.168.19.202 br0: 56(84) bytes of data.
64 bytes from 192.168.19.102: icmp_seq=12 ttl=64 time=0.818 ms
64 bytes from 192.168.19.102: icmp_seq=13 ttl=64 time=0.441 ms
64 bytes from 192.168.19.102: icmp_seq=14 ttl=64 time=0.507 ms
64 bytes from 192.168.19.102: icmp_seq=15 ttl=64 time=0.444 ms
^C
--- 192.168.19.102 ping statistics ---
15 packets transmitted, 4 received, 73% packet loss, time 14006ms
rtt min/avg/max/mdev = 0.441/0.552/0.818/0.157 ms
综合实验:两张网卡链路聚合,在和第三张网卡组成网桥
配置team0
[root@server_1 ~]# nmcli connection add con-name team0 ifname team0 type team config '{"runner": {"name": "loadbalance"}}'
Connection ‘team0’ (9c635d95-312d-4369-a0d3-18c122468437) successfully added.[root@server_1 ~]# nmcli connection add con-name team0-port1 ifname eno33554992 type team-slave master team0
Connection ‘team0-port1’ (2098e51e-d30c-4343-be2e-c252fe413187) successfully added.[root@server_1 ~]# nmcli connection add con-name team0-port2 ifname eno50332216 type team-slave master team0
Connection ‘team0-port2’ (f484116a-7009-4154-88de-342395af8949) successfully added.[root@server_1 ~]# teamdctl team0 state
setup:
runner: loadbalance
ports:
eno33554992
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
eno50332216
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
停止team0,停止NetworkManager
[root@server_1 ~]# nmcli device disconnect team0
Device ‘team0’ successfully disconnected.[root@server_1 ~]# systemctl stop NetworkManager
[root@server_1 ~]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
配置br0
[root@server_1 ~]# cd /etc/sysconfig/network-scripts/
[root@server_1 network-scripts]# ll | grep ifcfg
-rw-r--r--. 1 root root 314 May 7 23:49 ifcfg-eno16777736
-rw-r--r--. 1 root root 254 Sep 16 2015 ifcfg-lo
-rw-r--r--. 1 root root 334 May 11 14:32 ifcfg-team0
-rw-r--r--. 1 root root 127 May 11 14:32 ifcfg-team0-port1
-rw-r--r--. 1 root root 127 May 11 14:33 ifcfg-team0-port2
将team0添加到br0[root@server_1 network-scripts]# vim ifcfg-team0
删除多余配置,增加BRIDGE变量等于br0
DEVICE=team0
TEAM_CONFIG="{\"runner\": {\"name\": \"loadbalance\"}}"
DEVICETYPE=Team
NAME=team0
UUID=0f896254-6965-4f0f-ab28-e2c2fa1cb3de
ONBOOT=yes
BRIDGE=br0
配置br0[root@server_1 network-scripts]# vim ifcfg-br0
NAME=br0
DEVICE=br0
ONBOOT=yes
TYPE=Bridge
IPADDR=192.168.19.102
PREFIC=24
重启network[root@server_1 network-scripts]# systemctl restart network
测试
[root@server_2 ~]# ping 192.168.19.102
PING 192.168.19.102 (192.168.19.102) 56(84) bytes of data.
64 bytes from 192.168.19.102: icmp_seq=1 ttl=64 time=0.854 ms
64 bytes from 192.168.19.102: icmp_seq=2 ttl=64 time=0.538 ms
^C
--- 192.168.19.102 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.538/0.696/0.854/0.158 ms
来源:https://blog.csdn.net/qq_36148336/article/details/102469579