vlan:https://www.cnblogs.com/du-z/p/10802786.html
trunk:https://www.cnblogs.com/du-z/p/10804773.html
Linux Bridge : 基本原理就是创建一个桥接接口 br0 ,在物理网卡和虚拟网络接口之间传递数据,此种方式host却可以和vm联通。
vim /etc/sysconfig/network-scripts/ifcfg-eth0
...
TYPE=Ethernet
NAME=eth0
DEVICE=eth0
ONBOOT=yes
BRIDGE=br0
...
vim /etc/sysconfig/network-scripts/ifcfg-br0
...
TYPE=Bridge
NAME=br0
DEVICE=br0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.137.134
PREFIX=24
GATEWAY=192.168.137.2
DNS=8.8.8.8
DNS2=114.114.114.114
...
## yum install bridge-utils -y
##brctl show 查看网桥配置
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c294ea15a no ens33
virbr0 8000.525400eb441b yes virbr0-nic
##brctl 命令帮助手册
[root@localhost ~]# brctl --help
Usage: brctl [commands]
commands:
addbr <bridge> add bridge #添加网桥
delbr <bridge> delete bridge #删除网桥
addif <bridge> <device> add interface to bridge #向网桥添加接口
delif <bridge> <device> delete interface from bridge #删除网桥上接口
hairpin <bridge> <port> {on|off} turn hairpin on/off
setageing <bridge> <time> set ageing time
setbridgeprio <bridge> <prio> set bridge priority
setfd <bridge> <time> set bridge forward delay
sethello <bridge> <time> set hello time
setmaxage <bridge> <time> set max message age
setpathcost <bridge> <port> <cost> set path cost
setportprio <bridge> <port> <prio> set port priority
show [ <bridge> ] show a list of bridges #查看网桥列表
showmacs <bridge> show a list of mac addrs #查看物理地址列表
showstp <bridge> show bridge stp info
stp <bridge> {on|off} turn stp on/off
[root@localhost ~]# lsmod |grep 8021q
[root@localhost ~]# modprobe 8021q
[root@localhost ~]# lsmod |grep 8021q
8021q 33104 0
garp 14384 1 8021q
mrp 18542 1 8021q
# 在/etc/sysconfig/modules下增加一个8021q.modules文件
[root@localhost ~]# vim /etc/sysconfig/modules/8021q.modules
...
modprobe 8021q
...
[root@localhost ~]# rpm -ivh vconfig-1.9-16.el7.x86_64.rpm #需用网络源
[root@localhost ~]# rpm -qa |grep vconfig
vconfig-1.9-16.el7.x86_64
[root@localhost ~]# ifconfig
ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.137.137 netmask 255.255.255.0 broadcast 192.168.137.255
inet6 fe80::f34c:437:4b83:f0b4 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:30:5c:f9 txqueuelen 1000 (Ethernet)
RX packets 12004 bytes 915163 (893.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1195 bytes 233853 (228.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
## 注意:修改网卡配置文件中:BOOTPROTO=static
# vconfig add ens38 10
# vconfig add ens38 10
vlan接口文件:
# vim ifcfg-ens38.10
VLAN=yes #启用vlan
TYPE=vlan #类型vlan
PHYSDEV=ens38vlan #物理设备网卡
VLAN_ID=10 #vlan_id
ONBOOT=yes # 自启
ZONE=trusted #开启作用域
DEVICE=ens38.10 #设备名
BRIDGE=brvlan10 #网桥
# vim ifcfg-ens38.20
VLAN=yes
TYPE=vlan
PHYSDEV=ens38
VLAN_ID=20
ONBOOT=yes
ZONE=trusted
DEVICE=ens38.20
BRIDGE=brvlan20
vlan网桥文件:
## vim ifcfg-brvlan-10
YPE=bridge
BOOTPROTO=static
NAME=brvlan-10
DEVICE=brvlan-10
ONBOOT=yes
## vim ifcfg-brvlan-20
TYPE=bridge
BOOTPROTO=static
NAME=brvlan-20
DEVICE=brvlan-20
ONBOOT=yes
# brctl addif brvlan-10 ens38.10
# brctl addif brvlan-20 ens38.20
# systemctl restart network
常用的有三种:
- mode=0:平衡负载模式,有自动备援,但需要”Switch”支援及设定。
- mode=1:自动备援模式,其中一条线若断线,其他线路将会自动备援。
- mode=6:平衡负载模式,有自动备援,不必”Switch”支援及设定。
# cat ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=none
DEVICE=eth1
ONBOOT=yes
MASTER=bond0
SLAVE=yes
# 载入bond模块:
# modprobe bonding
# cat ifcfg-bond0
DEVICE=bond0
TYPE=Bond
NAME=bond0
BONDING_MASTER=yes
BOOTPROTO=static
USERCTL=no
ONBOOT=yes
#IPADDR=192.168.10.10
#PREFIX=24
#GATEWAY=192.168.10.19
BONDING_OPTS="mode=6 miimon=100"
BRIDGE=br1
# cat ifcfg-br1
TYPE=Bridge
DEVICE=br1
ONBOOT=yes
IPADDR=192.168.10.1
IPADDR1=192.168.20.1
IPADDR2=192.168.30.1
IPADDR3=192.168.40.1
IPADDR4=192.168.50.1
PREFIX3=24
PREFIX4=24
#GATEWAY=172.16.0.1
#DNS1=172.16.254.251
#DNS2=223.5.5.5
# 查看网卡信息:
ethtool bond0
手机扫一扫
移动阅读更方便
你可能感兴趣的文章