You are not logged in.
Hey there fellow Archers,
I know this probably doesn't belong in the Newbie Corner, but I'm not 100% sure where to put it. I want to dynamically generate a new hostname (and possibly a new MAC address) every time I boot. This is for a virtual machine that will be used to test security on a local network. Is there a simple way to make this happen? I've been out of the Arch loop for a while and preliminary research shows nothing on the subject, so any help is appreciated.
Mitch
Offline
I would assume you could simply write a script that changes /etc/hostname on every reboot. The mac address is a different matter. How are you virtualizing? Is this just a virtualbox VM you're using?
Offline
I would assume you could simply write a script that changes /etc/hostname on every reboot.
You may be able to do this with a custom latehook in the initramfs.
https://wiki.archlinux.org/index.php/Mk … time_hooks
Last edited by WorMzy (2013-10-03 21:13:16)
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Is it really that simple? If so, I can have this whole project knocked out in no time. If that is the case, I can then solve the MAC address portion without much issue. In the same script that sets the hostname I can do a
ip link set eth0 address 02:01:02:03:04:08
where the MAC is selected from a list of properly formatted options each time.
Thanks!
Edit: run_latehook is exactly what I'm looking for. Booyah.
Last edited by minasmorath (2013-10-03 21:19:29)
Offline
If you are using kvm, then virt-clone (i think) does exactly what you are asking
take a look here: http://linux.die.net/man/1/virt-clone & here http://linux.die.net/man/1/virt-sysprep
https://balaskas.gr
Linux System Engineer - Registered Linux User #420129
Offline
It should be a piece of cake to randomize MAC address with a script if you're comfortable with your hypervisor's command line tools.
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline
I used to do this on my laptop in ubuntu, here are some snippets of code I used which you might find useful...
Be sure to install the "words" package for the dictionary...
You should be able to randomize the mac address easily. There are tools that'll do it for you.
#!/bin/bash
HOST=`perl -e 'open IN, "</usr/share/dict/words";rand($.) < 1 && ($n=$_) while <IN>;$n=~s/'\''//g;print lc($n)'`
DOMAIN=`perl -e 'open IN, "</usr/share/dict/words";rand($.) < 1 && ($n=$_) while <IN>;$n=~s/'\''//g;print lc($n)'`
echo "New selected hostname is $HOST.$DOMAIN.com..."
# Search/Repace hosts temp construct (template simply has strings HOST and DOMAIN in appropriate spots)
cp /etc/hosts.template /etc/hosts
sed -i 's/HOST/'$HOST'/g' /etc/hosts
sed -i 's/DOMAIN/'$DOMAIN'/g' /etc/hosts
# Create a new hostname file
echo "$HOST.$DOMAIN.com" > /etc/hostname
# Clean up old hostname stuff, doesn't break anything but probably inefficient
rm -rf /home/username/.kde/tmp*
rm -rf /home/username/.kde/socket*
rm -rf /home/username/.kde/cache*
Sometimes you really get some hilarious host/domain name combinations... (some sample output)
Setting peculiarity.vices.com to new hostname...
Setting luxury.typified.com to new hostname...
Setting tonga.algols.com to new hostname...
Setting stank.gulling.com to new hostname...
Setting memorializes.smileys.com to new hostname...
Setting mollycoddles.recliners.com to new hostname...
Setting bulldozing.tamils.com to new hostname...
Setting indefinitely.mortician.com to new hostname...
Setting leopard.elaborate.com to new hostname...
Setting engravings.tuns.com to new hostname...
Setting mart.diamante.com to new hostname...
Offline
macchanger application can generate random mac adresses too. No ideia if it is useful for you.
Offline