-1

I have few computers each with same ethernet MAC address. I want to change ethernet MAC address on each computer as soon as network card is detected so I do not have any conflicts in the network. My system is using nonstandard linux with systemd. Is it possible to configure MAC address using systemd and standard linux commands?

  • 1
    Configure a static IP of your own in /etc/network/interface! – Thushi Jun 6 '17 at 9:33
  • @Thushi I was talking about mac address. IP address is taken from dhcp. – Trismegistos Jun 6 '17 at 9:56
  • @Trismegistos, probably easiest to tie it to the distro's interface configuration scripts, and there might already be a system for doing that. Unless you really definitely want to do it manually, of course. – ilkkachu Jun 6 '17 at 11:20
  • @Trismegistos: Ok, If that's the case please do mention it clearly in your question, one will think of IP address when you just mention ethernet address. Check adding udev rules. – Thushi Jun 6 '17 at 13:01
  • 1
    @Thushi ethernet address is MAC it never been IP. IP protocol is hardware agnostic. Those are different OSI layers. – Trismegistos Jun 6 '17 at 14:46
0

Use the config line HWADDR=AA:BB:CC:DD:EE:FF in the machine's /etc/sysconfig/network-scripts/ifcfg-eth0 config file, as such:

DEVICE=eth0
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
HWADDR=AA:BB:CC:DD:EE:FF
IPADDR=10.2.3.4
NETMASK=255.255.255.0
GATEWAY=10.2.3.254
DNS1=8.8.8.8
DNS2=4.4.4.4
USERCTL=no
  • I meant MAC address not IP address. IP address is taken from DHCP and for that I need unique MAC address. Moreover there is not /etc/sysconfig on my computer. Linux distribution device runs is not standard one. I wanted to use systemd for that because it configures devices. – Trismegistos Jun 6 '17 at 9:57
  • This is for RHEL. Which Linux distro are you using? – dr01 Jun 6 '17 at 10:44
0

I'm using Parrot Home (Debian based distro) and after checking some sugestions I made a script to do it in every boot for eth0 and wlan0.

  1. Login in root and install macchanger with apt-get install macchanger -y

  2. Create a file in /etc/cron.daily/: vim /etc/cron.daily/macchanger.sh

  3. Check the name of your network adapters with ip a (in the most of cases it's eth0 and wlan0, for Ethernet and Wi-Fi respectively) and put the follow code in the file: #!/bin/bash sudo ifconfig eth0 down; sudo ifconfig wlan0 down; sudo macchanger -r eth0; sudo macchanger -r wlan0; sudo ifconfig eth0 up; sudo ifconfig wlan0 up

    Exit vim by pressing ESC, write wq and pressing ENTER.

  4. Make the file executable with chmod +x /etc/cron.daily/macchanger.sh

  5. Create a crontab to execute your script with crontab -e and create a new final line with: @reboot sh /etc/cron.daily/macchanger.sh

These five steps created a automatic mac changer in linux in ever system startup!

  • A sudo command run under cron will fail unless you have configured it (sudo) to be passwordless. It’s better to use sudo to put the command into root’s crontab. – Scott Jun 26 at 3:26
  • Thank you brother! – PySnowden Jun 30 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.