Linux/bash: How to get interface's IPv6 address?
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
add a comment |
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
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
add a comment |
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
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
linux bash ipv6
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
You could use:
ip -6 addr
It will return all the IPv6 adresses you have configured.
add a comment |
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.
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
You could use:
ip -6 addr
It will return all the IPv6 adresses you have configured.
add a comment |
You could use:
ip -6 addr
It will return all the IPv6 adresses you have configured.
add a comment |
You could use:
ip -6 addr
It will return all the IPv6 adresses you have configured.
You could use:
ip -6 addr
It will return all the IPv6 adresses you have configured.
answered Feb 14 '12 at 13:22
RobertRobert
7711411
7711411
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Feb 14 '12 at 13:25
PaulPaul
48.5k14122149
48.5k14122149
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Feb 7 at 9:38
answered Feb 7 at 9:07
F1LinuxF1Linux
1114
1114
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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