https://wiki.xenproject.org/index.php?title=Scripts/make-mac.sh&feed=atom&action=historyScripts/make-mac.sh - Revision history2024-03-28T09:08:35ZRevision history for this page on the wikiMediaWiki 1.31.3https://wiki.xenproject.org/index.php?title=Scripts/make-mac.sh&diff=18915&oldid=prevLars.kurth at 16:15, 7 September 20182018-09-07T16:15:04Z<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 16:15, 7 September 2018</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 32:</td>
<td colspan="2" class="diff-lineno">Line 32:</td>
</tr>
<tr>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>echo $mac</div></td>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>echo $mac</div></td>
</tr>
<tr>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></pre></div></td>
<td class="diff-marker"> </td>
<td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></pre></div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty"> </td>
<td class="diff-marker">+</td>
<td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"></td>
</tr>
<tr>
<td colspan="2" class="diff-empty"> </td>
<td class="diff-marker">+</td>
<td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Networking]]</div></td>
</tr>
</table>Lars.kurthhttps://wiki.xenproject.org/index.php?title=Scripts/make-mac.sh&diff=18914&oldid=prevLars.kurth: 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..."2018-09-07T16:14:37Z<p>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 <a href="/index.php?title=$&action=edit&redlink=1" class="new" title="$ (page does not exist)"> $# < 1 </a> ; then ech..."</p>
<p><b>New page</b></p><div>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.<br />
<br />
<pre><br />
#!/bin/bash<br />
if [[ $# < 1 ]] ; then<br />
echo "Usage: $0 vmname [bridge]"<br />
exit 1<br />
fi<br />
<br />
name=$1<br />
bridge="xenbr0"<br />
<br />
if [[ $# > 1 ]] ; then<br />
bridge=$2<br />
fi<br />
<br />
hmac=$(cat /sys/class/net/${bridge}/address)<br />
<br />
if [[ -z "$hmac" ]] ; then<br />
fail "Couldn't find address for device $bridge"<br />
fi<br />
<br />
# Get the host mac, and lop off the first two bytes<br />
mac=$(echo $hmac | sed 's/^..:..:\(.*$\)/\1/;')<br />
<br />
# Add an "extension" to the end based on the name<br />
macext=$(echo "$name" | md5sum | sed 's/^\(..\).*$/\1/;')<br />
<br />
# And pick a number for the first byte that has bit 2 set ("local")<br />
mac="5a:${mac}:${macext}"<br />
<br />
echo $mac<br />
</pre></div>Lars.kurth