Difference between revisions of "DHCP static IP assignation"

(Created page with "Category:Linux =Access configuration file= The main configuration file is '''/etc/dhcp/dhcpd.conf''' <syntaxhighlight lang="bash"> vim /etc/dhcp/dhcpd.conf </syntaxhig...")
 
(Static IP @)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Linux]]
 
[[Category:Linux]]
  
 +
=Global configuration=
  
=Access configuration file=
+
 
 +
==Access configuration file==
  
 
The main configuration file is '''/etc/dhcp/dhcpd.conf'''
 
The main configuration file is '''/etc/dhcp/dhcpd.conf'''
Line 12: Line 14:
  
  
 
+
==Static IP @==
=Static IP @=
 
  
 
This new configuration will ONLY accept known clients and give them a static IP @.
 
This new configuration will ONLY accept known clients and give them a static IP @.
Line 25: Line 26:
 
option broadcast-address 172.16.50.255;
 
option broadcast-address 172.16.50.255;
 
option routers 172.16.50.254;
 
option routers 172.16.50.254;
option domain-name-servers 172.16.50.2, 8.8.8.8;
+
# Google 8.8.8.8 8.8.4.4
 +
# OpenDNS 208.67.222.222 208.67.220.220 (https://www.opendns.com/home-internet-security/opendns-ip-addresses/)
 +
option domain-name-servers 172.16.50.2, 208.67.222.222, 8.8.8.8;
 
option domain-name "mydomain.lan";
 
option domain-name "mydomain.lan";
 
option ntp-servers 172.16.50.254;
 
option ntp-servers 172.16.50.254;
Line 33: Line 36:
 
subnet 172.16.50.0 netmask 255.255.255.0 {
 
subnet 172.16.50.0 netmask 255.255.255.0 {
 
     host client1 {
 
     host client1 {
         hardware ethernet DD:GH:DF:E5:F7:D7;
+
         hardware ethernet AA:00:DF:E5:F7:D7;
 
         fixed-address 172.16.50.20;
 
         fixed-address 172.16.50.20;
 
     }
 
     }
 
     host client2 {
 
     host client2 {
         hardware ethernet 00:JJ:YU:38:AC:45;
+
         hardware ethernet 00:CD:BC:38:AC:45;
 
         fixed-address 172.16.50.21;
 
         fixed-address 172.16.50.21;
 
     }
 
     }
Line 52: Line 55:
 
* MAC @
 
* MAC @
 
* Set a specific static IP @
 
* Set a specific static IP @
 
 
 
 
  
 
=Add new host=
 
=Add new host=
  
 
+
==Configuration file==
Every time you need to install you host you have to:
 
  
 
Edit the configuration file:
 
Edit the configuration file:
Line 68: Line 66:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
 +
 +
==Declare new host==
  
 
Add new host at the end of the file :
 
Add new host at the end of the file :
Line 83: Line 84:
  
  
 +
==Take on changes==
  
 
Restart the DHCP server :
 
Restart the DHCP server :

Latest revision as of 15:42, 2 August 2015


Global configuration

Access configuration file

The main configuration file is /etc/dhcp/dhcpd.conf

vim /etc/dhcp/dhcpd.conf


Static IP @

This new configuration will ONLY accept known clients and give them a static IP @.

# Sample /etc/dhcpd.conf
# (add your comments here) 
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 172.16.50.255;
option routers 172.16.50.254;
# Google 8.8.8.8 8.8.4.4
# OpenDNS 208.67.222.222 208.67.220.220 (https://www.opendns.com/home-internet-security/opendns-ip-addresses/)
option domain-name-servers 172.16.50.2, 208.67.222.222, 8.8.8.8;
option domain-name "mydomain.lan";
option ntp-servers 172.16.50.254;

deny unknown-clients;

subnet 172.16.50.0 netmask 255.255.255.0 {
    host client1 {
        hardware ethernet AA:00:DF:E5:F7:D7;
        fixed-address 172.16.50.20;
    }
    host client2 {
        hardware ethernet 00:CD:BC:38:AC:45;
        fixed-address 172.16.50.21;
    }
}

Note:

The deny unknown-clients; command is why only known clients are accepted.


For each client you have to adjust:

  • MAC @
  • Set a specific static IP @

Add new host

Configuration file

Edit the configuration file:

vim /etc/dhcp/dhcpd.conf


Declare new host

Add new host at the end of the file :

host myNewHost {
  hardware ethernet 00:0e:af:31:d1:cc;
  fixed-address 172.16.50.60;
  option host-name "myNewHost";
}

==> Don't forget to the given IP @ must match the DNS server declaration !


Take on changes

Restart the DHCP server :

/etc/init.d/isc-dhcp-server restart