title: How to get MAC address in CentOS 7 using terminal and not using NIC?
body: <p>In one of the project, client has upgraded their server from CentOS6 to CentOS7. In CentOS 6, we used to get MAC address from "ifconfig -a" command and fetching out MAC address by regex (.<em>HWaddr.</em>:(.*)). Now in CentOS 7, ifconfig is not working. We are using java and suggested to use below code which is working fine, but we have to provide solution using command only and not using Java APIs: </p>
  
  <pre><code>String getLocalServerMAC(){
      String macAddress = null;
      String macAddressToBeValidated = null;
      try {
          Enumeration&lt;NetworkInterface&gt; networkInterfaces = NetworkInterface.getNetworkInterfaces();
          for (NetworkInterface networkInterface : Collections.list(networkInterfaces)) {
              if (networkInterface != null &amp;&amp; networkInterface.isUp()) {
                  macAddressToBeValidated = getNotValidatedMACAddress(networkInterface);
                  if (macAddressToBeValidated != null &amp;&amp; !macAddressToBeValidated.isEmpty()) {
                      macAddress = macAddressToBeValidated; break;
                  }
              }
          }
      }catch (SocketException|RuntimeException e) {
          LOGGER.error(e.getMessage(), e);
      }
      return macAddress;
  }
  
  private static String getNotValidatedMACAddress(NetworkInterface networkInterface) throws SocketException {
      StringBuilder macAddressToBeValidated = new StringBuilder();
      byte[] macAddressAsStream = networkInterface.getHardwareAddress();
      if(macAddressAsStream != null) {
          for (int i = 0; i &lt; macAddressAsStream.length; i++){
              macAddressToBeValidated.append(String.format("%02X%s", macAddressAsStream[i], (i &lt; macAddressAsStream.length - 1) ? "-" : ""));
          }
      }
      return macAddressToBeValidated.toString();
  }
  </code></pre>