1. 程式人生 > 實用技巧 >12.第十章 網路協議和管理配置

12.第十章 網路協議和管理配置

1.TCP的三次握手四次揮手

三次握手(three-way handshaking)

1.背景:TCP位於傳輸層,作用是提供可靠的位元組流服務,為了準確無誤地將資料送達目的地,TCP協議採納三次握手策略。

2.原理:

1)傳送端首先發送一個帶有SYN(synchronize)標誌地資料包給接收方。

2)接收方接收後,回傳一個帶有SYN/ACK標誌的資料包傳遞確認資訊,表示我收到了。

3)最後,傳送方再回傳一個帶有ACK標誌的資料包,代表我知道了,表示’握手‘結束。

通俗的說法

1)Client:嘿,李四,是我,聽到了嗎?

2)Server:我聽到了,你能聽到我的嗎?

3)Client:好的,我們互相都能聽到對方的話,我們的通訊可以開始了。

四次揮手(Four-Way-Wavehand)

1.意義:當被動方收到主動方的FIN報文通知時,它僅僅表示主動方沒有資料再發送給被動方了。但未必被動方所有的資料都完整的傳送給了主動方,所以被動方不會馬上關閉SOCKET,它可能還需要傳送一些資料給主動方後,再發送FIN報文給主動方,告訴主動方同意關閉連線,所以這裡的ACK報文和FIN報文多數情況下都是分開發送的。

2.原理:

1)第一次揮手:Client傳送一個FIN,用來關閉Client到Server的資料傳送,Client進入FIN_WAIT_1狀態。

2)第二次揮手:Server收到FIN後,傳送一個ACK給Client,確認序號為收到序號+1(與SYN相同,一個FIN佔用一個序號),Server進入CLOSE_WAIT狀態。

3)第三次揮手:Server傳送一個FIN,用來關閉Server到Client的資料傳送,Server進入LAST_ACK狀態。

4)第四次揮手:Client收到FIN後,Client進入TIME_WAIT狀態,接著傳送一個ACK給Server,確認序號為收到序號+1,Server進入CLOSED狀態,完成四次揮手

通俗的說法

1)Client:我所有東西都說完了

2)Server:我已經全部聽到了,但是等等我,我還沒說完

3)Server:好了,我已經說完了

4)Client:好的,那我們的通訊結束

2.抓包

[root@centos8 ~]# tcpdump -i eth0 -nn icmp and src host 10.0.0.6 and dst host 10.0.0.7

3.劃分子網
`1)10.0.0.0/8給32省份劃分子網,借5位
2^n>=32

(1) 劃分子網的netmask 255.11111000.0.0 255.248.0.0
(2) 每個子網的主機數 32-13=19 2^19-2=524286
(3) 第一個子網的網路ID?
10.00000 000.0.0
10.0.0.0/13
(4) 河南省得到第10個子網,此子網的網路iD是什麼?
10.00000 000.0.0
10.00001
10.01001 000.0.0 10.72.0.0/13

2)中國移動10.0.0.0/8 給32個省公司劃分對應的子網,河南省得到第10個子網,再給省內的16個地市劃分子網
10.01001 000.0.0 10.72.0.0/13

(1)每個市公司的子網的netmask?
2^4>=16 借4位網路ID
13+4=17
255.255.128.0
(2)每個市公司的子網的主機數有多少?
32-17=15 2^15-2=32766
(3)各地市的最小netid和最大netid?
10.72.0.0-10.79.128.0

(4)洛陽市第2個子網,最小IP和最大IP?
10.72.128.1-10.72.255.254

10.01001000.00000000.0/17 10.72.0.1-10.72.127.254
10.01001000.10000000.0/17 10.72.128.1-10.72.255.254
10.01001001.00000000.0/17 10.73.0.1-10.73.127.254
10.01001001.10000000.0/17 10.73.128.0-10.73.255.254
10.01001010.00000000.0/17 10.74.0.1-10.74.127.254
10.01001010.10000000.0/17 10.74.128.1-10.74.255.254
10.01001011.00000000.0/17 10.75.0.1-10.75.127.254
10.01001011.10000000.0/17 10.75.128.1-10.75.255.254
10.01001100.00000000.0/17 10.76.0.1-10.76.127.254
10.01001100.10000000.0/17 10.76.128.1-10.76.255.254
10.01001101.00000000.0/17 10.77.0.1-10.77.127.254
10.01001101.10000000.0/17 10.77.128.1-10.77.255.254
10.01001110.00000000.0/17 10.78.0.1-10.78.127.254
10.01001110.10000000.0/17 10.78.128.1-10.255.254
10.01001111.00000000.0/17 10.79.0.1-10.79.127.254
10.01001111.10000000.0/17 10.79.128.1-10.79.255.254`

5.合併超網
`#8個C類網段
220.78.168.0/24
220.78.169.0/24
220.78.170.0/24
220.78.171.0/24
220.78.172.0/24
220.78.173.0/24
220.78.174.0/24
220.78.175.0/24

220.78.10101 000.0 220.78.168.0/24
220.78.10101 001.0 220.78.169.0/24
220.78.10101 010.0 220.78.170.0/24
...
220.78.10101 110.0 220.78.174.0/24
220.78.10101 111.0 220.78.175.0/24

合併成

220.78.168.0/21`

6.網路基本配置檔案格式
[root@centos8 network-scripts]# vim ifcfg-eth1 DEVICE=eth1 NAME=con-eth1 BOOTPROTO=none IPADDR=172.16.0.8 PREFIX=16 GATEWAY=172.16.0.254 DNS1=180.76.76.76 DNS2=223.5.5.5 :wq

7.多網絡卡bonding
`[root@centos8 ~]# cdnet
[root@centos8 network-scripts]# ls
ifcfg-eth0 ifcfg-eth0.bak
[root@centos8 network-scripts]# vim ifcfg-bond0
NAME=bond0
TYPE=bond
DEVICE=bond0
BOOTPROTO=none
IPADDR=10.0.0.100
PREFIX=8

miimon指定鏈路檢測時間間隔,如果miimon=100,那麼系統每100ms監測一次鏈路連線狀態,如果有一條線路不通就轉入另一條線路

BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1" #生產中不加fail_over_mac=1,這裡因為是vmware環境,不加可能有問題
:wq

[root@centos8 network-scripts]#vim ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
ONBOOT=yes
:wq
[root@centos8 network-scripts]# vim ifcfg-eth1
DEVICE=eth1
NAME=eth1
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
ONBOOT=yes
:wq

[root@centos8 network-scripts]# nmcli connection
NAME UUID TYPE DEVICE
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 ethernet eth0
Wired connection 1 c4a28af1-0cbc-3fd8-84af-5d891444e362 ethernet eth1
[root@centos8 network-scripts]# nmcli connection reload
[root@centos8 network-scripts]# nmcli connection
NAME UUID TYPE DEVICE
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 ethernet eth0
Wired connection 1 c4a28af1-0cbc-3fd8-84af-5d891444e362 ethernet eth1
bond0 ad33d8b0-1f7b-cab9-9447-ba07f855b143 bond bond0
eth1 9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04 ethernet --
[root@centos8 network-scripts]# nmcli connection up bond0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)

[root@centos8 network-scripts]# nmcli connection up eth0
現在就設定成功了

[root@centos7 network-scripts]# ping 10.0.0.100
PING 10.0.0.100 (10.0.0.100) 56(84) bytes of data.
64 bytes from 10.0.0.100: icmp_seq=1 ttl=64 time=0.404 ms
64 bytes from 10.0.0.100: icmp_seq=2 ttl=64 time=0.808 ms
64 bytes from 10.0.0.100: icmp_seq=3 ttl=64 time=0.303 ms
64 bytes from 10.0.0.100: icmp_seq=4 ttl=64 time=1.07 ms

[root@centos8 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: None
Currently Active Slave: eth0 #現在eth0是主
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:9a:ff:0e
Slave queue ID: 0

Slave Interface: eth1 #eth1是從
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:9a:ff:18
Slave queue ID: 0

現在把eth0斷開連線
[root@centos8 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup) (fail_over_mac active)
Primary Slave: None
Currently Active Slave: eth1 #eth1就自動切上去了
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: eth0
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 00:0c:29:9a:ff:0e
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:9a:ff:18
Slave queue ID: 0

[root@centos8 network-scripts]# vim ifcfg-bond0
NAME=bond0
TYPE=bond
DEVICE=bond0
BOOTPROTO=none
IPADDR=10.0.0.100
PREFIX=24

miimon指定鏈路檢測時間間隔,如果miimon=100,那麼系統每100ms監測一次鏈路連線狀態,如果有一條線路不通就轉入另一條線路

BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1" #生產中不加fail_over_mac=1,這裡因為是vmware環境,不加可能有問題

改成0模式

[root@centos8 network-scripts]# nmcli connection reload
[root@centos8 network-scripts]# nmcli connection up bond0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/17)

[root@centos8 network-scripts]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: load balancing (round-robin) #改成輪詢模式
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:9a:ff:0e
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:9a:ff:18
Slave queue ID: 0`

8.網路組 Network Teaming
`[root@centos8 ~]# cdnet
[root@centos8 network-scripts]# ls
ifcfg-bond0 ifcfg-eth0 ifcfg-eth0.bak ifcfg-eth1
[root@centos8 network-scripts]# rm -rf *
[root@centos8 network-scripts]# ls
[root@centos8 network-scripts]# reboot

[root@centos8 ~]# cdnet
[root@centos8 network-scripts]# ls
[root@centos8 network-scripts]# nmcli connection
NAME UUID TYPE DEVICE
Wired connection 1 d3334e5c-5601-3bfa-ba0d-ea55b2a26862 ethernet eth0
[root@centos8 network-scripts]# ip a
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:9a:ff:0e brd ff:ff:ff:ff:ff:ff
inet 10.0.0.163/24 brd 10.0.0.255 scope global dynamic noprefixroute eth0
valid_lft 1673sec preferred_lft 1673sec
inet6 fe80::b58d:8b21:95e2:a7f2/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:9a:ff:18 brd ff:ff:ff:ff:ff:ff
[root@centos8 network-scripts]# nmcli con add type team con-name myteam0 ifname team0 config '{"runner": {"name": "broadcast"}}'
Connection 'myteam0' (a0e7fb69-d807-47ae-9c93-ddc92958cf35) successfully added.
[root@centos8 network-scripts]# nmcli connection
NAME UUID TYPE DEVICE
myteam0 a0e7fb69-d807-47ae-9c93-ddc92958cf35 team team0
Wired connection 1 d3334e5c-5601-3bfa-ba0d-ea55b2a26862 ethernet eth0

[root@centos8 network-scripts]# ls
ifcfg-myteam0
[root@centos8 network-scripts]# cat ifcfg-myteam0
TEAM_CONFIG="{"runner": {"name": "broadcast"}}"
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=myteam0
UUID=a0e7fb69-d807-47ae-9c93-ddc92958cf35
DEVICE=team0
ONBOOT=yes
DEVICETYPE=Team

[root@centos8 network-scripts]# nmcli connection delete myteam0
Connection 'myteam0' (a0e7fb69-d807-47ae-9c93-ddc92958cf35) successfully deleted.
[root@centos8 network-scripts]# nmcli connection
NAME UUID TYPE DEVICE
Wired connection 1 d3334e5c-5601-3bfa-ba0d-ea55b2a26862 ethernet eth0
[root@centos8 network-scripts]# nmcli con add type team con-name myteam0 ifname team0 config '{"runner": {"name": "broadcast"}}' ipv4.addresses 10.0.0.100/24 ipv4.method manual
Connection 'myteam0' (40763c08-ffb1-4e19-bf02-98d835a4b8e3) successfully added.
[root@centos8 network-scripts]# nmcli connection
NAME UUID TYPE DEVICE
Wired connection 1 d3334e5c-5601-3bfa-ba0d-ea55b2a26862 ethernet eth0
myteam0 40763c08-ffb1-4e19-bf02-98d835a4b8e3 team team0
[root@centos8 network-scripts]# ip a
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:9a:ff:0e brd ff:ff:ff:ff:ff:ff
inet 10.0.0.163/24 brd 10.0.0.255 scope global dynamic noprefixroute eth0
valid_lft 1368sec preferred_lft 1368sec
inet6 fe80::b58d:8b21:95e2:a7f2/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:9a:ff:18 brd ff:ff:ff:ff:ff:ff
5: team0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 5e:9c:e0:2a:9b:0d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute team0
valid_lft forever preferred_lft forever

[root@centos8 network-scripts]# nmcli con add con-name team0-eth0 type team-slave ifname eth0 master team0
Connection 'team0-eth0' (bdd375d4-ea22-47c2-a876-dacbd795731a) successfully added.

[root@centos8 network-scripts]# nmcli con add con-name team0-eth1 type team-slave ifname eth1 master team0
Connection 'team0-eth1' (67b88115-a2da-4fac-b244-0e4106c6a479) successfully added.
[root@centos8 network-scripts]# nmcli connection
NAME UUID TYPE DEVICE
Wired connection 1 d3334e5c-5601-3bfa-ba0d-ea55b2a26862 ethernet eth0
myteam0 40763c08-ffb1-4e19-bf02-98d835a4b8e3 team team0
team0-eth1 67b88115-a2da-4fac-b244-0e4106c6a479 ethernet eth1
team0-eth0 bdd375d4-ea22-47c2-a876-dacbd795731a ethernet --
[root@centos8 network-scripts]# nmcli connection delete Wired\ connection\ 1
Connection 'Wired connection 1' (d3334e5c-5601-3bfa-ba0d-ea55b2a26862) successfully deleted.

[root@centos7 network-scripts]# ping 10.0.0.100
PING 10.0.0.100 (10.0.0.100) 56(84) bytes of data.
64 bytes from 10.0.0.100: icmp_seq=1 ttl=64 time=0.239 ms
64 bytes from 10.0.0.100: icmp_seq=1 ttl=64 time=0.247 ms (DUP!)
64 bytes from 10.0.0.100: icmp_seq=2 ttl=64 time=1.11 ms
64 bytes from 10.0.0.100: icmp_seq=2 ttl=64 time=1.12 ms (DUP!)
64 bytes from 10.0.0.100: icmp_seq=3 ttl=64 time=0.277 ms
64 bytes from 10.0.0.100: icmp_seq=3 ttl=64 time=0.290 ms (DUP!)
64 bytes from 10.0.0.100: icmp_seq=4 ttl=64 time=0.259 ms
64 bytes from 10.0.0.100: icmp_seq=4 ttl=64 time=0.268 ms (DUP!)

出現DUP ,j設定的是broadcast 廣播模式

[root@centos6 ~]# tcpdump -i eth0 -nn icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
22:33:09.275034 IP 10.0.0.7 > 10.0.0.100: ICMP echo request, id 1911, seq 103, length 64 #10.0.0.7 發給10.0.0.100 ,下面收到兩條回覆,這就是DUP
22:33:09.275235 IP 10.0.0.100 > 10.0.0.7: ICMP echo reply, id 1911, seq 103, length 64
22:33:09.275238 IP 10.0.0.100 > 10.0.0.7: ICMP echo reply, id 1911, seq 103, length 64
22:33:10.277866 IP 10.0.0.7 > 10.0.0.100: ICMP echo request, id 1911, seq 104, length 64
22:33:10.277985 IP 10.0.0.100 > 10.0.0.7: ICMP echo reply, id 1911, seq 104, length 64
22:33:10.277988 IP 10.0.0.100 > 10.0.0.7: ICMP echo reply, id 1911, seq 104, length 64
22:33:11.279186 IP 10.0.0.7 > 10.0.0.100: ICMP echo request, id 1911, seq 105, length 64
22:33:11.279415 IP 10.0.0.100 > 10.0.0.7: ICMP echo reply, id 1911, seq 105, length 64
22:33:11.279430 IP 10.0.0.100 > 10.0.0.7: ICMP echo reply, id 1911, seq 105, length 64
22:33:12.280717 IP 10.0.0.7 > 10.0.0.100: ICMP echo request, id 1911, seq 106, length 64
22:33:12.280935 IP 10.0.0.100 > 10.0.0.7: ICMP echo reply, id 1911, seq 106, length 64
22:33:12.280940 IP 10.0.0.100 > 10.0.0.7: ICMP echo reply, id 1911, seq 106, length 64

斷開第一個網絡卡

64 bytes from 10.0.0.100: icmp_seq=270 ttl=64 time=0.288 ms
64 bytes from 10.0.0.100: icmp_seq=271 ttl=64 time=1.19 ms
64 bytes from 10.0.0.100: icmp_seq=272 ttl=64 time=0.217 ms
64 bytes from 10.0.0.100: icmp_seq=273 ttl=64 time=0.665 ms
64 bytes from 10.0.0.100: icmp_seq=274 ttl=64 time=1.01 ms
64 bytes from 10.0.0.100: icmp_seq=275 ttl=64 time=0.456 ms

這裡就沒有重複包

[root@centos8 ~]# teamdctl team0 state #檢視狀態
setup:
runner: broadcast
ports:
eth0
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 1
eth1
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0

[root@centos8 network-scripts]# vim ifcfg-myteam0
TEAM_CONFIG="{"runner": {"name": "activebackup"}}" #把這裡改成activebackup模式
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=10.0.0.100
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=myteam0
UUID=40763c08-ffb1-4e19-bf02-98d835a4b8e3
DEVICE=team0
ONBOOT=yes
DEVICETYPE=Team
[root@centos8 network-scripts]# nmcli connection reload
[root@centos8 network-scripts]# nmcli connection up myteam0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)

[root@centos8 network-scripts]# teamdctl team0 state
setup:
runner: activebackup #變成了activebackup模式
ports:
eth0
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
eth1
link watches:
link summary: up
instance[link_watch_0]:
name: ethtool
link: up
down count: 0
runner:
active port: eth1`

9.網橋

`[root@centos7 ~]# nmcli connection
[root@centos7 ~]# ifconfig eth0 0/0
[root@centos7 ~]# yum -y install bridge-utils
[root@centos7 ~]# ifconfig eth1 0/0
[root@centos7 ~]# ip a

兩個網絡卡都沒有IP

[root@centos7 ~]# rpm -ql bridge-utils

[root@centos7 ~]# brctl show

檢視網橋

新增網橋

[root@centos7 ~]# brctl addbr bro
[root@centos7 ~]# brctl show

把eth0加入網橋

[root@centos7 ~]# brctl addif br0 eth0
[root@centos7 ~]# brctl show

br0 網絡卡down

啟用br0網絡卡

[root@centos7 ~]# ip link set br0 up
[root@centos7 ~]# ip a

br0 現在是up

[root@centos7 ~]# brctl show

eth1 還沒有加入網橋中

現在是ping不通的

把eth1加入網橋

[root@centos7 ~]# brctl addif br0 eth1

網路立即通了

[root@centos7 ~]# brctl show

網橋裡有eth0和eth1兩個介面

網橋MAC表


[root@centos7 ~]# brctl show
[root@centos7 ~]# btctl stp br0 on
[root@centos7 ~]# brctl show

開啟STP,生成樹協議,防止交換機產生環路

生成樹協議,如果發現網路中有迴環,會禁用掉此介面,避免網路中出現迴環造成網路風暴

nmcli命令建立網橋


[root@centos7 ~]# cdnet
[root@centos7 ~]# nmcli connection add con-name mybro type bridge ifname br0
[root@centos7 ~]# brctl show

nmcli 建立網橋


[root@centos7 ~]# brctl show
[root@centos7 ~]# nmcli connection add con-name mybr0-port0 ifname eth0 type bridge-slave master br0
[root@centos7 ~]# brctl show

把eth0加入網橋


[root@centos7 ~]# nmcli connection add con-name mybr0-port1 ifname eth1 type bridge-slave master br0
[root@centos7 ~]# nmcli connection

把eth1 加入網橋


[root@centos7 ~]# nmcli connection reload
[root@centos7 ~]# nmcli connection
[root@centos7 ~]# nmcli connection up mybro-port0
[root@centos7 ~]# nmcli connection up mybro-port1
[root@centos7 ~]# nmcli connection

現在就通了

[root@centos7 ~]# cdnet
[root@centos7 network-scripts]# ls
ifcfg-eth0.bak ifdown-eth ifdown-sit ifup-eth ifup-ppp init.ipv6-global
ifcfg-lo ifdown-ippp ifdown-Team ifup-ippp ifup-routes network-functions
ifcfg-mybr0 ifdown-ipv6 ifdown-TeamPort ifup-ipv6 ifup-sit network-functions-ipv6
ifcfg-mybr0-port0 ifdown-isdn ifdown-tunnel ifup-isdn ifup-Team
ifcfg-mybr0-port1 ifdown-post ifup ifup-plip ifup-TeamPort
ifdown ifdown-ppp ifup-aliases ifup-plusb ifup-tunnel
ifdown-bnep ifdown-routes ifup-bnep ifup-post ifup-wireless
[root@centos7 network-scripts]# cat ifcfg-mybr0
STP=yes
BRIDGING_OPTS=priority=32768
TYPE=Bridge
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=mybr0
UUID=58a86a2a-3eff-49fc-8ffb-0965beed3b86
DEVICE=br0
ONBOOT=yes
[root@centos7 network-scripts]# cat ifcfg-mybr0-port0
TYPE=Ethernet
NAME=mybr0-port0
UUID=05c1717d-fdfb-46df-9b97-a8dc1e872b10
DEVICE=eth0
ONBOOT=yes
BRIDGE=br0
[root@centos7 network-scripts]# cat ifcfg-mybr0-port1
TYPE=Ethernet
NAME=mybr0-port1
UUID=cca3edf9-d5f9-49b1-aaa6-6b619b9786d1
DEVICE=eth1
ONBOOT=yes
BRIDGE=br0
`

10.ubuntu網路配置檔案格式
`root@ubuntu18:/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.18/24
gateway4: 10.0.0.2
nameservers:
search: [neteagles.cn, neteagles.com]
addresses: [223.5.5.5, 223.6.6.6] `