{"id":355,"date":"2020-06-26T16:53:33","date_gmt":"2020-06-26T15:23:33","guid":{"rendered":"http:\/\/huf.org\/wp\/?p=355"},"modified":"2021-01-02T09:00:53","modified_gmt":"2021-01-02T08:00:53","slug":"raspberry-pi-make-routes-persistent-with-dhcpcd","status":"publish","type":"post","link":"https:\/\/huf.org\/wp\/?p=355","title":{"rendered":"raspberry pi: make routes persistent with dhcpcd"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"alignright is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/huf.org\/wp\/wp-content\/uploads\/2020\/06\/route.png\" alt=\"\" class=\"wp-image-359\" width=\"151\" height=\"236\" srcset=\"https:\/\/huf.org\/wp\/wp-content\/uploads\/2020\/06\/route.png 318w, https:\/\/huf.org\/wp\/wp-content\/uploads\/2020\/06\/route-192x300.png 192w\" sizes=\"auto, (max-width: 151px) 100vw, 151px\" \/><figcaption>routing decisions&#8230;<\/figcaption><\/figure><\/div>\n\n\n\n<p> <\/p>\n\n\n\n<p>so, the other day I needed to add a static route to my raspberry&#8217;s route table. the critter is running raspbian 9 (&#8222;jessie&#8220;). this version of debianesque linux uses dhcpcd for the network configuration.<\/p>\n\n\n\n<p>you can find a whole lot of info on how to configure the box with a static ip address. however, there are few examples for configuring a <em>static routing table entry <\/em>that will persist after a reboot.<\/p>\n\n\n\n<p>as we all know by now, you can enter a manual route using the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \/sbin\/route add -net 10.1.2.0\/24 gw 10.1.1.100<\/code><\/pre>\n\n\n\n<p>where 10.1.1.100 is the router on your local network behind which the target network 10.1.2.0 with the netmask 255.255.255.0 (the &#8222;\/24&#8220;) is to be found!<\/p>\n\n\n\n<p>this entry will be lost after a reboot. in order to make it persistent, you have to edit\/create a so-called &#8222;exit hook&#8220;. that&#8217;s a file that gets executed by dhcpd at various occasions, e.g. after the network interface has been configured with a valid address.<\/p>\n\n\n\n<p>here&#8217;s how to do it:<\/p>\n\n\n\n<p>edit the exit hook file. the command will create it, if it&#8217;s not there already:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># sudo vi \/etc\/dhcpcd.exit-hook<\/code><\/pre>\n\n\n\n<p>add the routing command, just as you&#8217;d type it on the command line (first line is for documentation):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>## adding the persistent route from the example above:\n\/sbin\/route add -net 10.1.2.0\/24 gw 10.1.1.100<\/code><\/pre>\n\n\n\n<p>now, in order to activate the hook file, you can try: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># sudo service dhcpcd restart<\/code><\/pre>\n\n\n\n<p>for a definitive test issue the <strong>reboot<\/strong> command.<\/p>\n\n\n\n<p>if something goes wrong, you can <strong>debug<\/strong> the dhcpcd hooks by editing the file <strong>\/lib\/dhcpcd\/dhcpcd-run-hooks<\/strong> and change the line<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>: ${syslog_debug:=false}\nto\n: ${syslog_debug:=true}<\/code><\/pre>\n\n\n\n<p>you can then <strong>&#8222;tail \/var\/syslog&#8220;<\/strong> in order to see the debug output.<\/p>\n\n\n\n<p>happy routing!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>so, the other day I needed to add a static route to my raspberry&#8217;s route table. the critter is running raspbian 9 (&#8222;jessie&#8220;). this version of debianesque linux uses dhcpcd for the network configuration. you can find a whole lot &hellip; <a href=\"https:\/\/huf.org\/wp\/?p=355\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-355","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/huf.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/huf.org\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/huf.org\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/huf.org\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/huf.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=355"}],"version-history":[{"count":9,"href":"https:\/\/huf.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/355\/revisions"}],"predecessor-version":[{"id":370,"href":"https:\/\/huf.org\/wp\/index.php?rest_route=\/wp\/v2\/posts\/355\/revisions\/370"}],"wp:attachment":[{"href":"https:\/\/huf.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/huf.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/huf.org\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}