Linux网络总结(Bridge/brctl/ip link/vconfig)
ip link创建bond:
# ip link add bond0 type bond
# ip link set bond0 type bond miimon 100 mode balance-alb
# ip link set eth0 down
# ip link set eth0 master bond0
# ip link set eth1 down
# ip link set eth1 master bond0
# ip link set bond0 up
ip link创建vlan子接口:
# ip link add link bond0 name bond0.2 type vlan id 2
# ip link set bond0.2 up
# ip link add link bond0 name bond0.3 type vlan id 3
# ip link set bond0.3 up
ip link创建桥:
# ip link add br0 type bridge
# ip link set bond0.2 master br0
# ip link set br0 up
# ip link add br1 type bridge
# ip link set bond0.3 master br1
# ip link set br1 up
ip link将设备添加至桥
# ip link set guest_1_tap_0 master br0
# ip link set guest_2_tap_0 master br0
# ip link set guest_2_tap_1 master br1
# ip link set guest_3_tap_0 master br1
开启桥vlan_filtering功能:
# ip link set br0 type bridge vlan_filtering 1
或者
#echo 1 > /sys/class/net/docker0/bridge/vlan_filtering
添加设置设备或者桥上允许vlan通过:
# bridge vlan add dev guest_2_tap_1 vid 3 pvid untagged master
# bridge vlan add dev bond0 vid 3 master
添加桥,并添加设备:
$ brctl addif br0 veth0.5
$ brctl addbr br1
Linux 上配置网络设备命令举例:
以 Redhat6.2 红帽 Linux 发行版为例,如果已安装 VLAN 内核模块和管理工具 vconfig,TAP/TUN 设备管理工具 tunctl,那么可以用以下命令设置前述网络设备:
创建 Bridge:brctl addbr [BRIDGE NAME]
删除 Bridge:brctl delbr [BRIDGE NAME]
attach 设备到 Bridge:brctl addif [BRIDGE NAME] [DEVICE NAME]
从 Bridge detach 设备:brctl delif [BRIDGE NAME] [DEVICE NAME]
查询 Bridge 情况:brctl show
创建 VLAN 设备:vconfig add [PARENT DEVICE NAME] [VLAN ID]
删除 VLAN 设备:vconfig rem [VLAN DEVICE NAME]
设置 VLAN 设备 flag:vconfig set_flag [VLAN DEVICE NAME] [FLAG] [VALUE]
设置 VLAN 设备 qos:
vconfig set_egress_map [VLAN DEVICE NAME] [SKB_PRIORITY] [VLAN_QOS]
vconfig set_ingress_map [VLAN DEVICE NAME] [SKB_PRIORITY] [VLAN_QOS]
查询 VLAN 设备情况:cat /proc/net/vlan/[VLAN DEVICE NAME]
创建 VETH 设备:ip link add link [DEVICE NAME] type veth
创建 TAP 设备:tunctl -p [TAP DEVICE NAME]
删除 TAP 设备:tunctl -d [TAP DEVICE NAME]
查询系统里所有二层设备,包括 VETH/TAP 设备:ip link show
删除普通二层设备:ip link delete [DEVICE NAME] type [TYPE]