# FreeBSD Assign IP from Mysql



## hac3ru (Mar 21, 2012)

Can anyone tell me how to do this?

I`m a newbie in FreeBSD and *I* have to admin a network here. I did a script that will write the MACs into a mysql DB but *I* don't know how to use that DB in order to assign IPs. I`ll have two columns: MAC and IP. I want the server to give each MAC from the table the corresponding IP address.

Thanks in advance.


----------



## SirDice (Mar 22, 2012)

MySQL is not the most obvious choice for this. You should set up a DHCP server.

net/isc-dhcp42-server


----------



## Abriel (Mar 22, 2012)

You can check http://hg.rez-gif.supelec.fr/dhcpd-mysql/


----------



## hac3ru (Mar 22, 2012)

My bad...

I already have a DHCP server but at the moment, *I* log onto the server and change the MACs manually... I want this to be done automatically, MACs being taken from a MySQL db. Is it possible?


----------



## Beeblebrox (Mar 22, 2012)

@Abriel Although I have no need for it at the moment, a very interesting concept.


----------



## SirDice (Mar 22, 2012)

hac3ru said:
			
		

> I already have a DHCP server but at the moment, *I* log onto the server and change the MACs manually. I want this to be done automatically, MACs being taken from a MySQL db. Is it possible?


For starters, why on earth are you locking MACs and IPs? Let DHCP do the job it's supposed to do.

As for servers, they shouldn't use DHCP at all, they should have static IP addresses. 

But if you're hellbent on making your life more complex than it should be then I guess you could write a simple perl script to get the data from MySQL and create the lease file that's needed for DHCP.


----------



## hac3ru (Mar 22, 2012)

*I* took this server as it is and _I_ want to make the process easier for the user. There's a network where campus network with lots of rooms and lots of IPs.  Each floor has something like xxx.xxx.1 (floor).xxx so you have some control over who has what IP.

Anyways. I`ll try using perl and see what`s happening


----------



## SirDice (Mar 22, 2012)

hac3ru said:
			
		

> Each floor has something like xxx.xxx.1(floor).xxx so you have some control over who has what IP...


Stick each floor in its own VLAN and use a DHCP relay. Each machine will then get an IP address from a specific range. All neatly compartmentalized.


----------



## throAU (Mar 23, 2012)

hac3ru said:
			
		

> *I* took this server as it is and _I_ want to make the process easier for the user. There's a network where campus network with lots of rooms and lots of IPs.  Each floor has something like xxx.xxx.1 (floor).xxx so you have some control over who has what IP.
> 
> Anyways. I`ll try using perl and see what`s happening



Why are you wanting to do this?  IPs are not worth keeping track of for end user machines, this is what DNS is for.

Get used to dealing with DNS, because with the coming of ipv6, you sure as hell aren't going to be remembering subnet/IP information to figure out where a particular machine is.

How is this going to be easier for the user than just using DHCP?


----------



## hac3ru (Mar 23, 2012)

Well, those are the rules for now. As *I* said, *I* took over the network in this state and *I*`m not allowed to alter it at the moment. Still, if *I* do this it`s not an alteration


----------



## SirDice (Mar 23, 2012)

Talk to your boss, tell him the network is a mess. Hire a proper network engineer to redesign the whole lot.


----------

