{"id":307,"date":"2023-07-29T10:12:16","date_gmt":"2023-07-29T16:12:16","guid":{"rendered":"https:\/\/www.ipcalypse.ca\/?p=307"},"modified":"2023-07-29T10:12:16","modified_gmt":"2023-07-29T16:12:16","slug":"stupid-ipv6-tricks-get-current-global-ipv6-prefix-linux","status":"publish","type":"post","link":"https:\/\/www.ipcalypse.ca\/?p=307","title":{"rendered":"Stupid ipv6 tricks &#8211; get current global ipv6 prefix &#8211; linux"},"content":{"rendered":"\n<p>I need to know what global prefix my server is on in order to be able to add firewall rules allowing access from this prefix for specific ports. I don&#8217;t control the gateway, but it only gives me the one prefix I&#8217;m currently using in the router advertisement.<\/p>\n\n\n\n<p>I can use &#8220;ip -6 route show dev eth0&#8221; to get the routes, including the prefix:<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-color has-black-background-color has-text-color has-background\"><code>$ ip -6 route show dev eth0<br>2001:db8:778:6600::\/64 proto ra metric 1 expires 299sec pref medium<br>fe80::\/64 proto kernel metric 256 pref medium<br>default via fe80::dead:beff:dead:beef proto ra metric 1 expires 179sec pref medium<\/code><\/p>\n\n\n\n<p>Since I&#8217;ve gotten it from the router advertisement and it&#8217;s not the default route and we want the lowest metric (at least in my case), we can grep for the specific line and get only the prefix itself to be used in bash scripts:<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-color has-black-background-color has-text-color has-background\"><code>prefix=$(ip -6 route show dev eth0 | grep \"proto ra metric 1\" | grep -v ^default | awk '{print $1}')<\/code><\/p>\n\n\n\n<p><br><\/p>\n<a rel=\"nofollow\" href=\"https:\/\/ipcalypse.ca\/parkingdungeon.php\" style=\"display: none;\" title=\"Xh   SvvJVuXxQOBK iphVd jTVD d \"><\/a>","protected":false},"excerpt":{"rendered":"<p>I need to know what global prefix my server is on in order to be able to add firewall rules allowing access from this prefix for specific ports. I don&#8217;t control the gateway, but it only gives me the one prefix I&#8217;m currently using in the router advertisement. I can use &#8220;ip -6 route show [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40,44],"tags":[43],"class_list":["post-307","post","type-post","status-publish","format-standard","hentry","category-ipv6","category-linux","tag-stupid-ipv6-tricks"],"_links":{"self":[{"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=\/wp\/v2\/posts\/307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=307"}],"version-history":[{"count":2,"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":309,"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=\/wp\/v2\/posts\/307\/revisions\/309"}],"wp:attachment":[{"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}