Chinaunix首页 | 论坛 | 博客
  • 博客访问: 491859
  • 博文数量: 28
  • 博客积分: 858
  • 博客等级: 一等列兵
  • 技术积分: 852
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-02 14:13
文章分类

全部博文(28)

文章存档

2020年(1)

2019年(1)

2018年(5)

2017年(1)

2014年(1)

2013年(2)

2012年(17)

分类: 系统运维

2018-03-27 10:47:53

Linux Bridge
创建bridge流程
  • 清除原有配置
ip addr flush dev ens9
#刷新网络接口,临时配置的ip地址等配置信息将会被清楚
  • 创建bridge设备
[root@localhost ~]# ip link add host_bridge1 type bridge
#创建一个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
  • 配置一个ip,使bridge变成L3 bridge
[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
  • 绑定物理接口道bridge设备
[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
  • 检查bridge设备
[root@localhost ~]# bridge link show
2: ens9 state UP : mtu 1500 master host_bridge1 state disabled priority 32 cost 19
  • 开启bridge设备
[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

阅读(4302) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~