<p>I have a software running in OpenShift (Kubernetes) where the licence is based on the MAC address. When restarting the app, the MAC address of the container changes and I have to apply for a new licence file.</p>

<p>Since there are no static MAC-Adressess in k8s pods, I want to spoof the Java call to NetworkInterface.getHardwareAddress() to trick the software into thinking the MAC Address is still the same.</p>

<pre><code>Enumeration enumeration = NetworkInterface.getNetworkInterfaces();
while (enumeration.hasMoreElements()) {
    NetworkInterface networkInterface = (NetworkInterface) enumeration.nextElement();
    if (networkInterface.isLoopback() || networkInterface.isPointToPoint() || networkInterface.isVirtual()) {
        continue;
    }
    if (networkInterface.isUp()) {
        byte[] arrayOfByte = networkInterface.getHardwareAddress();
        if (arrayOfByte != null &amp;&amp; arrayOfByte.length == 6) {
            StringBuilder stringBuilder = new StringBuilder();
            for (byte b = 0; b &lt; arrayOfByte.length; b++) {
                if (b != 0) {
                    stringBuilder.append(":");
                }
                stringBuilder.append(String.format("%02x", arrayOfByte[b]));
            }
            System.out.println(networkInterface.getName() + ": " + stringBuilder);
        }
    }
}
</code></pre>

<p>actual: eth0: 01:14:4d:ec:01:42</p>

<p>expected: eth0: ee:ee:ee:ee:ee:ee</p>

leNerd42
<p>Unfortunately, you cannot do this in Java. </p>

<p>The method <code>NetworkInterface::getNetworkInterfaces()</code> is implemented as <code>native</code>, which means it does not access any specific field to obtain its results. If it did, you might have luck hacking stuff with reflection, but as it stands, you have to manage it in your OS configuration instead.</p>

<p>EDIT: As for Kubernetes solutions, you might want to look <a href="https://www.reddit.com/r/kubernetes/comments/8a36jw/set_mac_address_possible_with_k8s/" rel="nofollow noreferrer">here</a> </p>
