Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # let host and guests talk to each other over macvlan
  4. # configures a macvlan interface on the hypervisor
  5. # run this on the hypervisor (e.g. in /etc/rc.local)
  6. # made for IPv4; need modification for IPv6
  7. # meant for a simple network setup with only eth0,
  8. # and a static (manual) ip config
  9. # Evert Mouw, 2013
  10.  
  11. HWLINK=eth0
  12. MACVLN=macvlan0
  13. TESTHOST=www.google.com
  14.  
  15. # ------------
  16. # wait for network availability
  17. # ------------
  18.  
  19. while ! ping -q -c 1 $TESTHOST > /dev/null
  20. do
  21. echo "$0: Cannot ping $TESTHOST, waiting another 5 secs..."
  22. sleep 5
  23. done
  24.  
  25. # ------------
  26. # get network config
  27. # ------------
  28.  
  29. IP=$(ip address show dev $HWLINK | grep "inet " | awk '{print $2}')
  30. NETWORK=$(ip -o route | grep $HWLINK | grep -v default | awk '{print $1}')
  31. GATEWAY=$(ip -o route | grep default | awk '{print $3}')
  32.  
  33. # ------------
  34. # setting up $MACVLN interface
  35. # ------------
  36.  
  37. ip link add link $HWLINK $MACVLN type macvlan mode bridge
  38. ip address add $IP dev $MACVLN
  39. ip link set dev $MACVLN up
  40.  
  41. # ------------
  42. # routing table
  43. # ------------
  44.  
  45. # empty routes
  46. ip route flush dev $HWLINK
  47. ip route flush dev $MACVLN
  48.  
  49. # add routes
  50. ip route add $NETWORK dev $MACVLN metric 0
  51.  
  52. # add the default gateway
  53. ip route add default via $GATEWAY
  54.  
  55. echo 1 > /sys/module/kvm/parameters/ignore_msrs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement