Linux Bridge

4270阅读 0评论2018-03-27 今生路人甲
分类:系统运维

Linux Bridge
创建bridge流程
ip addr flush dev ens9
#刷新网络接口,临时配置的ip地址等配置信息将会被清楚
[root@localhost ~]# ip link add host_bridge1 type bridge
#创建一个bridge设备
ip link show host_bridge1
5: host_bridge1: mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
link/ether 76:8e:8d:79:e3:4d brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# ip addr add 10.90.241.200/24 dev host_bridge1
[root@localhost ~]# ip addr show dev host_bridge1
5: host_bridge1: mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 76:8e:8d:79:e3:4d brd ff:ff:ff:ff:ff:ff
inet 10.90.241.200/24 scope global host_bridge1
valid_lft forever preferred_lft forever
[root@localhost ~]# ip link set dev ens9 master host_bridge1
[root@localhost ~]# ip link show
1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens9: mtu 1500 qdisc pfifo_fast master host_bridge1 state UP mode DEFAULT qlen 1000
link/ether 52:54:00:ce:25:48 brd ff:ff:ff:ff:ff:ff
3: eth0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 52:54:00:d8:82:cc brd ff:ff:ff:ff:ff:ff
4: docker0: mtu 1500 qdisc noqueue state DOWN mode DEFAULT
link/ether 02:42:98:98:48:d9 brd ff:ff:ff:ff:ff:ff
5: host_bridge1: mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
link/ether 52:54:00:ce:25:48 brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# bridge link show
2: ens9 state UP : mtu 1500 master host_bridge1 state disabled priority 32 cost 19
[root@localhost ~]# ip link set host_bridge1 up
[root@localhost ~]# ip link show host_bridge1
5: host_bridge1: mtu 1500 qdisc noqueue state UP mode DEFAULT qlen 1000
link/ether 52:54:00:ce:25:48 brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# ping 10.90.241.200
PING 10.90.241.200 (10.90.241.200) 56(84) bytes of data.
64 bytes from 10.90.241.200: icmp_seq=1 ttl=64 time=1.64 ms
^C
--- 10.90.241.200 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.645/1.645/1.645/0.000 ms
[root@localhost ~]# ping 10.90.241.201
PING 10.90.241.201 (10.90.241.201) 56(84) bytes of data.
64 bytes from 10.90.241.201: icmp_seq=1 ttl=64 time=0.142 ms
64 bytes from 10.90.241.201: icmp_seq=2 ttl=64 time=0.086 ms
^C
--- 10.90.241.201 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.086/0.114/0.142/0.028 ms
[root@localhost ~]# ping 10.88.38.52
connect: Network is unreachable
[root@localhost ~]# ip route add default via 10.90.241.1
[root@localhost ~]# ip route
default via 10.90.241.1 dev host_bridge1
10.90.241.0/24 dev host_bridge1 proto kernel scope link src 10.90.241.200
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
[root@localhost ~]# ping -c 2 10.88.38.52
PING 10.88.38.52 (10.88.38.52) 56(84) bytes of data.
64 bytes from 10.88.38.52: icmp_seq=1 ttl=123 time=3.21 ms
64 bytes from 10.88.38.52: icmp_seq=2 ttl=123 time=1.17 ms

--- 10.88.38.52 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 1.178/2.195/3.212/1.017 ms

下面是另一台创建的过程
[root@localhost ~]# ip addr flush ens9
[root@localhost ~]# ip link add host_bridge2 type bridge
[root@localhost ~]# ip link show host_bridge2
5: host_bridge2: mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
link/ether d2:d5:a0:00:3c:1c brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# ip addr add 10.90.241.201/24 dev host_bridge2
[root@localhost ~]# ip addr show dev host_bridge2
5: host_bridge2: mtu 1500 qdisc noop state DOWN qlen 1000
link/ether d2:d5:a0:00:3c:1c brd ff:ff:ff:ff:ff:ff
inet 10.90.241.201/24 scope global host_bridge2
valid_lft forever preferred_lft forever
[root@localhost ~]# ip link set dev ens9 master host_bridge2
[root@localhost ~]# ip link show
1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens9: mtu 1500 qdisc pfifo_fast master host_bridge2 state UP mode DEFAULT qlen 1000
link/ether 52:54:00:30:e3:f6 brd ff:ff:ff:ff:ff:ff
3: eth1: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 52:54:00:38:49:d7 brd ff:ff:ff:ff:ff:ff
4: docker0: mtu 1500 qdisc noqueue state DOWN mode DEFAULT
link/ether 02:42:d8:88:c2:f3 brd ff:ff:ff:ff:ff:ff
5: host_bridge2: mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
link/ether 52:54:00:30:e3:f6 brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# bridge link show
2: ens9 state UP : mtu 1500 master host_bridge2 state disabled priority 32 cost 19
[root@localhost ~]# ip link set host_bridge2 up
[root@localhost ~]# ip link show host_bridge2
5: host_bridge2: mtu 1500 qdisc noqueue state UP mode DEFAULT qlen 1000
link/ether 52:54:00:30:e3:f6 brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# ip route show
10.90.241.0/24 dev host_bridge2 proto kernel scope link src 10.90.241.201
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
[root@localhost ~]# ip route add default via 10.90.241.1
[root@localhost ~]# ping 10.88.38.52
PING 10.88.38.52 (10.88.38.52) 56(84) bytes of data.
64 bytes from 10.88.38.52: icmp_seq=1 ttl=123 time=1.17 ms
64 bytes from 10.88.38.52: icmp_seq=2 ttl=123 time=1.19 ms
^C
--- 10.88.38.52 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 1.172/1.185/1.198/0.013 ms

上一篇:Docker Network --Bridge
下一篇:Linux network - virtual network