Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an Ubuntu machine on which I have created four VLANs, namely eth0.100 ,eth0.200 , eth0.300 and eth0.400. I want to dynamically obtain the IP addresses using the DHCP server. It should provide an IP from different range of IP addresses, i.e.

for VLAN interface eth0.100,--> 192.168.0.20 - 192.168.0.40
for VLAN interface eth0.200 --> 192.168.0.50 - 192.168.0.70
for eth0.300 and eth0.400   --> likewise

How can I implement this? How will I read the VLAN ID of the interface which is requesting the IP address? How will I convey the information about the VLANs running on the client to the DHCP server?

I think I should create VLAN interfaces on the DHCP server also. If I do, how will I let the DHCP server know the presence of VLANs?

I am stuck in this. How should I proceed?

share|improve this question

2 Answers 2

VLAN's are a layer 2 feature, while IP/DHCP is a layer 3 one, I just wanted to make that clear but they have a lot to do with each other in this scenario.

Basically all you really need to do is ensure that your L2/3 switch/router is configured to allow your DHCP server to not only route to/from all VLANs but provide a 'DHCP Helper' service so that all clients in all VLANs refer to it when they make a DHCP request. On Cisco L2/3 devices the 'dhcp helper' command configures this.

Once this is in place any machine on any of the VLANs can then request an address via DHCP and the request will be correctly routed to the DHCP server which, if correctly configured, will return an appropriate address.

The way it does it is this (this is more for future reference for others to be honest);

  1. The client sends out a DHCP broadcast from itself as 0.0.0.0 to 255.255.255.255 (or whatever given the NM) containing its MAC address asking for an IP.
  2. Your L2/3 switch/router, if configured to act as a DHCP Helper, then looks at what interface the broadcast came in on, checks its DHCP helper list to find out where to send the request and then sends it to that DHCP server but this time as a unicast message containing its own per-segment/VLAN gateway IP address (i.e. the likely DG the client will route through) but retaining the client machine's MAC so that client-specific settings such as reservations etc. can be applied by the DHCP server. It does this so that the DHCP server knows which network to issue an address for and also how to get it back to the L2/3 switch/router.
  3. The DHCP server gets this unicast request from the L2/3 switch/router, sees that it comes from a certain network, if it has a scope defined for that and there's a free or reserved (because it knows the client's MAC) address it then send back an issued IP to the L2/3 switch/router via unicast (it knows its IP remember) - along with any client-specific settings.
  4. The L2/3 switch/router receives the response from the DHCP server and simply passes it onto the client by changing the IP address to that of the client - this will include any client-specific settings.

Is that clear?

The main point of this is that the DHCP server doesn't need to know anything about the L2 network/VLANs at all - just the L3 network and matching scopes.

share|improve this answer
    
Thank you for the answer. In vendor-agnostic terms the feature of the switch that you refer to is called DHCP Relay (RFC 3046). E.g. on a ProCurve 3400 the commands are dhcp-relay to swtich on and vlan 100 ip helper-address xx.xx.xx.xx. The switch should have an IP address configured on each vlan. –  Dmitri Chubarov Sep 20 '12 at 15:29

Your networks seem to be a bit non-cidr in nature. Which will make routing difficult to deal with. If you want to use one /24 for your entire network and split it up into 4 vlan networks then each one should be a /26.

This would mean your networks would look like this.

  • vlan 100 192.168.0.0/26
  • vlan 200 192.168.0.64/26
  • vlan 300 192.168.0.128/26
  • vlan 400 192.168.0.192/26

For the DHCP server you'll need to have interfaces on each vlan for it as well. And the ports on the switch that connect to both of these servers will have to be trunk ports. As for setting up the DHCP server to work with the different interface we'll need to know what OS and DHCP server you're planning on using to help you out with any specifics there. But in general if each interface that DHCPD is listening on has an ip address in a given network it will return an ip address from the pool associated with that network.

share|improve this answer
    
Thanks for the quick reply.But sorry,i did not understand why do i need to create VLANs on the dhcpserver as well.And if a dhcp request comes from eth0.100, how the server will come to know the interface and provide the IP accordingly from that particular range.Can you please explain me this? –  user1186683 Jul 30 '12 at 12:03
    
Alternatively, you could simply use a helper address in the router to forward DHCP broadcasts to the server instead of actually placing it in each subnet. –  Paul Ackerman Jul 30 '12 at 12:11
    
I believe the /26 implies definitions of distinct networks. So, if a request comes from a client in the 0.0/26 range, the dhcp server listening on that SUBnetwork can only hand out an IP within that network. –  JoshP Jul 30 '12 at 12:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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