How To Install DHCP Server In Linux

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
whether it's an enterprise network a lab network or even a home network a dhcp server is just too darn convenient not to have it's going to hand out ip addresses automatically to computers and that's going to save you having to go around every single device manually configuring an ip address on them but how do you install and configure your own dhcp server well stick around and watch this video because that's exactly what we're going to be doing [Music] now as you can probably tell from the title the plan is to install dhcp onto a linux server specifically it's going to be ubundu now i'm not actually going to go through the whole process of installing ubuntu and configuring that uh because i've already done that in a previous video so if you want to know how to you know create a virtual machine it's running ubuntu 20.04 well i've actually got another video in which i did that for this dns server so by all means go out and have a look at that specific video to see how to actually build the virtual machine and then come back to this one where we actually start the configuration and installation of the dhcp service so we've already got this server in place it's already up and running it's got ubuntu installed it's been patched to the latest version and now it just needs the dhcp service installing and configuring but there is another couple of steps we need to factor in here because dhcp well when a computer doesn't have an ip address it's operating at layer 2. there's no way it knows you know who the dhcp server is out there so what it does it sends a broadcast out onto the network for every single computer to hear and in the hopes basically that you know someone's going to pick that up and respond but that's a layer 2 broadcast now in our case this dhcp server is going to be used for providing ip addressing for this subnet these are two completely separate layer 3 networks and they're even separated by an actual firewall so it's a case of i need to be able to get these broadcasts from this network to this server and that's where a dhcp relay agent comes into play it gets called different things depending on the vendors i know like cisco for instance if you've got like a layer 3 switch you'll configure an ip helper address because that covers more than just dhcp for instance but in our case we're running pfsense as a firewall and that has a dhcp really agent that you can configure and basically what it does it just listens on this network and if it hears you know any requests for an ip address on the network it actually picks up that broadcast request and then it forwards it over to the dhcp server as a unicast uh then the the server sent sends back a reply to the firewall and the firewall passes it over to the computer that asked for the ip address in the first place so that's one extra thing we need to do and the thing is then it's a case of because this is a firewall i also need to allow dhcp traffic through the firewall now i don't have to do it for that initial dhcp relay traffic because it's a case of it's part of the service if you will but once the computer's got an ip address it needs to talk directly to the dhcp server it's not going to just keep broadcasting all the time once it's got its ip it's going to talk to the dhcp server directly now normally the firewall wouldn't allow that traffic through it's not part of a dhcp relay service so i do have to put in a rule to allow dhcp traffic from computers on this network to that dhcp server so although the video has more to do with dhcp how to install it how to configure it i'm just tagging this on as an extra just so that you know because typically the dhcp server isn't in the same network as the uh the actual computers that you're you know providing ip addressing to so first thing we need to do is install our dhcp service well we're logged into our dhcp server so it's got linux installed and it's had the latest updates applied so the next thing is to actually install the hcp service so in this case we'll be using the isc dhcp server so sudo install asc dhcp server my password in i say yes so it's it's there's not a great deal of actual space gonna get taken up by this it's saying it's 1865 kilobytes so it's uh it's a very small service really but it's extremely useful um so now that that's you know it's actually installed thing is we've actually now got to configure it because it's installed all of the files so it's kind of like ready to go it's just the files aren't actually configured the way we want them to be because i mean i mean there's no way they know what our network's going to be like so the one thing i do like about this particular dhcp server is the default config files are full of a lot of good comments and they tend to be grayed out but you just tweak them to your own specific purposes but there is one thing i want to do first and that is i want to restrict the interface um that's could actually run on so we'll just have a look here so there's a file here which is isc dhcp server so that's the one i'm interested in so i'm just going to copy that because i want to make a backup first i mean to be honest i'm not making any changes really but it's a case of a good practice to to have so and what help sudo copy that right so we made a backup of that specific file and then what i'm going to do is edit the file so so we can make a change to it now technically it doesn't really matter because this is a like a virtual machine it's only got one interface anyway but i mean if this was like a real network a real life production network typically you'd probably have a production interface you'd have a backup interface you'd have a management interface and typically you would only want to run the dhcp in service on a specific interface usually so in this case by default it's actually running on every interface but i want to actually restrict it just you know out of good practice more than anything so i'm going to do the same for both ipv4 and ipv6 i mean to give you like a good example to say like if you've got like multiple interfaces just separate them with a space while while there's nothing you know between those parentheses it means it's going to run on every interface so i'm just going to save that actually i'll just double check that was ens192 i think that's the one i said yeah ens192 right okay so that's that done so the next thing to do is to actually configure um there's no point trying to go to the uh like the dhcp the dns rather uh i really want you ghc pin right so if we look in here and we've got a lot of files the one that we're interested in well if you're going to be running uh dhcp for version six it would be that one if you're going to be doing it for ipv4 that's the one we're interested in these are all to do with like setting up specific things for the dhcp client so that's when uh the actual computer itself has got an interface configured to use dhcp in other words it's trying to get an ip through dhcp which in this case would be completely pointless basically because this is the dhcp server anywho right what we want to do is make a copy of this file so i'll just back this up to another name just all right okay and then we'll edit that uh original file now this one i think is i think this is kind of like it's one of these things where you've got all these uh all these things comment out uh commented out and probably in production what you'd end up doing is you're then wiping a lot of this information anyway uh it's a case of like yeah it's great when you're starting it helps you understand how the service is you know configured and so on but yeah it's just it ends up being so long that you'd really want to sort of delete a lot of this um if you don't need it so like i say though the developers made life a lot easier because they've you know they've given you good examples so this is the actual config file and it's got examples in it some some parts are grayed out or commented out whereas summer like live if you will just got information that isn't correct and we need to fix that so first thing we're going to do is we're going to change the domain name to what ours is so that's going to be template.lan and we're going to change these dns servers so these ones interestingly look here the name servers are separated by a color whereas if you go back to like the the actual service uh configuration for the you know what interface running on it's separated by a space so yeah go figure anywho 172.16.17.10 right what what this is up here is basically this is the the dns suffix if you will uh this is the domain name server or what they call as the yeah they call it the domain name server or your dns server and then we've got lease times but these are these what we refer to as like global settings so these are shared settings common settings among multiple subnets that you're going to be leasing out so if we go back to our diagram typically a dhcp server it it actually supports multiple subnet source let's say for instance we were going to be setting up this dhcp server to serve both of these two subnets now globally we'll probably want all of these computers referencing this dns server so we'd set that as a like the global setting um likewise they'll probably want the same domain name suffix so we set that as a global setting but i mean i might you know set up another subnet for instance which is a bit more specific uh i might want somebody i want them to use their own you know more private dns server or something i might want to use a completely different dns suffix and that's what the the actual server gives you the option to to do because this by having these global options it saves you how to just keep typing the same stuff you know into every single subnet pool that you set up uh so you can set things up on a global setting and then you can fine-tune it for individual subnets so here what we've got is our global settings i'm not too fussed about these lease times i'm just going to leave them you know by their defaults i mean in a production environment you might want to say i want the least times um i want to be a case of you know the lease is going to expire after about nine hours for example so that way you don't run out during the uh the eight hour well a typical eight hour like window for for when people are working uh if you're in a maybe like in a cafe or something it's a case of you might want the list to be only like an hour i mean these like the way dhcp works is it it actually borrows an ip at least as an ip address for a certain amount of time but after a certain amount of time before that the computer will actually go back to dhcp and say can i extend the lease but ultimately it's going to expire anyway now in our case i'm not too fussed about that but like i said i mean you've got to set them for your environment some environments you might want them to last a long time others you might want them to expire very very quickly otherwise you'll just run out of ip addresses now this setting down here i'm not i'm not going to touch that at the moment it's it's set up so that it's not going to perform ddns and that's the default behavior now that's where the dhcp server informs the dns server so the idea is a computer goes and you know it borrows an ip address basically from the dhcp service pool but the trouble is dns doesn't know about the host name so what this does is it it allows you to set things up so that when a computer actually releases an ip address through dhcp the dhcp server then goes and informs the dns server so that way you can actually you know reference that computer through its hostname going forward and it's extremely uh useful especially if you use dns for like service for example it's a case of not dns if you're using dhcp to hand out ipad or synthetic for your service it means you just you'll always be able to keep connecting to them through like a host name as opposed to some dynamic ip address the ip address can always change but the actual host name will be kept up to date through this dhcp piece it is extremely useful uh it's not really part of this video because um this is just to set up a like a bug standard dhcp server just the bare bones really uh so it's something i'll probably look into for another video uh in any case this next setting here i'm going to uncomment that one because they're saying this is if you want to set this up as being the official dhcp server now in our case we only have one so yes it is actually the author of the dhcp server so yeah that's the reason i'm commenting it down here i don't need to make any different any changes to where you know what we're doing and where we're sending their log messages i'm just going to leave that as is and down here is where we start getting into the actual subnet pools themselves so we've got an example here which doesn't have anything in it now i'm uncommenting this because i want to actually put in a an actual range if you will that covers the computer's own local ip addressing so this would be 172.16.17 now if i don't what i find is it will complain that's if we go back to the diagram not that that's the that's the firewall go back to my diagram here this computer it's plugged into the 172 1617 network but it's it's actually handing out ip addressing to completely different subnets uh in this case it's just a one the nineteen type range but um it helps if we put that in anyway like i said like it says it helps the dhcp server don't understand the overall topology because otherwise i find it actually like it gives you like a warning it gets a bit confused like it's like i think it's probably because of i don't know i'm not on the local network what's going on here now here this is a really good example of a very basic dhc people configuration it's not really luck needs to go in here and most of the time there isn't to be honest when it comes to like just say like pcs and servers and so on so i'm just going to change this what um matches our own network so this is going to be the 172 16.19 network i just need to change that last octet over there uh for the range and i think i'm going to go from about 100 to 250 for this i'm going could set this to whatever you know you whatever range you want it to be and i do i'm also i do like this approach uh compared to some other ones that i've seen where some some computer just systems there that when like have a dhcp service what they do is they they actually ask you to define the entire range yes that's like one to 254 for example and then they ask you to exclude ip addresses where in this particular case what we're doing is we're just telling it here's the range of ip addresses that you've got to play with and you know at least these ip addresses out to the computers so it's a much simpler strategy i find and you do have to leave a you know a bit of a gap here and there because otherwise you won't have like um room for like fixed ip addresses manual ip addressing for your computers otherwise you get a clash so that's uh that needs fixing so the subnet is 172 16 19.0 and it's a slash 24 network for dhcp we're going to use a range of well basically dot 100.250 so that's that's quite a quite a large amount for this particular network and then what you've got underneath is uh when it comes to the router or the default gateway or the router however you want to refer to that as being it's 172 16 19.25 so whenever a computer comes along and asks for an ip address it's going to get these global settings up here so you know your domain name dns server least times and this is going to be its default gateway and then this is this is basically more for the dhcp server itself to understand now there are other options that you've got if we go further down so we've got them down here we've got a much more detailed example i mean this one here they're saying to actually ignore because this is for the predecessor the dhcp which is boot p but this is a more specific subnet where they've got a lot of information in there so these sort of settings like you know the option for the routers routers default gateway whatever you want to call it this overrides the global setting uh same goes for the leasing times the domain name and so on the this all override so you can do that where you can have a as i've said earlier you can have a sort of global settings and then you can be more specific with other uh subnet pools later down the line it just saves you having to keep typing all of this information out for every single subnet pull the config file i'll start getting bigger and bigger and bigger and it's it's just a hassle every time you need to add a new pool or something or if you need to make a change i mean if i need to change like the dns server for example i've just got to change it at that top in the global setting it's a one-off change i don't have to go through every single pool so if we come a bit further down i'll ignore that particular option about um you know reserving ip addresses because i want to use this specific example here now dhcp is as it says it's a dynamic protocol basically the idea is the computer goes and asks for an ip address and it actually gets a pretty much a random one and from the pool and it's a case of after a while that ipaddress will change to something different but what you can do is you can actually reserve ip addresses for for certain computers and it uses the mac address to to work out you know you know and identify you know individual computers so what i'm just going to do is i'm just going to paste this in just to make my life easier rather than typing this all out now that needs to be pc2 as well so what this is for is that when when this specific computer comes along and asks for an ip address it's actually going to get this fixed ip address and it's going to get that ip address all the time so i've got a pc or a computer called pc it's going to get a an ip address through the pool and that could change over time whereas pc2 here which has that specific mac address on its network card it's always going to get this ip address so this is this is more relevant when you've got like a firewall for example with rules and you want to make maybe elevated privileges or something maybe there's a server out there you only want certain computers getting access to for example in which case you need to have a fixed ip address so you can either go around these computers and manually configure the ip or you can do this which is to reserve an ip and you reference them based on whatever the mac address of the network card is because that's what happens within within dhcp the computer goes and talks to the dhcp server and it actually provides its mac address uh then the dhcp server it keeps a database of all the ip addresses that it's leased out and it's using the mac address to reference who got that ip address for example and i want that as just as a an example of like the options here i'm not too fussed about this this version of configuring everything it's really just a case if i want a pool setting up up there and then i want a fixed ip as opposed to a dynamic ip for another computer i mean incidentally the one of the reasons you do something like that if i go back to my diagram here i mean there are companies i've dealt with in the past where what they do is they actually have all of their computers have an actual uh an ip address allocated to them through dhcp they don't go around every single computer and manually configure the ips instead what happens is those servers will then update dns while rather the dhcp server tells dns you know what ip address belongs the host name so it doesn't matter where that computer appears on the network you can always reference it by its horse name because dns is always getting updated but a really cool thing about it is that uh say for instance we need to renumber this entire network if i've got i don't know 50 or 100 computers in here i mean if they've all got like a manual ip address i'm going to go through every single one of them and change the the ip address on those computers whereas by doing it through dhcp all i've got to do is update dhcp and then i've got to update the firewall because obviously the ip address and the firewall will change uh source network you know in here it's going to change and in the case of pf sense that doesn't really matter because it just it references back uh to its own interface it understands you know what network it belongs to so you don't actually reference the ip address itself directly it's got a much clever way of dealing with that but it means you could literally renumber an entire subnet effectively just by changing your dhcp server and um guy peterson on a firewall it makes life a breeze uh fortunately you don't have to do it that often though but anyway we've now got a dhcp configured so the next thing is to actually start the dhcp server running so it will be system cdl so pseudo system ctl and it is uh ics i think it was i see it's ifc that's it let's see uh dhcp server would help me told it to actually start first there's a computer i mean basically what's happened is dhcp has been installed and it's got the config file this is just not running yet so it helps if we actually tell it to start now so then go back and now we'll just double check if it's actually working without yeah that's working so it seems to be okay but now we've actually got to test it so what i've got is i've got a couple of pcs i've got one called pc and i've got one called pc2 so we're going to log into this one here if i put the password in first right okay so i'll bring the interface up on that one so that one is i think it's i'm sure it was in it's 192 or something oh config what's a config okay and then let's get what it's like p addresses [Applause] so that's kind of like p address of 172 16 19.201 so it's at least the ip address so that's quite quite quite easy to do if going to into here because i mean out of the box these are all set up for dhcp anyway so if we just have a bit of a look on this you can see that's all you know there's your right there's your dns server there's your uh your default gateway that's okay i'll just leave that don't need that close that down so if i bring up a web browser i should be able to get out to the internet for example because i've got a i've got an ip address i know who the uh the actual dns server is so can i actually look at oh yeah i can actually look at my videos is that what that's what we've been up to so far right so we know that that's got an ip address and that's working fine so the next thing is what about dhc what about pc number two this one should have an actual a fixed ip address so we'll log into this one now interesting enough that previous pc was running uh published so that's a version of linux based on debian now this one is running fedora so that's based on red hat but what i've found which is interesting is using similar uh similar desktop because it to me look the same but anyway i'll just turn on its network card there uh just close that and see what state this one's in so this one yeah it's still it's still getting 172 16 19.10 um so that seems fine so if we ask this one we'll try and firefox on that one i shouldn't make a hit with a difference to be honest so try youtube yeah i think give out to youtube on this one as well so that's that's the only difference between these is that one's getting a dynamic ip address and one's getting a fixed ip address so it's a case of i suppose it depends on how you want to configure it i mean you've got that you've got that flexibility to go with a dynamic ip addressing everything or you know mine with manual ip addressing or you can do it like a combination of reservations for example so it's uh very very flexible and it's pretty easy enough to set up but i did have to make some slight changes and that's to get like the dhcp really agent working but one thing actually god i need to cover is we come back to this computer if you have a look at dhcp uh it's called dhcp lease i'm trying to know what command is there's a there's a command i need to run the lease list that's it there is one slight catch here we're only being told about one computer having a leased ip address and that's because the one that's running fedora has a reserved ip address whereas this one is pubos it's got a dynamic ip address so when we run that command uh the computer's keeping a database of all the ip addresses that it's leasing out and one thing that's not in there is actually these reserved ips so if you do reserve ips you're going to have to go back to the config file to check those versus running something like this dhcp lease list uh to get the dynamic leasing so this one says it's well this particular case it's that it's valid for let's try to see what time is uh yeah it's not it's not that too long but it's um yeah it's the only way to find out basic i mean you can go and look at the individual file itself if you want but the only way to find out about the actual fixed or reserved ones is to actually go back to the actual config file there you are technically it's not part of like a dhcp build as such but one thing i do need to cover is how to set up a dhcp really agent uh so if go back to our diagram we've got a firewall here this could be anything it might be a layer 3 switch for example um and it's a case of we've got to be able to get layer 2 broadcasts out of this network here across to that dhcp server because otherwise it's never going to heal them and computers on this network would never get an ip address so in this case i've actually configured a dhcp relay agent on the firewall it actually comes built in it's just not enabled by default so just minimize the terminal there if we go across to the firewall for this particular lab if we go to services and dhcp relay that's what it looks like by default so it's not it's not automatically enabled so i think the way though that they set this sort of thing up is the expectation is i mean it's got its own capabilities of running dhcp if you want you can you can run this as a dhcp server but i'm just running it primarily as a firewall so this is by default turned off but we need to turn it on then what you need to do is pick the interfaces that you're going to be listening on now in our case i only need to be listening on this one interface but if for instance i wanted to do you know allow dhcp on the management interface like i've done there i would highlight both the management and the lab one in the basis but as i said i only need running on the one and then you've got to give the actual firewall in this case a list of ip addresses for your dhcp servers now in my case i've only got one but basically what the firewall is now doing is as i explained before i think it's a case of a broadcast you get a layer 2 broadcast gets sent out on this network and the firewall is now just listening on this interface and what it will do is it'll actually unicast that over to this server and the server then send it back now the way that the dhcp server knows what ip address ranges it can hand out is because the firewall is actually including its own ip address in that specific pool so it's telling the dhcp server about this 172 1619 network so that way this dhcp server knows it's got to go to its you know dhcp pool for 172 1619 pull out an ip address from that it'll send that back to the firewall and the firewall it'll send it back into the network now there is one other thing you do need to do because by enabling that dhcp really that's it there's nothing else as far as dhcp really is concerned you don't have to set up any firewall rules for that because the firewall itself is listening so it expects to be able to let that sort of traffic in any way well it doesn't actually let it through as such it's just sitting listening but once an actual computer's got an ip address what we do have to do is we have to set up a rule for dhcp otherwise once the computer's got an ip address it's going to want to talk to the dhcp server to be able to renew that ip for example so up here i've configured a rule right at the top it's right over the top of the list because i've got a list down here to block access to all other private networks for example i've got one that allows computers to talk to the dns server and this one's too allowed to talk to dhcp servers so we're allowing udp traffic from that specific network if you will that's sourced from port 68 and going to these specific servers now in this case there's only one server anyway but i like to sell these aliases because it means i can change the alias i can change the ip rest of the dhcp server i can add more and i don't have to touch the rule itself uh it's less less likely for things to go wrong if i do it that way and it's much much more flexible i find but anyway we're allowing udp access from port 68 up to at this moment 172 16 17.12 and to port 67 because that's how dhcp works the sender you the sender is sending traffic from port 68 and it's sending it to port 67. so that rules just sitting there right at the top to deal with when the dhcp you know leasing needs to be renegotiated effectively but it means that i've got a now got a dhcp server in this network it's all set up to hand out these ip addresses and we've tested it it's working all tickety-boo i mean there are other things you can put into dhcp servers i mean go back to um that config well go back to this one here this is this is this is basically just like a bare bones config that i've copied and stored because i'll say that for notes i'll put this all into the description whatever uh so you'll know what uh what sort of things to put in there but you can add all sorts of options in here i mean this like i paid telephones for example they'll want to know what computer do i register with um or rather pbx i should say they want to know what to register with so they can get their config file so they can get their uh information like the tftp server for instance to pull their firmware images down and so on because you don't want to go around every single telephone manually configuring that sort of stuff it's all done through dhcp it makes the whole thing dynamic so there's lots of other options you can put in there's a lot of reserved numbers in there this one's just referencing this you know option routers or routers if you prefer to mean the default gateway but there's there's tons of options out there that you can add into dhcp but hcp server doesn't care it's it ultimately depends on the end point you know it knows it's looking for a certain option number and when it sees it it uses that but overall i must admit it's a it's a pretty easy d you know server to configure every time you want to add a new pool you just basically you know create a few more lines in it every time you make a change you have to reboot this and get uh well not the computer you have to restart the service to get that change to take effect but it's uh yeah very easy service to set up and extremely extremely handy well thanks for making it to the end of this video i really do hope you found it useful if so then do click the like button and share because that encourages youtube's algorithm to suggest it to other people who might find it useful as well if you're new to the channel and you'd like to see more content like this then yeah do subscribe just remember to click the little bell icon though that way you'll get notifications when i send new content out if you've got any comments any suggestions if you want to leave any feedback at all please post that in the comments section below and if you'd like to support the channel i've left links to both patreon and paypal in the description below but above all thanks very much for watching i'll see you in the next video you
Info
Channel: Tech Tutorials - David McKone
Views: 3,380
Rating: undefined out of 5
Keywords: How To Install DHCP Server In Linux, install dhcp server ubuntu 20.04, install ubuntu dhcp server, how to install dhcp in linux, linux dhcp, linux dhcp server, linux dhcp server configuration, linux dhcp server ubuntu, linux dhcp settings, ubuntu dhcp, ubuntu dhcp service, ubuntu dhcp dns server, ubuntu dhcp server 20.04, isc dhcp server, isc dhcp server configuration, isc dhcp show leases, pfsense dhcp relay firewall rules
Id: ZlLMhcT4EgM
Channel Id: undefined
Length: 34min 38sec (2078 seconds)
Published: Sun Apr 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.