openvswitch 使用记录(二)--vlan 环境搭建(1)

ovs-br1 即host1环境

 

host1 上ovs-br1创建过程

1、查看物理网卡

[root@localhost openvswitch-2.12.0]# ifconfig

enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 10.20.42.99  netmask 255.255.255.0  broadcast 10.20.42.255

        inet6 fe80::20b:2fff:fe17:4706  prefixlen 64  scopeid 0x20<link>

        ether 00:0b:2f:17:47:06  txqueuelen 1000  (Ethernet)

        RX packets 74939  bytes 72871505 (69.4 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 6264  bytes 473439 (462.3 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

[root@localhost openvswitch-2.12.0]# ovs-vsctl show

c41a7ff7-3835-4d77-8870-e9210053cb86

ovs_version: "2.12.0"

2、添加ovs-br1网桥

[root@localhost openvswitch-2.12.0]# ovs-vsctl add-br ovs-br1

[root@localhost openvswitch-2.12.0]# ovs-vsctl show

c41a7ff7-3835-4d77-8870-e9210053cb86

    Bridge "ovs-br1"

        Port "ovs-br1"

            Interface "ovs-br1"

                type: internal

    ovs_version: "2.12.0"

3、添加端口(物理网卡)添加到ovs-br1中

[root@localhost openvswitch-2.12.0]# ovs-vsctl add-port ovs-br1 enp2s0

注意:此时可能网络无法连接外网,如果需要连接外网的话需要如下步骤:

[root@localhost openvswitch-2.12.0]# ifconfig enp2s0 0

[root@localhost openvswitch-2.12.0]# killall dhclient

[root@localhost ext_tools]# ifconfig ovs-br1 up

[root@localhost openvswitch-2.12.0]# dhclient ovs-br1

[root@localhost openvswitch-2.12.0]# ifconfig ovs-br1

ovs-br1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 10.20.42.99  netmask 255.255.255.0  broadcast 10.20.42.255

        inet6 fe80::d85e:7dff:fea4:de4a  prefixlen 64  scopeid 0x20<link>

        ether 00:0b:2f:17:47:06  txqueuelen 1000  (Ethernet)

        RX packets 206  bytes 26321 (25.7 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 49  bytes 8536 (8.3 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

此时可以连接外网

[root@localhost ext_tools]# ping www.baidu.com

PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.

64 bytes from 61.135.169.121: icmp_seq=1 ttl=54 time=1.48 ms

64 bytes from 61.135.169.121: icmp_seq=2 ttl=54 time=1.56 ms

64 bytes from 61.135.169.121: icmp_seq=3 ttl=54 time=1.44 ms

 

[root@localhost openvswitch-2.12.0]# ovs-vsctl show

c41a7ff7-3835-4d77-8870-e9210053cb86

    Bridge "ovs-br1"

        Port "ovs-br1"

            Interface "ovs-br1"

                type: internal

        Port "enp2s0"

            Interface "enp2s0"

    ovs_version: "2.12.0"

[root@localhost openvswitch-2.12.0]#

 

4、向网桥ovs-br1中添加vlan端口p10 vid为10

[root@localhost openvswitch-2.12.0]# ovs-vsctl add-port ovs-br1 p10 tag=10 -- set interface p10 type=internal

5、向网桥ovs-br1中添加vlan端口p20 vid为20

[root@localhost openvswitch-2.12.0]# ovs-vsctl add-port ovs-br1 p20 tag=20 -- set interface p20 type=internal

[root@localhost openvswitch-2.12.0]# ovs-vsctl show

c41a7ff7-3835-4d77-8870-e9210053cb86

    Bridge "ovs-br1"

        Port "p20"

            tag: 20

            Interface "p20"

                type: internal

        Port "p10"

            tag: 10

            Interface "p10"

                type: internal

        Port "ovs-br1"

            Interface "ovs-br1"

                type: internal

        Port "enp2s0"

            Interface "enp2s0"

    ovs_version: "2.12.0"

 

注意:Port "enp2s0" 默认为trunk端口,允许所有的vlan id通过

 

 

6、创建vm1网卡及分配ip地址

 

 

 

 

[loongson@localhost ~]$ ifconfig eth0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.1.2  netmask 255.255.255.0  broadcast 192.168.1.255

        inet6 fe80::5054:ff:feca:274f  prefixlen 64  scopeid 0x20<link>

        ether 52:54:00:ca:27:4f  txqueuelen 1000  (Ethernet)

        RX packets 0  bytes 0 (0.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 21  bytes 2638 (2.5 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

2、vm2网卡创建以及ip地址配置(步骤同上)

 

 

 

[loongson@localhost ~]$ ifconfig eth0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.1.3  netmask 255.255.255.0  broadcast 192.168.1.255

        inet6 fe80::5054:ff:feea:f052  prefixlen 64  scopeid 0x20<link>

        ether 52:54:00:ea:f0:52  txqueuelen 1000  (Ethernet)

        RX packets 7  bytes 572 (572.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 29  bytes 2018 (1.9 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

到此为止 host1 上的vm1和vm2搭建完成

host2搭建过程看下一篇文章openvswitch 使用记录(二)--vlan 环境搭建(2)

https://mp.csdn.net/console/editor/html/104468102

--------------------------------------------------------------------------

等待host2上环境搭建完成后测试结果

验证结果如下

vm1----ping ---->vm3、vm4    以及vm1---ping--->vm2、vm5、vm6

[loongson@localhost ~]$ ifconfig eth0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.1.2  netmask 255.255.255.0  broadcast 192.168.1.255

        inet6 fe80::5054:ff:feca:274f  prefixlen 64  scopeid 0x20<link>

        ether 52:54:00:ca:27:4f  txqueuelen 1000  (Ethernet)

        RX packets 36  bytes 2806 (2.7 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 58  bytes 5396 (5.2 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

[loongson@localhost ~]$ ping 192.168.1.4

PING 192.168.1.4 (192.168.1.4) 56(84) bytes of data.

64 bytes from 192.168.1.4: icmp_seq=1 ttl=64 time=44.4 ms

64 bytes from 192.168.1.4: icmp_seq=2 ttl=64 time=36.0 ms

^C

--- 192.168.1.4 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1001ms

rtt min/avg/max/mdev = 36.086/40.290/44.495/4.209 ms

[loongson@localhost ~]$ ping 192.168.1.5

PING 192.168.1.5 (192.168.1.5) 56(84) bytes of data.

64 bytes from 192.168.1.5: icmp_seq=1 ttl=64 time=36.0 ms

64 bytes from 192.168.1.5: icmp_seq=2 ttl=64 time=35.0 ms

64 bytes from 192.168.1.5: icmp_seq=3 ttl=64 time=37.8 ms

^C

--- 192.168.1.5 ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2003ms

rtt min/avg/max/mdev = 35.066/36.322/37.809/1.131 ms

[loongson@localhost ~]$ ping 192.168.1.3

PING 192.168.1.3 (192.168.1.3) 56(84) bytes of data.

From 192.168.1.2 icmp_seq=1 Destination Host Unreachable

From 192.168.1.2 icmp_seq=2 Destination Host Unreachable

From 192.168.1.2 icmp_seq=3 Destination Host Unreachable

^C

--- 192.168.1.3 ping statistics ---

5 packets transmitted, 0 received, +3 errors, 100% packet loss, time 4041ms

pipe 3

[loongson@localhost ~]$ ping 192.168.1.6

PING 192.168.1.6 (192.168.1.6) 56(84) bytes of data.

From 192.168.1.2 icmp_seq=1 Destination Host Unreachable

From 192.168.1.2 icmp_seq=2 Destination Host Unreachable

From 192.168.1.2 icmp_seq=3 Destination Host Unreachable

^C

--- 192.168.1.6 ping statistics ---

4 packets transmitted, 0 received, +3 errors, 100% packet loss, time 3022ms

pipe 3

[loongson@localhost ~]$ ping 192.168.1.7

PING 192.168.1.7 (192.168.1.7) 56(84) bytes of data.

From 192.168.1.2 icmp_seq=1 Destination Host Unreachable

From 192.168.1.2 icmp_seq=2 Destination Host Unreachable

From 192.168.1.2 icmp_seq=3 Destination Host Unreachable

^C

--- 192.168.1.7 ping statistics ---

5 packets transmitted, 0 received, +3 errors, 100% packet loss, time 4060ms

pipe 3

[loongson@localhost ~]$

 

vm2---ping--->vm5、vm6  以及vm2---ping--->vm1、vm3、vm4

[loongson@localhost ~]$ ifconfig eth0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.1.3  netmask 255.255.255.0  broadcast 192.168.1.255

        inet6 fe80::5054:ff:feea:f052  prefixlen 64  scopeid 0x20<link>

        ether 52:54:00:ea:f0:52  txqueuelen 1000  (Ethernet)

        RX packets 50  bytes 3342 (3.2 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 42  bytes 2844 (2.7 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

[loongson@localhost ~]$ ping 192.168.1.6

PING 192.168.1.6 (192.168.1.6) 56(84) bytes of data.

64 bytes from 192.168.1.6: icmp_seq=1 ttl=64 time=42.1 ms

64 bytes from 192.168.1.6: icmp_seq=2 ttl=64 time=35.2 ms

^C

--- 192.168.1.6 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1001ms

rtt min/avg/max/mdev = 35.224/38.680/42.137/3.462 ms

[loongson@localhost ~]$ ping 192.168.1.7

PING 192.168.1.7 (192.168.1.7) 56(84) bytes of data.

64 bytes from 192.168.1.7: icmp_seq=1 ttl=64 time=38.8 ms

64 bytes from 192.168.1.7: icmp_seq=2 ttl=64 time=35.1 ms

64 bytes from 192.168.1.7: icmp_seq=3 ttl=64 time=35.6 ms

^C

--- 192.168.1.7 ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2003ms

rtt min/avg/max/mdev = 35.144/36.541/38.861/1.666 ms

[loongson@localhost ~]$ ping 192.168.1.2

PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.

From 192.168.1.3 icmp_seq=1 Destination Host Unreachable

From 192.168.1.3 icmp_seq=2 Destination Host Unreachable

From 192.168.1.3 icmp_seq=3 Destination Host Unreachable

^C

--- 192.168.1.2 ping statistics ---

4 packets transmitted, 0 received, +3 errors, 100% packet loss, time 3021ms

pipe 3

[loongson@localhost ~]$ ping 192.168.1.4

PING 192.168.1.4 (192.168.1.4) 56(84) bytes of data.

From 192.168.1.3 icmp_seq=1 Destination Host Unreachable

From 192.168.1.3 icmp_seq=2 Destination Host Unreachable

From 192.168.1.3 icmp_seq=3 Destination Host Unreachable

^C

--- 192.168.1.4 ping statistics ---

4 packets transmitted, 0 received, +3 errors, 100% packet loss, time 3020ms

pipe 3

[loongson@localhost ~]$ ping 192.168.1.5

PING 192.168.1.5 (192.168.1.5) 56(84) bytes of data.

From 192.168.1.3 icmp_seq=1 Destination Host Unreachable

From 192.168.1.3 icmp_seq=2 Destination Host Unreachable

From 192.168.1.3 icmp_seq=3 Destination Host Unreachable

^C

--- 192.168.1.5 ping statistics ---

4 packets transmitted, 0 received, +3 errors, 100% packet loss, time 3019ms

pipe 3

[loongson@localhost ~]$

 

参考资料:

http://docs.openvswitch.org/en/latest/howto/vlan/

发布了13 篇原创文章 · 获赞 2 · 访问量 3246

猜你喜欢

转载自blog.csdn.net/wangyangzhizunwudi/article/details/104443831