{"id":270,"date":"2023-12-16T19:07:24","date_gmt":"2023-12-17T02:07:24","guid":{"rendered":"http:\/\/www.ipcalypse.ca\/?p=270"},"modified":"2023-12-16T19:07:24","modified_gmt":"2023-12-17T02:07:24","slug":"stupid-ipv6-tricks-get-current-ipv6-address-linux","status":"publish","type":"post","link":"https:\/\/www.ipcalypse.ca\/?p=270","title":{"rendered":"Stupid ipv6 tricks &#8211; get current ipv6 address &#8211; linux"},"content":{"rendered":"<p>how to get current ipv6 address when addresses change<br \/>\nmy computer got a new address, the old address has a preferred lifetime of 0:<\/p>\n<p># ip -6 address show dev eth0<br \/>\n2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 state UP qlen 1000<br \/>\ninet6 2604:3d09:3580:a:f66d:4ff:fe32:eaf9\/64 scope global mngtmpaddr dynamic<br \/>\nvalid_lft 600sec preferred_lft 300sec<br \/>\ninet6 2604:3d00:d44a:486:f66d:4ff:fe32:eaf9\/64 scope global deprecated mngtmpaddr dynamic<br \/>\nvalid_lft 300sec preferred_lft 0sec<br \/>\ninet6 fe80::f66d:4ff:fe32:eaf9\/64 scope link<br \/>\nvalid_lft forever preferred_lft forever<\/p>\n<p>I only want the valid address for scripts:<br \/>\n# ip -6 address show dev eth0 | grep -v deprecated | grep mngtmpaddr\u00a0| sed -e&#8217;s\/^.*inet6 \\([^ ]*\\)\\\/.*$\/\\1\/;t;d&#8217;<\/p>\n<p>2604:3d09:3580:a:f66d:4ff:fe32:eaf9<\/p>\n<p>yay!<\/p>\n<p>What this does:<\/p>\n<ol>\n<li>ip -6 address show dev eth0\n<ol>\n<li>This shows all the ipv6 addresses configured on eth0<\/li>\n<\/ol>\n<\/li>\n<li>\u00a0grep mngtmpaddr\n<ol>\n<li>This grep displays only addresses that were derived from the MAC address (IE SLAAC addresses)<\/li>\n<\/ol>\n<\/li>\n<li>grep -v deprecated\n<ol>\n<li>This grep removes addresses that are deprecated (IE preferred lifetime = 0) and shouldn&#8217;t be used.<\/li>\n<\/ol>\n<\/li>\n<li>sed \u00a0-e&#8217;s\/^.*inet6 \\([^ ]*\\)\\\/.*$\/\\1\/;t;d&#8217;\n<ol>\n<li>This regex removes \u00a0everything but IPv6 addresses from the line.\n<ol>\n<li>found at\u00a0https:\/\/superuser.com\/questions\/389766\/linux-bash-how-to-get-interfaces-ipv6-address<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>need some way to detect when changes happen.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>how to get current ipv6 address when addresses change my computer got a new address, the old address has a preferred lifetime of 0: # ip -6 address show dev eth0 2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 state UP qlen 1000 inet6 2604:3d09:3580:a:f66d:4ff:fe32:eaf9\/64 scope global mngtmpaddr dynamic valid_lft 600sec preferred_lft 300sec inet6 2604:3d00:d44a:486:f66d:4ff:fe32:eaf9\/64 scope global deprecated [&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":[],"class_list":["post-270","post","type-post","status-publish","format-standard","hentry","category-ipv6","category-linux"],"_links":{"self":[{"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=\/wp\/v2\/posts\/270","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=270"}],"version-history":[{"count":4,"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=\/wp\/v2\/posts\/270\/revisions"}],"predecessor-version":[{"id":313,"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=\/wp\/v2\/posts\/270\/revisions\/313"}],"wp:attachment":[{"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ipcalypse.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}