FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 10-03-2011, 07:43 AM
Scott Ferguson
 
Default IP address depending on the MAC

On 03/10/11 03:31, Ireneusz Szcześniak wrote:
> Hi,
>
> I'm planning to install an image of Debian to a number of computers.
> Each of these computers will have the same configuration except the
> hostname and the IP address. The IP configuration has to be static.
> I can't use a DHCP server.
>
> QUESTION; Is there a way to assign a hostname and a static IP address
> at boot time depending on the MAC address of the computer's network
> interface card?

I note that someone has already given you a scripting solution.

>
>
> Thanks, Irek
>

If you have a large number of identical hardware machines to image - a
multicast solution that allows defining build rules (ie static network
addresses, hostname, /etc/host, passwords, usernames, network shares and
logons etc)
might save time and make management easier. eg. FAI (most excellent)
Clonezilla SE (excellent), systemimager (I haven't used), and others.

For identical software and different hardware using a package list (dpkg
--get-selections > package.list) can be used.

For large deployments consider Puppet (very good, especially in mixed
environments).

Cheers


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 4E8967A4.3010406@gmail.com">http://lists.debian.org/4E8967A4.3010406@gmail.com
 
Old 10-03-2011, 10:38 AM
Darac Marjal
 
Default IP address depending on the MAC

On Sun, Oct 02, 2011 at 06:31:59PM +0200, Ireneusz Szcześniak wrote:
> Hi,
>
> I'm planning to install an image of Debian to a number of computers.
> Each of these computers will have the same configuration except the
> hostname and the IP address. The IP configuration has to be static.
> I can't use a DHCP server.
>
> QUESTION; Is there a way to assign a hostname and a static IP
> address at boot time depending on the MAC address of the computer's
> network interface card?

I'm not sure about hostname but there IS a way to assign a static IP
address to an interface based on it's MAC address. It's called StateLess
Address Autoconfiguration (SLAAC). Basically, you take the 48-bit mac
address, modify it a little (mainly adding FF:FE in the middle) and you
now have a 64-bit interface identifier. This becomes the second half of
your IP address.

For the first half of the address, you will either use the standard
link-local prefix, or if you can use a route-advertising daemon
(package: radvd), you can advertise a site-wide prefix to allow the
machines to be addressed from anywhere. I suspect, though, that the
link-local prefix should be fine for your purposes, though.


--
Darac Marjal
 
Old 10-03-2011, 04:52 PM
Chris Davies
 
Default IP address depending on the MAC

Javier Barroso <javibarroso@gmail.com> wrote:
> If you know which macs you will have, you can make an init script
> which generate /etc/network/interface and /etc/hostname and /etc/hosts
> the first boot and then remove itself.

You don't even need to know in advance the MACs as long as enough of
the address is unique.

> $ cat /etc/init.d/10setnetworkonlyfirstboot
> #!/bin/bash
# > mymac=$(ip add show dev eth0 | awk '/ether/ {print $2}')
# > myhost=$(awk "/$mymac/ {print $3}")
# > myip=$(awk "/$mymac/ {print $2}")

myhex=$(
ip add show dev eth0 | # Get the interface detail
awk '/ether/ {print toupper($2)}' | # Extract MAC
cut -d: -f6 # Get last octet (as hex)
)
mydec=$( echo "16 i $myhex p" | dc ) # Convert hex to dec
myip="192.168.1.$mydec" # Must guarantee not 0 or 255


> sed -i "s/IP/$myip" /etc/network/interfaces # and probably some
> changes in /etc/hosts
> sed -i "s/HOSTNAME/$myhost" /etc/hostname # and probably some changes
> in /etc/hosts
> rm -f /etc/init.d/10setnetworkonlyfirstboot

Rather than removing the configuration file, you could add, say,
"# Configured eth0" to /etc/network/interfaces during setup. Next time
just exit if that line exists in the file.

Chris


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 8s5pl8xttd.ln2@news.roaima.co.uk">http://lists.debian.org/8s5pl8xttd.ln2@news.roaima.co.uk
 
Old 10-05-2011, 09:15 PM
Raf Czlonka
 
Default IP address depending on the MAC

On Wed, Oct 05, 2011 at 08:59:08PM BST, Ireneusz Szcześniak wrote:
> The computers are in a university laboratory, where students often
> unplug the lan cable. Then they plug the cable again after some
> time, and unplug again.
>
> The problem with this plugging and unplugging is that when the
> dhclient doesn't receive a lease in time, it randomly picks an
> address and stays with it even then the cable is plugged later.
> With this random address I can't connect to the computer remotely.
> And so the idea of a static address came to my mind. But now I
> think I should look into the configuration of dhclient to resolve
> the problem.

You can resolve this issue by setting up a long lease time and set up
static leases only - it's trivial.

Regards,
--
Raf


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 20111005211558.GA14182@linuxstuff.pl">http://lists.debian.org/20111005211558.GA14182@linuxstuff.pl
 
Old 10-05-2011, 10:08 PM
Liam O'Toole
 
Default IP address depending on the MAC

On 2011-10-05, Raf Czlonka <rjc@linuxstuff.pl> wrote:
> On Wed, Oct 05, 2011 at 08:59:08PM BST, Ireneusz Szcześniak wrote:
>> The computers are in a university laboratory, where students often
>> unplug the lan cable. Then they plug the cable again after some
>> time, and unplug again.
>>
>> The problem with this plugging and unplugging is that when the
>> dhclient doesn't receive a lease in time, it randomly picks an
>> address and stays with it even then the cable is plugged later.
>> With this random address I can't connect to the computer remotely.
>> And so the idea of a static address came to my mind. But now I
>> think I should look into the configuration of dhclient to resolve
>> the problem.
>
> You can resolve this issue by setting up a long lease time and set up
> static leases only - it's trivial.
>
> Regards,
> --
> Raf

Yet another option is to configure clients to send their hostname in the
DHCP request. The hostnames will register with dnsmasq's DNS resolver,
so you can connect to the clients by hostname rather than IP address.
That is my preferred configuration.

--
Liam O'Toole
Cork, Ireland


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: slrnj8plao.2d1.liam.p.otoole@dipsy.tubbynet">http://lists.debian.org/slrnj8plao.2d1.liam.p.otoole@dipsy.tubbynet
 
Old 10-06-2011, 05:13 AM
Ireneusz Szcześniak
 
Default IP address depending on the MAC

On 05.10.2011 23:15, Raf Czlonka wrote:

On Wed, Oct 05, 2011 at 08:59:08PM BST, Ireneusz Szcześniak wrote:

The computers are in a university laboratory, where students often
unplug the lan cable. Then they plug the cable again after some
time, and unplug again.

The problem with this plugging and unplugging is that when the
dhclient doesn't receive a lease in time, it randomly picks an
address and stays with it even then the cable is plugged later.
With this random address I can't connect to the computer remotely.
And so the idea of a static address came to my mind. But now I
think I should look into the configuration of dhclient to resolve
the problem.


You can resolve this issue by setting up a long lease time and set up
static leases only - it's trivial.


This is what I have already done, but the static lease doesn't protect
me from the "unplugging problem" and the behaviour of dhclient. I
haven't looked into the config of dhclient yet, but reconfiguring it
so that it keeps trying to get a configuration and doesn't fall back
to a random IP address seems a good thing to try.


--
Ireneusz (Irek) Szczesniak
http://www.irkos.org


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Archive: 4E8D38E0.8030601@gmail.com">http://lists.debian.org/4E8D38E0.8030601@gmail.com
 
Old 10-06-2011, 06:56 AM
Raf Czlonka
 
Default IP address depending on the MAC

On Thu, Oct 06, 2011 at 06:13:04AM BST, Ireneusz Szcześniak wrote:
> This is what I have already done, but the static lease doesn't
> protect me from the "unplugging problem" and the behaviour of
> dhclient. I haven't looked into the config of dhclient yet, but
> reconfiguring it so that it keeps trying to get a configuration and
> doesn't fall back to a random IP address seems a good thing to try.

You only need the IP address when the PC is plugged into the net, right?
In that case setting a static lease will solve your problem, simply make
sure to install a bit of software that detects the cable being plugged
in, e.g. AFAICR the aforementioned packages should have that capability
or simply use ifplugd or similar.
What do you mean by "falls back to a random IP address"?
What purpose unplugging the PC from the network has? Is it part of the lab?

Regards,
--
Raf


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 20111006065617.GA3583@linuxstuff.pl">http://lists.debian.org/20111006065617.GA3583@linuxstuff.pl
 

Thread Tools




All times are GMT. The time now is 06:56 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org