#!/bin/bash #修改混杂模式命令: ifconfig 查看网卡,记录网卡编号(XXXX) ip linkset XXXX promisc on ifconfig 查看是否开启混杂模式,网卡属性中含有PROMISC字样即开启
二、配合namespace基本使用
#!/bin/bash ip link add [link DEV] [ name ] NAME [ txqueuelen PACKETS ] [ address LLADDR ] [ broadcast LLADDR ] [ mtu MTU ] [ numtxqueues QUEUE_COUNT ] [ numrxqueues QUEUE_COUNT ] type TYPE [ ARGS ] option: link DEVICE:指定要操作的物理设备 name NAME:指定新虚拟设备的名称 type TYPE:指定新设备的类型 bridge - Ethernet Bridge device bond - Bonding device dummy - Dummy network interface ifb - Intermediate Functional Block device ipoib - IP over Infiniband device macvlan - Virtual interface base on link layer address (MAC) macvtap - Virtual interface based on link layer address (MAC) and TAP. vcan - Virtual Controller Area Network interface veth - Virtual ethernet interface vlan - 802.1q tagged virtual LAN interface vxlan - Virtual eXtended LAN ip6tnl - Virtual tunnel interface IPv4|IPv6 over IPv6 ipip - Virtual tunnel interface IPv4 over IPv4 sit - Virtual tunnel interface IPv6 over IPv4 gre - Virtual tunnel interface GRE over IPv4 gretap - Virtual L2 tunnel interface GRE over IPv4 ip6gre - Virtual tunnel interface GRE over IPv6 ip6gretap - Virtual L2 tunnel interface GRE over IPv6 vti - Virtual tunnel interface nlmon - Netlink monitoring device geneve - GEneric NEtwork Virtualization Encapsulation macsec - Interface for IEEE 802.1AE MAC Security (MACsec) numtxqueues QUEUE_COUNT:指定新设备的传输队列数 numrxqueues QUEUE_COUNT:指定新设备的接收队列数
macvvlan创建 ip link add link DEVICE name NAME type { macvlan | macvtap } mode { private | vepa | bridge | passthru [ nopromisc ] } 范例:ip link add eth0 dev macvlan1 type macvlan mode bridge 创建一个于eth0链接的macvlan网卡,其是桥接模式
创建macvlan接口
ip link add eth0 dev macvlan1 type macvlan mode bridge
创建namespace空间
ip netns add namespace1 创建命名空间
ip link set macvlan1 netns namespace1 将macvlan1绑定到命名空间1上
配置macvlan网络‘
ip netns exec amespace1 ip addr add 10.0.0.2/24 dev macvlan1 配置macvlan ip