Macvlan

Aus xinux wiki
Wechseln zu: Navigation, Suche

important

!main interface musn't have a IP

set links

  • ip link add link eth0 mac0 address 00:22:22:22:22:00 type macvlan
  • ip link add link eth0 mac1 address 00:22:22:22:22:11 type macvlan
  • ip link add link eth0 mac2 address 00:22:22:22:22:22 type macvlan

set ips

  • ip addr add 192.168.244.180/21 brd + dev mac0
  • ip addr add 192.168.244.181/21 brd + dev mac1
  • ip addr add 192.168.244.182/21 brd + dev mac2

bring the interfaces up

  • ip link set dev eth0 up
  • ip link set dev mac0 up
  • ip link set dev mac1 up
  • ip link set dev mac2 up

settings in proc system

  • echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
  • echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
  • echo 2 >/proc/sys/net/ipv4/conf/all/rp_filter

script

#!/bin/bash
case $1 in
start)
  echo start macvlan
  ip link add link eth0 mac0 address 00:22:22:22:22:00 type macvlan
  ip link add link eth0 mac1 address 00:22:22:22:22:11 type macvlan
  ip link add link eth0 mac2 address 00:22:22:22:22:22 type macvlan
  ip addr add 192.168.244.180/21 brd + dev mac0
  ip addr add 192.168.244.181/21 brd + dev mac1
  ip addr add 192.168.244.182/21 brd + dev mac2
  ip link set dev eth0 up 
  ip link set dev mac0 up 
  ip link set dev mac1 up 
  ip link set dev mac2 up 
  echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
  echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
  echo 2 >/proc/sys/net/ipv4/conf/all/rp_filter
 ;;
stop)
  echo stop macvlan
  echo 0 >/proc/sys/net/ipv4/conf/all/arp_ignore
  echo 0 >/proc/sys/net/ipv4/conf/all/arp_announce
  echo 0 >/proc/sys/net/ipv4/conf/all/rp_filter
  ip link set dev mac0 down 
  ip link set dev mac1 down
  ip link set dev mac2 down
  ip link set dev eth0 down 
  ip addr del 192.168.244.180/21 brd + dev mac0
  ip addr del 192.168.244.181/21 brd + dev mac1
  ip addr del 192.168.244.182/21 brd + dev mac2
  ip link del link eth0 mac0 address 00:22:22:22:22:00 type macvlan
  ip link del link eth0 mac1 address 00:22:22:22:22:11 type macvlan
  ip link del link eth0 mac2 address 00:22:22:22:22:22 type macvlan
 ;;
esac


links