-1

I am writing a bash script to change MAC (Ethernet) address back to default one after changing it. In order to match the default value and the current value, the script needs the default value. However I am not sure where to store the default MAC address. Currently The address is hard-coded and stored in the script

MAC=**:**:**:**:**

It doesn't seem appropriate to hardcode like this for security purposes, but retrieving default MAC address seems pretty hard because the MAC address has already changed to another value.

Possible solution is to store it in another file or some other places. Are there any ideas to solve without hardcoding it?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • When youe MAC can be obtained from the TCP/IP stack itself, it doesn't make much sense to try and hide it -- it's not some secret piece of information. Just save it wherever is the most convenient. Passwords -- those are secret, MAC addresses are not. – David C. Rankin Aug 04 '21 at 02:53
  • 1
    Good question lol, here's an answer https://stackoverflow.com/a/20686749/2834978 – LMC Aug 04 '21 at 03:26
  • As @DavidC.Rankin explained, it might be nonsense to hide it. Maybe I should ask another question later about how to avoid hardcoding values, thanks. – Animal Farm Aug 04 '21 at 06:25

1 Answers1

1

Protecting a public information like a MAC address is a bit strange but what about cryptography? Let's assume you have GNU gpg installed, and a key pair with identity animal.farm@orwell.gb. Then:

echo "$MAC" | gpg -e -r animal.farm@orwell.gb > ~/.mac

Will encrypt the value of shell variable MAC and store the encrypted value in a file named .mac in your home directory. Decrypt with:

gpg -d ~/.mac 2> /dev/null

If you protected your private key with a passphrase (recommended) you will be asked for it.

Renaud Pacalet
  • 25,260
  • 3
  • 34
  • 51