You are not logged in.

#1 2013-10-03 20:19:03

minasmorath
Member
From: USA
Registered: 2009-11-24
Posts: 52
Website

Can I dynamically generate a new hostname each time I boot?

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

#2 2013-10-03 21:06:25

Durden
Member
Registered: 2011-06-19
Posts: 261

Re: Can I dynamically generate a new hostname each time I boot?

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

#3 2013-10-03 21:12:36

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,412
Website

Re: Can I dynamically generate a new hostname each time I boot?

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

#4 2013-10-03 21:17:11

minasmorath
Member
From: USA
Registered: 2009-11-24
Posts: 52
Website

Re: Can I dynamically generate a new hostname each time I boot?

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

#5 2013-10-03 21:19:38

ebal
Member
From: Athens, Greece
Registered: 2009-05-26
Posts: 224
Website

Re: Can I dynamically generate a new hostname each time I boot?

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

#6 2013-10-03 21:26:52

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Can I dynamically generate a new hostname each time I boot?

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

#7 2013-10-03 22:45:17

xterminus
Member
From: Tacoma, WA, USA, Earth, Sol, M
Registered: 2005-10-30
Posts: 93

Re: Can I dynamically generate a new hostname each time I boot?

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

#8 2013-10-04 00:39:41

Diaz
Member
From: Portugal
Registered: 2008-04-16
Posts: 366

Re: Can I dynamically generate a new hostname each time I boot?

macchanger application can generate random mac adresses too. No ideia if it is useful for you.

Offline

Board footer

Powered by FluxBB