Is there a command to insert a mac address into a subnet in dhcpd.conf file?
I am looking for a command that allows me to insert an host inside the dhcpd.conf file
without manualy touching that file.
I am using: CentOS release 5.3.
The file looks like this:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
host client1 {
hardware ethernet 00:04:0d:0c:0f:0a;
}
host client2 {
hardware ethernet a0:be:cd:ea:1d:14;
}
###Block I wanto to insert
host client_i_want_to_insert {
hardware ethernet e3:ee:ed:ea:1d:e4;
}
###########
}}
dhcp isc-dhcpd
add a comment |
I am looking for a command that allows me to insert an host inside the dhcpd.conf file
without manualy touching that file.
I am using: CentOS release 5.3.
The file looks like this:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
host client1 {
hardware ethernet 00:04:0d:0c:0f:0a;
}
host client2 {
hardware ethernet a0:be:cd:ea:1d:14;
}
###Block I wanto to insert
host client_i_want_to_insert {
hardware ethernet e3:ee:ed:ea:1d:e4;
}
###########
}}
dhcp isc-dhcpd
What is the desired output?
– Nasir Riley
Jan 5 at 15:40
add a comment |
I am looking for a command that allows me to insert an host inside the dhcpd.conf file
without manualy touching that file.
I am using: CentOS release 5.3.
The file looks like this:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
host client1 {
hardware ethernet 00:04:0d:0c:0f:0a;
}
host client2 {
hardware ethernet a0:be:cd:ea:1d:14;
}
###Block I wanto to insert
host client_i_want_to_insert {
hardware ethernet e3:ee:ed:ea:1d:e4;
}
###########
}}
dhcp isc-dhcpd
I am looking for a command that allows me to insert an host inside the dhcpd.conf file
without manualy touching that file.
I am using: CentOS release 5.3.
The file looks like this:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
host client1 {
hardware ethernet 00:04:0d:0c:0f:0a;
}
host client2 {
hardware ethernet a0:be:cd:ea:1d:14;
}
###Block I wanto to insert
host client_i_want_to_insert {
hardware ethernet e3:ee:ed:ea:1d:e4;
}
###########
}}
dhcp isc-dhcpd
dhcp isc-dhcpd
edited Jan 5 at 20:20
Rui F Ribeiro
39.5k1479132
39.5k1479132
asked Jan 5 at 15:26
Yerry GarcíaYerry García
162
162
What is the desired output?
– Nasir Riley
Jan 5 at 15:40
add a comment |
What is the desired output?
– Nasir Riley
Jan 5 at 15:40
What is the desired output?
– Nasir Riley
Jan 5 at 15:40
What is the desired output?
– Nasir Riley
Jan 5 at 15:40
add a comment |
2 Answers
2
active
oldest
votes
For answering to your specific string-handling question:
You can use
sedto insert lines before a string in the middle of
file, for your use case.
As such, supposing your file is:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
host client1 {
hardware ethernet 00:04:0d:0c:0f:0a;
}
host client2 {
hardware ethernet a0:be:cd:ea:1d:14;
}
####
}}
You can do:
sed -i '/####/i
thost client_i_want_to_insert {nthardware ethernet e3:ee:ed:ea:1d:e4;nt}n' /etc/dhcp/dhcpd.conf
However, in the past I also managed a couple of ISP cable modems (I
clearly recognise that line filename "3M-1M-OKS2016NOV.cm"; as
provisioning a cable modem configuration file).
I have several recommendations to add:
- Having a host definition spanning several lines is not practical. Over time the DHCP file will become unwieldy. For scripting it is
more difficult, both for inserting or removing lines. I recommend
doing only it over one line as:
host client2 { hardware ethernet a0:be:cd:ea:1d:14; }
- The names of hostnames also have to be unique. Either you increment them, or use your customer code *if* a numeric code.
- an alternative, when incrementing the host part, is putting a comment with the customer code *after* the host definition. As an
added bonus, it is more easier to deal with the file, if you need to
do it manually to fix some provisioning mistake, or do some rapid
intervention.
host client2 { hardware ethernet a0:be:cd:ea:1d:14; } #_cus234XP_
As such, when deleting a customer, as you are dealing with
one-liners, you just need a single grep -v or sed.
Further, ISC DHCP also lets you include files. For not having to
insert lines into the middle of a configuration file, you can do:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
include "customers";
}}
And then the customers file should be something like:
host client1 { hardware ethernet 00:04:0d:0c:0f:0a; } #_cus234XP_
host client2 { hardware ethernet a0:be:cd:ea:1d:14; } #_cus235XZ_
So, then, you just need to append new CM/customers to the end of the
file, and not need to deal with sed/awk, at least for adding new
customers.
Furthermore, I would advise eyeing other possible solutions for
implementing DHCP provisioning for CM modems/customers.
In the past, I wrote provisioning software for dealing with ISC DHCP
text files, for a couple of years. There are some limitations to the
process:
- Each time a new item is removed/inserted, the service has to be restarted;
- If by chance you duplicate an host, the service won't restart;
- Any kind of parsing has to be done in text mode, or done in ancillary/duplicate methods;
- If some auxiliary housekeeping is done by hand, it is prone to errors.
I then discovered docsis_server which is an "hacked" ISC DHCP on top of MySQL for Linux, specifically developed as a provisioning open source middle ware for the cable industry. I ended up writing my provisioning software/web front end on top of it. It was a boon dealing directly with MySQL queries, instead of text files, for interacting with the DHCP service.
Sadly, I think the project is no longer maintained. https://github.com/bschirrmeister/docsis_server
Nowadays, you also have the Kea project from ISC for DHCP, which is worth a look. It seems very interesting to develop on top of it for provisioning schemes. https://kea.isc.org
Kea is an open source software system including DHCPv4, DHCPv6
servers, Dynamic DNS daemon, REST API interface, MySQL, PostgreSQL and
Cassandra databases, RADIUS and NETCONF interfaces and related
utilities.
Lastly, normally the cable modem control network is a private IP address space in the 10.x.x.x range ; there is no business here with giving public IP addresses to cable modems such as 97.129.2.x as you are using.
P.S. AFAIK, the provisioning solution I wrote on top of docsis_server has been in production for 10 years now.
1
@GAD3R I was searching to that netmask tidbit to delete it, you beat me to it...thanks.
– Rui F Ribeiro
Jan 5 at 17:56
dhcpd file has multiple subnets with multiple filenames, so I have to look for the exact subnet with the group having the exact filename and insert the new client.
– Yerry García
Jan 6 at 19:08
but what I am looking for is a native ISC DHCP SERVER linux command like: dhcp add host "host client_i_want_to_insert {hardware ethernet e3:ee:ed:ea:1d:e4;}" inside "subnet ip_address" with filename "3M-1M-OKS2016NOV.cm" This is just an example code.
– Yerry García
Jan 6 at 19:18
@YerryGarcía I recommend investing more time in questions, that is not obvious from the question itself. Those kind of management "problems" is why I wrote management software, and later on went withdocsis_serverand why it might be worthy investigating kea, that supports other backends besides text. However, some backends /ISP extensions in kea are paid. Supposedly such backend was meant to exist in ISC DHCP, but I suppose was not never extended and fixed(?). Even it worked well (it does not), it would meant keeping the text files on parallel, as it would be run-time modifications only.
– Rui F Ribeiro
Jan 6 at 20:45
@YerryGarcía Truth to be told, there are LDAP extensions to ISC DHCP, but AFAIK they were not never officially fully supported by ISC. These kind of automation stuff involves some planning and programming, and even the question and my answer enters sound in off-topic territory here. Contact me into my profile personal contacts, I can give some very general pointers.
– Rui F Ribeiro
Jan 6 at 20:54
|
show 3 more comments
awk solution
awk '/}}/{$0="thost client3 {ntthardware ethernet a:b:c;nt}n"$0}1' file
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492674%2fis-there-a-command-to-insert-a-mac-address-into-a-subnet-in-dhcpd-conf-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
For answering to your specific string-handling question:
You can use
sedto insert lines before a string in the middle of
file, for your use case.
As such, supposing your file is:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
host client1 {
hardware ethernet 00:04:0d:0c:0f:0a;
}
host client2 {
hardware ethernet a0:be:cd:ea:1d:14;
}
####
}}
You can do:
sed -i '/####/i
thost client_i_want_to_insert {nthardware ethernet e3:ee:ed:ea:1d:e4;nt}n' /etc/dhcp/dhcpd.conf
However, in the past I also managed a couple of ISP cable modems (I
clearly recognise that line filename "3M-1M-OKS2016NOV.cm"; as
provisioning a cable modem configuration file).
I have several recommendations to add:
- Having a host definition spanning several lines is not practical. Over time the DHCP file will become unwieldy. For scripting it is
more difficult, both for inserting or removing lines. I recommend
doing only it over one line as:
host client2 { hardware ethernet a0:be:cd:ea:1d:14; }
- The names of hostnames also have to be unique. Either you increment them, or use your customer code *if* a numeric code.
- an alternative, when incrementing the host part, is putting a comment with the customer code *after* the host definition. As an
added bonus, it is more easier to deal with the file, if you need to
do it manually to fix some provisioning mistake, or do some rapid
intervention.
host client2 { hardware ethernet a0:be:cd:ea:1d:14; } #_cus234XP_
As such, when deleting a customer, as you are dealing with
one-liners, you just need a single grep -v or sed.
Further, ISC DHCP also lets you include files. For not having to
insert lines into the middle of a configuration file, you can do:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
include "customers";
}}
And then the customers file should be something like:
host client1 { hardware ethernet 00:04:0d:0c:0f:0a; } #_cus234XP_
host client2 { hardware ethernet a0:be:cd:ea:1d:14; } #_cus235XZ_
So, then, you just need to append new CM/customers to the end of the
file, and not need to deal with sed/awk, at least for adding new
customers.
Furthermore, I would advise eyeing other possible solutions for
implementing DHCP provisioning for CM modems/customers.
In the past, I wrote provisioning software for dealing with ISC DHCP
text files, for a couple of years. There are some limitations to the
process:
- Each time a new item is removed/inserted, the service has to be restarted;
- If by chance you duplicate an host, the service won't restart;
- Any kind of parsing has to be done in text mode, or done in ancillary/duplicate methods;
- If some auxiliary housekeeping is done by hand, it is prone to errors.
I then discovered docsis_server which is an "hacked" ISC DHCP on top of MySQL for Linux, specifically developed as a provisioning open source middle ware for the cable industry. I ended up writing my provisioning software/web front end on top of it. It was a boon dealing directly with MySQL queries, instead of text files, for interacting with the DHCP service.
Sadly, I think the project is no longer maintained. https://github.com/bschirrmeister/docsis_server
Nowadays, you also have the Kea project from ISC for DHCP, which is worth a look. It seems very interesting to develop on top of it for provisioning schemes. https://kea.isc.org
Kea is an open source software system including DHCPv4, DHCPv6
servers, Dynamic DNS daemon, REST API interface, MySQL, PostgreSQL and
Cassandra databases, RADIUS and NETCONF interfaces and related
utilities.
Lastly, normally the cable modem control network is a private IP address space in the 10.x.x.x range ; there is no business here with giving public IP addresses to cable modems such as 97.129.2.x as you are using.
P.S. AFAIK, the provisioning solution I wrote on top of docsis_server has been in production for 10 years now.
1
@GAD3R I was searching to that netmask tidbit to delete it, you beat me to it...thanks.
– Rui F Ribeiro
Jan 5 at 17:56
dhcpd file has multiple subnets with multiple filenames, so I have to look for the exact subnet with the group having the exact filename and insert the new client.
– Yerry García
Jan 6 at 19:08
but what I am looking for is a native ISC DHCP SERVER linux command like: dhcp add host "host client_i_want_to_insert {hardware ethernet e3:ee:ed:ea:1d:e4;}" inside "subnet ip_address" with filename "3M-1M-OKS2016NOV.cm" This is just an example code.
– Yerry García
Jan 6 at 19:18
@YerryGarcía I recommend investing more time in questions, that is not obvious from the question itself. Those kind of management "problems" is why I wrote management software, and later on went withdocsis_serverand why it might be worthy investigating kea, that supports other backends besides text. However, some backends /ISP extensions in kea are paid. Supposedly such backend was meant to exist in ISC DHCP, but I suppose was not never extended and fixed(?). Even it worked well (it does not), it would meant keeping the text files on parallel, as it would be run-time modifications only.
– Rui F Ribeiro
Jan 6 at 20:45
@YerryGarcía Truth to be told, there are LDAP extensions to ISC DHCP, but AFAIK they were not never officially fully supported by ISC. These kind of automation stuff involves some planning and programming, and even the question and my answer enters sound in off-topic territory here. Contact me into my profile personal contacts, I can give some very general pointers.
– Rui F Ribeiro
Jan 6 at 20:54
|
show 3 more comments
For answering to your specific string-handling question:
You can use
sedto insert lines before a string in the middle of
file, for your use case.
As such, supposing your file is:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
host client1 {
hardware ethernet 00:04:0d:0c:0f:0a;
}
host client2 {
hardware ethernet a0:be:cd:ea:1d:14;
}
####
}}
You can do:
sed -i '/####/i
thost client_i_want_to_insert {nthardware ethernet e3:ee:ed:ea:1d:e4;nt}n' /etc/dhcp/dhcpd.conf
However, in the past I also managed a couple of ISP cable modems (I
clearly recognise that line filename "3M-1M-OKS2016NOV.cm"; as
provisioning a cable modem configuration file).
I have several recommendations to add:
- Having a host definition spanning several lines is not practical. Over time the DHCP file will become unwieldy. For scripting it is
more difficult, both for inserting or removing lines. I recommend
doing only it over one line as:
host client2 { hardware ethernet a0:be:cd:ea:1d:14; }
- The names of hostnames also have to be unique. Either you increment them, or use your customer code *if* a numeric code.
- an alternative, when incrementing the host part, is putting a comment with the customer code *after* the host definition. As an
added bonus, it is more easier to deal with the file, if you need to
do it manually to fix some provisioning mistake, or do some rapid
intervention.
host client2 { hardware ethernet a0:be:cd:ea:1d:14; } #_cus234XP_
As such, when deleting a customer, as you are dealing with
one-liners, you just need a single grep -v or sed.
Further, ISC DHCP also lets you include files. For not having to
insert lines into the middle of a configuration file, you can do:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
include "customers";
}}
And then the customers file should be something like:
host client1 { hardware ethernet 00:04:0d:0c:0f:0a; } #_cus234XP_
host client2 { hardware ethernet a0:be:cd:ea:1d:14; } #_cus235XZ_
So, then, you just need to append new CM/customers to the end of the
file, and not need to deal with sed/awk, at least for adding new
customers.
Furthermore, I would advise eyeing other possible solutions for
implementing DHCP provisioning for CM modems/customers.
In the past, I wrote provisioning software for dealing with ISC DHCP
text files, for a couple of years. There are some limitations to the
process:
- Each time a new item is removed/inserted, the service has to be restarted;
- If by chance you duplicate an host, the service won't restart;
- Any kind of parsing has to be done in text mode, or done in ancillary/duplicate methods;
- If some auxiliary housekeeping is done by hand, it is prone to errors.
I then discovered docsis_server which is an "hacked" ISC DHCP on top of MySQL for Linux, specifically developed as a provisioning open source middle ware for the cable industry. I ended up writing my provisioning software/web front end on top of it. It was a boon dealing directly with MySQL queries, instead of text files, for interacting with the DHCP service.
Sadly, I think the project is no longer maintained. https://github.com/bschirrmeister/docsis_server
Nowadays, you also have the Kea project from ISC for DHCP, which is worth a look. It seems very interesting to develop on top of it for provisioning schemes. https://kea.isc.org
Kea is an open source software system including DHCPv4, DHCPv6
servers, Dynamic DNS daemon, REST API interface, MySQL, PostgreSQL and
Cassandra databases, RADIUS and NETCONF interfaces and related
utilities.
Lastly, normally the cable modem control network is a private IP address space in the 10.x.x.x range ; there is no business here with giving public IP addresses to cable modems such as 97.129.2.x as you are using.
P.S. AFAIK, the provisioning solution I wrote on top of docsis_server has been in production for 10 years now.
1
@GAD3R I was searching to that netmask tidbit to delete it, you beat me to it...thanks.
– Rui F Ribeiro
Jan 5 at 17:56
dhcpd file has multiple subnets with multiple filenames, so I have to look for the exact subnet with the group having the exact filename and insert the new client.
– Yerry García
Jan 6 at 19:08
but what I am looking for is a native ISC DHCP SERVER linux command like: dhcp add host "host client_i_want_to_insert {hardware ethernet e3:ee:ed:ea:1d:e4;}" inside "subnet ip_address" with filename "3M-1M-OKS2016NOV.cm" This is just an example code.
– Yerry García
Jan 6 at 19:18
@YerryGarcía I recommend investing more time in questions, that is not obvious from the question itself. Those kind of management "problems" is why I wrote management software, and later on went withdocsis_serverand why it might be worthy investigating kea, that supports other backends besides text. However, some backends /ISP extensions in kea are paid. Supposedly such backend was meant to exist in ISC DHCP, but I suppose was not never extended and fixed(?). Even it worked well (it does not), it would meant keeping the text files on parallel, as it would be run-time modifications only.
– Rui F Ribeiro
Jan 6 at 20:45
@YerryGarcía Truth to be told, there are LDAP extensions to ISC DHCP, but AFAIK they were not never officially fully supported by ISC. These kind of automation stuff involves some planning and programming, and even the question and my answer enters sound in off-topic territory here. Contact me into my profile personal contacts, I can give some very general pointers.
– Rui F Ribeiro
Jan 6 at 20:54
|
show 3 more comments
For answering to your specific string-handling question:
You can use
sedto insert lines before a string in the middle of
file, for your use case.
As such, supposing your file is:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
host client1 {
hardware ethernet 00:04:0d:0c:0f:0a;
}
host client2 {
hardware ethernet a0:be:cd:ea:1d:14;
}
####
}}
You can do:
sed -i '/####/i
thost client_i_want_to_insert {nthardware ethernet e3:ee:ed:ea:1d:e4;nt}n' /etc/dhcp/dhcpd.conf
However, in the past I also managed a couple of ISP cable modems (I
clearly recognise that line filename "3M-1M-OKS2016NOV.cm"; as
provisioning a cable modem configuration file).
I have several recommendations to add:
- Having a host definition spanning several lines is not practical. Over time the DHCP file will become unwieldy. For scripting it is
more difficult, both for inserting or removing lines. I recommend
doing only it over one line as:
host client2 { hardware ethernet a0:be:cd:ea:1d:14; }
- The names of hostnames also have to be unique. Either you increment them, or use your customer code *if* a numeric code.
- an alternative, when incrementing the host part, is putting a comment with the customer code *after* the host definition. As an
added bonus, it is more easier to deal with the file, if you need to
do it manually to fix some provisioning mistake, or do some rapid
intervention.
host client2 { hardware ethernet a0:be:cd:ea:1d:14; } #_cus234XP_
As such, when deleting a customer, as you are dealing with
one-liners, you just need a single grep -v or sed.
Further, ISC DHCP also lets you include files. For not having to
insert lines into the middle of a configuration file, you can do:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
include "customers";
}}
And then the customers file should be something like:
host client1 { hardware ethernet 00:04:0d:0c:0f:0a; } #_cus234XP_
host client2 { hardware ethernet a0:be:cd:ea:1d:14; } #_cus235XZ_
So, then, you just need to append new CM/customers to the end of the
file, and not need to deal with sed/awk, at least for adding new
customers.
Furthermore, I would advise eyeing other possible solutions for
implementing DHCP provisioning for CM modems/customers.
In the past, I wrote provisioning software for dealing with ISC DHCP
text files, for a couple of years. There are some limitations to the
process:
- Each time a new item is removed/inserted, the service has to be restarted;
- If by chance you duplicate an host, the service won't restart;
- Any kind of parsing has to be done in text mode, or done in ancillary/duplicate methods;
- If some auxiliary housekeeping is done by hand, it is prone to errors.
I then discovered docsis_server which is an "hacked" ISC DHCP on top of MySQL for Linux, specifically developed as a provisioning open source middle ware for the cable industry. I ended up writing my provisioning software/web front end on top of it. It was a boon dealing directly with MySQL queries, instead of text files, for interacting with the DHCP service.
Sadly, I think the project is no longer maintained. https://github.com/bschirrmeister/docsis_server
Nowadays, you also have the Kea project from ISC for DHCP, which is worth a look. It seems very interesting to develop on top of it for provisioning schemes. https://kea.isc.org
Kea is an open source software system including DHCPv4, DHCPv6
servers, Dynamic DNS daemon, REST API interface, MySQL, PostgreSQL and
Cassandra databases, RADIUS and NETCONF interfaces and related
utilities.
Lastly, normally the cable modem control network is a private IP address space in the 10.x.x.x range ; there is no business here with giving public IP addresses to cable modems such as 97.129.2.x as you are using.
P.S. AFAIK, the provisioning solution I wrote on top of docsis_server has been in production for 10 years now.
For answering to your specific string-handling question:
You can use
sedto insert lines before a string in the middle of
file, for your use case.
As such, supposing your file is:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
host client1 {
hardware ethernet 00:04:0d:0c:0f:0a;
}
host client2 {
hardware ethernet a0:be:cd:ea:1d:14;
}
####
}}
You can do:
sed -i '/####/i
thost client_i_want_to_insert {nthardware ethernet e3:ee:ed:ea:1d:e4;nt}n' /etc/dhcp/dhcpd.conf
However, in the past I also managed a couple of ISP cable modems (I
clearly recognise that line filename "3M-1M-OKS2016NOV.cm"; as
provisioning a cable modem configuration file).
I have several recommendations to add:
- Having a host definition spanning several lines is not practical. Over time the DHCP file will become unwieldy. For scripting it is
more difficult, both for inserting or removing lines. I recommend
doing only it over one line as:
host client2 { hardware ethernet a0:be:cd:ea:1d:14; }
- The names of hostnames also have to be unique. Either you increment them, or use your customer code *if* a numeric code.
- an alternative, when incrementing the host part, is putting a comment with the customer code *after* the host definition. As an
added bonus, it is more easier to deal with the file, if you need to
do it manually to fix some provisioning mistake, or do some rapid
intervention.
host client2 { hardware ethernet a0:be:cd:ea:1d:14; } #_cus234XP_
As such, when deleting a customer, as you are dealing with
one-liners, you just need a single grep -v or sed.
Further, ISC DHCP also lets you include files. For not having to
insert lines into the middle of a configuration file, you can do:
subnet 97.129.0.0 netmask 255.255.240.0 {
deny unknown-clients;
range 97.129.2.2 97.129.2.254;
group {
filename "3M-1M-OKS2016NOV.cm";
include "customers";
}}
And then the customers file should be something like:
host client1 { hardware ethernet 00:04:0d:0c:0f:0a; } #_cus234XP_
host client2 { hardware ethernet a0:be:cd:ea:1d:14; } #_cus235XZ_
So, then, you just need to append new CM/customers to the end of the
file, and not need to deal with sed/awk, at least for adding new
customers.
Furthermore, I would advise eyeing other possible solutions for
implementing DHCP provisioning for CM modems/customers.
In the past, I wrote provisioning software for dealing with ISC DHCP
text files, for a couple of years. There are some limitations to the
process:
- Each time a new item is removed/inserted, the service has to be restarted;
- If by chance you duplicate an host, the service won't restart;
- Any kind of parsing has to be done in text mode, or done in ancillary/duplicate methods;
- If some auxiliary housekeeping is done by hand, it is prone to errors.
I then discovered docsis_server which is an "hacked" ISC DHCP on top of MySQL for Linux, specifically developed as a provisioning open source middle ware for the cable industry. I ended up writing my provisioning software/web front end on top of it. It was a boon dealing directly with MySQL queries, instead of text files, for interacting with the DHCP service.
Sadly, I think the project is no longer maintained. https://github.com/bschirrmeister/docsis_server
Nowadays, you also have the Kea project from ISC for DHCP, which is worth a look. It seems very interesting to develop on top of it for provisioning schemes. https://kea.isc.org
Kea is an open source software system including DHCPv4, DHCPv6
servers, Dynamic DNS daemon, REST API interface, MySQL, PostgreSQL and
Cassandra databases, RADIUS and NETCONF interfaces and related
utilities.
Lastly, normally the cable modem control network is a private IP address space in the 10.x.x.x range ; there is no business here with giving public IP addresses to cable modems such as 97.129.2.x as you are using.
P.S. AFAIK, the provisioning solution I wrote on top of docsis_server has been in production for 10 years now.
edited Jan 6 at 23:14
answered Jan 5 at 17:43
Rui F RibeiroRui F Ribeiro
39.5k1479132
39.5k1479132
1
@GAD3R I was searching to that netmask tidbit to delete it, you beat me to it...thanks.
– Rui F Ribeiro
Jan 5 at 17:56
dhcpd file has multiple subnets with multiple filenames, so I have to look for the exact subnet with the group having the exact filename and insert the new client.
– Yerry García
Jan 6 at 19:08
but what I am looking for is a native ISC DHCP SERVER linux command like: dhcp add host "host client_i_want_to_insert {hardware ethernet e3:ee:ed:ea:1d:e4;}" inside "subnet ip_address" with filename "3M-1M-OKS2016NOV.cm" This is just an example code.
– Yerry García
Jan 6 at 19:18
@YerryGarcía I recommend investing more time in questions, that is not obvious from the question itself. Those kind of management "problems" is why I wrote management software, and later on went withdocsis_serverand why it might be worthy investigating kea, that supports other backends besides text. However, some backends /ISP extensions in kea are paid. Supposedly such backend was meant to exist in ISC DHCP, but I suppose was not never extended and fixed(?). Even it worked well (it does not), it would meant keeping the text files on parallel, as it would be run-time modifications only.
– Rui F Ribeiro
Jan 6 at 20:45
@YerryGarcía Truth to be told, there are LDAP extensions to ISC DHCP, but AFAIK they were not never officially fully supported by ISC. These kind of automation stuff involves some planning and programming, and even the question and my answer enters sound in off-topic territory here. Contact me into my profile personal contacts, I can give some very general pointers.
– Rui F Ribeiro
Jan 6 at 20:54
|
show 3 more comments
1
@GAD3R I was searching to that netmask tidbit to delete it, you beat me to it...thanks.
– Rui F Ribeiro
Jan 5 at 17:56
dhcpd file has multiple subnets with multiple filenames, so I have to look for the exact subnet with the group having the exact filename and insert the new client.
– Yerry García
Jan 6 at 19:08
but what I am looking for is a native ISC DHCP SERVER linux command like: dhcp add host "host client_i_want_to_insert {hardware ethernet e3:ee:ed:ea:1d:e4;}" inside "subnet ip_address" with filename "3M-1M-OKS2016NOV.cm" This is just an example code.
– Yerry García
Jan 6 at 19:18
@YerryGarcía I recommend investing more time in questions, that is not obvious from the question itself. Those kind of management "problems" is why I wrote management software, and later on went withdocsis_serverand why it might be worthy investigating kea, that supports other backends besides text. However, some backends /ISP extensions in kea are paid. Supposedly such backend was meant to exist in ISC DHCP, but I suppose was not never extended and fixed(?). Even it worked well (it does not), it would meant keeping the text files on parallel, as it would be run-time modifications only.
– Rui F Ribeiro
Jan 6 at 20:45
@YerryGarcía Truth to be told, there are LDAP extensions to ISC DHCP, but AFAIK they were not never officially fully supported by ISC. These kind of automation stuff involves some planning and programming, and even the question and my answer enters sound in off-topic territory here. Contact me into my profile personal contacts, I can give some very general pointers.
– Rui F Ribeiro
Jan 6 at 20:54
1
1
@GAD3R I was searching to that netmask tidbit to delete it, you beat me to it...thanks.
– Rui F Ribeiro
Jan 5 at 17:56
@GAD3R I was searching to that netmask tidbit to delete it, you beat me to it...thanks.
– Rui F Ribeiro
Jan 5 at 17:56
dhcpd file has multiple subnets with multiple filenames, so I have to look for the exact subnet with the group having the exact filename and insert the new client.
– Yerry García
Jan 6 at 19:08
dhcpd file has multiple subnets with multiple filenames, so I have to look for the exact subnet with the group having the exact filename and insert the new client.
– Yerry García
Jan 6 at 19:08
but what I am looking for is a native ISC DHCP SERVER linux command like: dhcp add host "host client_i_want_to_insert {hardware ethernet e3:ee:ed:ea:1d:e4;}" inside "subnet ip_address" with filename "3M-1M-OKS2016NOV.cm" This is just an example code.
– Yerry García
Jan 6 at 19:18
but what I am looking for is a native ISC DHCP SERVER linux command like: dhcp add host "host client_i_want_to_insert {hardware ethernet e3:ee:ed:ea:1d:e4;}" inside "subnet ip_address" with filename "3M-1M-OKS2016NOV.cm" This is just an example code.
– Yerry García
Jan 6 at 19:18
@YerryGarcía I recommend investing more time in questions, that is not obvious from the question itself. Those kind of management "problems" is why I wrote management software, and later on went with
docsis_server and why it might be worthy investigating kea, that supports other backends besides text. However, some backends /ISP extensions in kea are paid. Supposedly such backend was meant to exist in ISC DHCP, but I suppose was not never extended and fixed(?). Even it worked well (it does not), it would meant keeping the text files on parallel, as it would be run-time modifications only.– Rui F Ribeiro
Jan 6 at 20:45
@YerryGarcía I recommend investing more time in questions, that is not obvious from the question itself. Those kind of management "problems" is why I wrote management software, and later on went with
docsis_server and why it might be worthy investigating kea, that supports other backends besides text. However, some backends /ISP extensions in kea are paid. Supposedly such backend was meant to exist in ISC DHCP, but I suppose was not never extended and fixed(?). Even it worked well (it does not), it would meant keeping the text files on parallel, as it would be run-time modifications only.– Rui F Ribeiro
Jan 6 at 20:45
@YerryGarcía Truth to be told, there are LDAP extensions to ISC DHCP, but AFAIK they were not never officially fully supported by ISC. These kind of automation stuff involves some planning and programming, and even the question and my answer enters sound in off-topic territory here. Contact me into my profile personal contacts, I can give some very general pointers.
– Rui F Ribeiro
Jan 6 at 20:54
@YerryGarcía Truth to be told, there are LDAP extensions to ISC DHCP, but AFAIK they were not never officially fully supported by ISC. These kind of automation stuff involves some planning and programming, and even the question and my answer enters sound in off-topic territory here. Contact me into my profile personal contacts, I can give some very general pointers.
– Rui F Ribeiro
Jan 6 at 20:54
|
show 3 more comments
awk solution
awk '/}}/{$0="thost client3 {ntthardware ethernet a:b:c;nt}n"$0}1' file
add a comment |
awk solution
awk '/}}/{$0="thost client3 {ntthardware ethernet a:b:c;nt}n"$0}1' file
add a comment |
awk solution
awk '/}}/{$0="thost client3 {ntthardware ethernet a:b:c;nt}n"$0}1' file
awk solution
awk '/}}/{$0="thost client3 {ntthardware ethernet a:b:c;nt}n"$0}1' file
answered Jan 5 at 21:59
stevesteve
13.9k22452
13.9k22452
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492674%2fis-there-a-command-to-insert-a-mac-address-into-a-subnet-in-dhcpd-conf-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is the desired output?
– Nasir Riley
Jan 5 at 15:40