Scripts/make-mac.sh: Difference between revisions
From Xen
Jump to navigationJump to search
Lars.kurth (talk | contribs) (Created page with "The following, is a little script that can be used to assign unique MAC addresses based on the name of a VM and a Xen bridge. <pre> #!/bin/bash if $# < 1 ; then ech...") |
Lars.kurth (talk | contribs) No edit summary |
||
Line 32: | Line 32: | ||
echo $mac |
echo $mac |
||
</pre> |
</pre> |
||
[[Category:Networking]] |
Latest revision as of 16:15, 7 September 2018
The following, is a little script that can be used to assign unique MAC addresses based on the name of a VM and a Xen bridge.
#!/bin/bash if [[ $# < 1 ]] ; then echo "Usage: $0 vmname [bridge]" exit 1 fi name=$1 bridge="xenbr0" if [[ $# > 1 ]] ; then bridge=$2 fi hmac=$(cat /sys/class/net/${bridge}/address) if [[ -z "$hmac" ]] ; then fail "Couldn't find address for device $bridge" fi # Get the host mac, and lop off the first two bytes mac=$(echo $hmac | sed 's/^..:..:\(.*$\)/\1/;') # Add an "extension" to the end based on the name macext=$(echo "$name" | md5sum | sed 's/^\(..\).*$/\1/;') # And pick a number for the first byte that has bit 2 set ("local") mac="5a:${mac}:${macext}" echo $mac