Linux/bash: How to get interface's IPv6 address?












5















What command can I use to get IPv6 address of an interface in a script?



Update: Output of sed from one of answers.



$ ip -6 addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
inet6 fe80::224:d7ff:fed0:4f5c/64 scope link
valid_lft forever preferred_lft forever


The other:



$ ip addr show dev eth0 | sed -e's/^.*inet6 ([^ ]*)/.*$/1/;t;d'
$ ip addr show dev eth0
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether f0:de:f1:7b:e9:6c brd ff:ff:ff:ff:ff:ff









share|improve this question

























  • Which IPv6 addresses? Your interfaces' IPv6 addresses?

    – m0skit0
    Feb 14 '12 at 13:27













  • Yes, edited, thx.

    – Ondra Žižka
    Feb 21 '12 at 4:33
















5















What command can I use to get IPv6 address of an interface in a script?



Update: Output of sed from one of answers.



$ ip -6 addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
inet6 fe80::224:d7ff:fed0:4f5c/64 scope link
valid_lft forever preferred_lft forever


The other:



$ ip addr show dev eth0 | sed -e's/^.*inet6 ([^ ]*)/.*$/1/;t;d'
$ ip addr show dev eth0
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether f0:de:f1:7b:e9:6c brd ff:ff:ff:ff:ff:ff









share|improve this question

























  • Which IPv6 addresses? Your interfaces' IPv6 addresses?

    – m0skit0
    Feb 14 '12 at 13:27













  • Yes, edited, thx.

    – Ondra Žižka
    Feb 21 '12 at 4:33














5












5








5


3






What command can I use to get IPv6 address of an interface in a script?



Update: Output of sed from one of answers.



$ ip -6 addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
inet6 fe80::224:d7ff:fed0:4f5c/64 scope link
valid_lft forever preferred_lft forever


The other:



$ ip addr show dev eth0 | sed -e's/^.*inet6 ([^ ]*)/.*$/1/;t;d'
$ ip addr show dev eth0
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether f0:de:f1:7b:e9:6c brd ff:ff:ff:ff:ff:ff









share|improve this question
















What command can I use to get IPv6 address of an interface in a script?



Update: Output of sed from one of answers.



$ ip -6 addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
inet6 fe80::224:d7ff:fed0:4f5c/64 scope link
valid_lft forever preferred_lft forever


The other:



$ ip addr show dev eth0 | sed -e's/^.*inet6 ([^ ]*)/.*$/1/;t;d'
$ ip addr show dev eth0
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether f0:de:f1:7b:e9:6c brd ff:ff:ff:ff:ff:ff






linux bash ipv6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 10 '13 at 16:07









MoonSire

8161825




8161825










asked Feb 14 '12 at 13:13









Ondra ŽižkaOndra Žižka

3792721




3792721













  • Which IPv6 addresses? Your interfaces' IPv6 addresses?

    – m0skit0
    Feb 14 '12 at 13:27













  • Yes, edited, thx.

    – Ondra Žižka
    Feb 21 '12 at 4:33



















  • Which IPv6 addresses? Your interfaces' IPv6 addresses?

    – m0skit0
    Feb 14 '12 at 13:27













  • Yes, edited, thx.

    – Ondra Žižka
    Feb 21 '12 at 4:33

















Which IPv6 addresses? Your interfaces' IPv6 addresses?

– m0skit0
Feb 14 '12 at 13:27







Which IPv6 addresses? Your interfaces' IPv6 addresses?

– m0skit0
Feb 14 '12 at 13:27















Yes, edited, thx.

– Ondra Žižka
Feb 21 '12 at 4:33





Yes, edited, thx.

– Ondra Žižka
Feb 21 '12 at 4:33










3 Answers
3






active

oldest

votes


















9














You could use:



ip -6 addr


It will return all the IPv6 adresses you have configured.






share|improve this answer































    12














    There are lots of ways you could do this.



    Here is one:



    ip addr show dev eth0 | sed -e's/^.*inet6 ([^ ]*)/.*$/1/;t;d'


    It is similar to Robert's answer, except strips out the address only.






    share|improve this answer































      0














      In the brave new world of SystemD, interface naming conventions have changed drastically . So when provisioning a new host, you might not be able to predict what the interface is called which could break scripts hard-coding eth0 as the IF name.



      My solution shown below isn't interface name-centric: it will extract the IPv6 Global Unicast Address it finds, whatever the interface is called. The IF could be wired or wireless and my expression will work. Just set it as a variable in your script and Bob's your uncle:



      IPV6GLOBALUNICAST="$(ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1)"


      Just paste the following into the cli to validate it does what it says on the tin and "just works" before whacking it into your scripts:



      ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1


      I'm using this with great success and hasn't failed in any circumstances to date. HTH- Terrence Houlahan






      share|improve this answer

























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "3"
        };
        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: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        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
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f389766%2flinux-bash-how-to-get-interfaces-ipv6-address%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        9














        You could use:



        ip -6 addr


        It will return all the IPv6 adresses you have configured.






        share|improve this answer




























          9














          You could use:



          ip -6 addr


          It will return all the IPv6 adresses you have configured.






          share|improve this answer


























            9












            9








            9







            You could use:



            ip -6 addr


            It will return all the IPv6 adresses you have configured.






            share|improve this answer













            You could use:



            ip -6 addr


            It will return all the IPv6 adresses you have configured.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 14 '12 at 13:22









            RobertRobert

            7711411




            7711411

























                12














                There are lots of ways you could do this.



                Here is one:



                ip addr show dev eth0 | sed -e's/^.*inet6 ([^ ]*)/.*$/1/;t;d'


                It is similar to Robert's answer, except strips out the address only.






                share|improve this answer




























                  12














                  There are lots of ways you could do this.



                  Here is one:



                  ip addr show dev eth0 | sed -e's/^.*inet6 ([^ ]*)/.*$/1/;t;d'


                  It is similar to Robert's answer, except strips out the address only.






                  share|improve this answer


























                    12












                    12








                    12







                    There are lots of ways you could do this.



                    Here is one:



                    ip addr show dev eth0 | sed -e's/^.*inet6 ([^ ]*)/.*$/1/;t;d'


                    It is similar to Robert's answer, except strips out the address only.






                    share|improve this answer













                    There are lots of ways you could do this.



                    Here is one:



                    ip addr show dev eth0 | sed -e's/^.*inet6 ([^ ]*)/.*$/1/;t;d'


                    It is similar to Robert's answer, except strips out the address only.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 14 '12 at 13:25









                    PaulPaul

                    48.5k14122149




                    48.5k14122149























                        0














                        In the brave new world of SystemD, interface naming conventions have changed drastically . So when provisioning a new host, you might not be able to predict what the interface is called which could break scripts hard-coding eth0 as the IF name.



                        My solution shown below isn't interface name-centric: it will extract the IPv6 Global Unicast Address it finds, whatever the interface is called. The IF could be wired or wireless and my expression will work. Just set it as a variable in your script and Bob's your uncle:



                        IPV6GLOBALUNICAST="$(ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1)"


                        Just paste the following into the cli to validate it does what it says on the tin and "just works" before whacking it into your scripts:



                        ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1


                        I'm using this with great success and hasn't failed in any circumstances to date. HTH- Terrence Houlahan






                        share|improve this answer






























                          0














                          In the brave new world of SystemD, interface naming conventions have changed drastically . So when provisioning a new host, you might not be able to predict what the interface is called which could break scripts hard-coding eth0 as the IF name.



                          My solution shown below isn't interface name-centric: it will extract the IPv6 Global Unicast Address it finds, whatever the interface is called. The IF could be wired or wireless and my expression will work. Just set it as a variable in your script and Bob's your uncle:



                          IPV6GLOBALUNICAST="$(ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1)"


                          Just paste the following into the cli to validate it does what it says on the tin and "just works" before whacking it into your scripts:



                          ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1


                          I'm using this with great success and hasn't failed in any circumstances to date. HTH- Terrence Houlahan






                          share|improve this answer




























                            0












                            0








                            0







                            In the brave new world of SystemD, interface naming conventions have changed drastically . So when provisioning a new host, you might not be able to predict what the interface is called which could break scripts hard-coding eth0 as the IF name.



                            My solution shown below isn't interface name-centric: it will extract the IPv6 Global Unicast Address it finds, whatever the interface is called. The IF could be wired or wireless and my expression will work. Just set it as a variable in your script and Bob's your uncle:



                            IPV6GLOBALUNICAST="$(ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1)"


                            Just paste the following into the cli to validate it does what it says on the tin and "just works" before whacking it into your scripts:



                            ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1


                            I'm using this with great success and hasn't failed in any circumstances to date. HTH- Terrence Houlahan






                            share|improve this answer















                            In the brave new world of SystemD, interface naming conventions have changed drastically . So when provisioning a new host, you might not be able to predict what the interface is called which could break scripts hard-coding eth0 as the IF name.



                            My solution shown below isn't interface name-centric: it will extract the IPv6 Global Unicast Address it finds, whatever the interface is called. The IF could be wired or wireless and my expression will work. Just set it as a variable in your script and Bob's your uncle:



                            IPV6GLOBALUNICAST="$(ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1)"


                            Just paste the following into the cli to validate it does what it says on the tin and "just works" before whacking it into your scripts:



                            ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1


                            I'm using this with great success and hasn't failed in any circumstances to date. HTH- Terrence Houlahan







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Feb 7 at 9:38

























                            answered Feb 7 at 9:07









                            F1LinuxF1Linux

                            1114




                            1114






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Super User!


                                • 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.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f389766%2flinux-bash-how-to-get-interfaces-ipv6-address%23new-answer', 'question_page');
                                }
                                );

                                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







                                Popular posts from this blog

                                How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                                is 'sed' thread safe

                                How to make a Squid Proxy server?