3

According to this answer...

https://unix.stackexchange.com/a/457577/61742

... I can use the following configuration to use pushed routes from my DHCP server in my DHCP client by placing in the /etc/dhclient.conf or /etc/dhcp3/dhclient.conf file the following configuration...

option classless-static-routes code 121 = array of { ip-address, ip-address };

But in CentOS 7 this file does not exist, but the following files...

[root@localhost ~]# ps -eaf | grep dhcli
root       780   650  0 15:02 ?        00:00:00 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-enp0s8.pid -lf /var/lib/NetworkManager/dhclient-00cb8299-feb9-55b6-a378-3fdc720e0bc6-enp0s8.lease -cf /var/lib/NetworkManager/dhclient-enp0s8.conf enp0s8
root       783   650  0 15:02 ?        00:00:00 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-enp0s17.pid -lf /var/lib/NetworkManager/dhclient-8512e951-6012-c639-73b1-5b4d7b469f7f-enp0s17.lease -cf /var/lib/NetworkManager/dhclient-enp0s17.conf enp0s17
root      2218  1152  0 15:36 pts/0    00:00:00 grep --color=auto dhcli

NOTE: Note the value for the "-cf" parameter (files: /var/lib/NetworkManager/dhclient-enp0s8.conf and /var/lib/NetworkManager/dhclient-enp0s17.conf).

My question is: What is the correct way to use "classless-static-routes" (code 121) on a CentOS 7 DHCP client?

Thanks!


PLUS:

This is the configuration of my ISC KEA DHCP (DHCPv4)...

cat /usr/local/etc/kea/kea-dhcp4.conf

[...]
"option-def": [{
        "name": "rfc3442-classless-static-routes",
        "code": 121,
        "space": "dhcp4",
        "type": "record",
        "record-types": "uint8,uint8,uint8,ipv4-address"
    }
],
"option-data": [{
        "name": "rfc3442-classless-static-routes",
        "data": "10,1,4, 10.1.6.4"
}]
[...]

The goal is that requests to 10.1.4.0/24 be routed to ip 10.1.6.4/32 in my DHCP clients.

NOTE: Is the same thing I would get with the command ip route add 10.1.4.0/24 dev enp0s8 via 10.1.6.4 in each my DHCP clients.

  • I think /etc/dhcp/dhclient-exit-hooks.d/rfc3442-classless-routes does that job by default. Nonetheless, I am not much found of passing around static routes via DHCP. – Rui F Ribeiro Aug 1 '18 at 21:54
  • 1
    Please read this. Mainly: add also request rfc3442-classless-static-routes; (and the ms option for Microsoft) in the dhcp client config file (whichever it might be). – Isaac Aug 1 '18 at 22:24
  • 1
    Hmmm, Network manager is not the best way to manage static routes from dhcp (IMnshO). Is that a must requirement? – Isaac Aug 1 '18 at 22:30
  • 1
    @EduardoLucio Network Manager is designed (and used) to bring interfaces up for each diferent user when the GUI (desktop manager) starts. That is not a "system wide" interface configuration. Where each interface has "static" values for all users. It is up to you to make take such decision. But it seems reasonable to me that "static routes" should be used with "static interfaces". Just saying ..... – Isaac Aug 2 '18 at 1:53
  • 1
    The KEA server is misconfigured "data": "10,1,4, 10.1.6.4" will hand a route to network 1.4.0.0/10 (it's already wrong this would be 1.0.0.0/10) via 10.1.6.4 . The answer is in rfc 3422 + kea's informations (previous link I provided twice). Both have to be understood – A.B Aug 2 '18 at 6:44
2

Shameless copying from this answer:

If you wish to do this via DHCP, ensure that your have properly configured your DHCP client per the RedHat Knowledgebase article in here

To ensure that RFC3442-standard classless static routes provided by a DHCP server are processed correctly when using NetworkManager, the following lines should be placed into /etc/dhclient.conf or, if using per-interface DHCP options, /etc/dhclient-<ifname>.conf:

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8; 
option ms-classless-static-routes code 249 = array of unsigned integer 8; 
also request rfc3442-classless-static-routes;
also request ms-classless-static-routes;

These lines will ensure that RFC3442 classless static routes are requested from the DHCP server, and that they are properly processed by NetworkManager.

  • I tried what you suggested, but it did not work. Note that the /var/lib/NetworkManager/dhclient-enp0s8.conf file contains everything that should be in /etc/dhclient-.conf. The impression I have is that in reality this is already configured... I'm really confused... =/ Thanks! – Eduardo Lucio Aug 2 '18 at 2:37
  • 1
    It did not work is a pretty broad statement. It does not give any detail of what did work and what exactly did not work. Are the static routes being emitted by the DHCP server? Are the static routes being loaded to the route table of the client computers? Is a ping meant to reach a computer in the 10.1.6.0/24 network and sent from a computer in the 10.1.4.0/24 actually reaching the 10.1.6.0/24 network? Are the pings in the 10.1.4.0/24 network being answered by the target computer? Are the answer packets traveling back to the 10.1.6.0/24 network? so on and so forth ...@EduardoLucio – Isaac Aug 2 '18 at 2:52
  • Any suggestions on what tests (a bash command, for example) could I do to get you better information? =D Thanks! – Eduardo Lucio Aug 2 '18 at 3:01
  • That's basic networking work that you must be able to perform on your own. It is pretty complex to build a shell script to do all of that (and several different commands should be executed in different computers at different times). No, not something that you should expect to get here (nor anywhere else). @EduardoLucio – Isaac Aug 2 '18 at 3:09
1

In fact this answer is a complement to @Isaac's answer and some pitfalls - may seem a bit obvious, but not to me - on the issue presented.

First of all, although there is some pattern within the presented universe, it is necessary to understand a correlation between what is configured in DHCP Server and what is expected in DHCP Client. Practically, parameters such as "option-def" -> "name" can vary between "rfc3442-classless-static-routes" and "classless-static-routes", "option-def" -> "record-types" between "uint8, uint8, uint8, ipv4-address" and "uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint8", and so on... That is, it depends on what the DHCP Client expects from the "other side" basically.

In the case of CentOS 7 what is pointed out in the thread https://unix.stackexchange.com/a/459963/61742 is already configured by default, then it is only necessary to configure in ISC KEA DHCP (DHCPv4) (my case) what CentOS 7 waits from the "other side".

Finally, the configuration looks like this...

cat /usr/local/etc/kea/kea-dhcp4.conf

[...]
"option-def": [{
        "name": "rfc3442-classless-static-routes",
        "code": 121,
        "space": "dhcp4",
        "type": "record",
        "array": true,
        "record-types": "uint8,uint8,uint8,uint8,uint8,uint8,uint8,uint8"
    }
],
"option-data": [{
        "name": "rfc3442-classless-static-routes",
        "data": "24,10,1,4,10,1,6,4"
}]
[...]

... since CentOS 7 is configured as...

cat /var/lib/NetworkManager/dhclient-enp0s8.conf

[...]
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8; 
also request rfc3442-classless-static-routes;
[...]

SOME CLARIFICATIONS:

"record-types" is a mask, that is, what is in each position of the array informed in "date" that as expected in CentOS 7 is an "array of unsigned integer 8" (uint8).

"data" works according to the following example: if I want the following routing 10.1.4.0/24 via 10.1.6.4 then I will inform "24,10,1,4,10,1,6,4". Note that the zero in 10.1.4.0/24 should be omitted since it is a mask for 3 octets (/24).

TIP: The "option-data" parameter can be placed in multiple locations in "subnet4" (file "/usr/local/etc/kea/kea-dhcp4.conf") and this will depend on how you want to distribute your configuration for routing.

Especial thanks to @Isaac , @Rui F Ribeiro and @A.B !

  • 1
    kea guide 8.2.9. Custom DHCPv4 options: "When array is set to true and type is set to "record", the last field is an array, i.e., it can contain more than one value" [...] so a single (or to be more rigorous 5 uint8 for a /0 + 1 ipv4) uint8 should work for all cases (as is done with the dhcpd equivalent). 8 uint8 will work only for /17 or narrower. – A.B Aug 2 '18 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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