Linux/bash: How to get interface's IPv6 address?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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 |
The other approaches mentioned here WILL FAIL if the IF is not named eth0
. And in the world of SystemD, IF names are far from predictable as IF naming conventions have changed drastically
My approach instead finds & extracts the Global Unicast Address- whatever the IF might be named. The IPv6 address could be configured for wlan0
- or any other name- and my bash snippet will successfully extract and expand it as a variable in a config file requiring the listening address to be specified.
IPV6GLOBALUNICAST="$(ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1)"
Paste below onto the CLI of a host with an IPv6 address configured to test it:
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
7911512
7911512
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.7k14122150
48.7k14122150
add a comment |
add a comment |
The other approaches mentioned here WILL FAIL if the IF is not named eth0
. And in the world of SystemD, IF names are far from predictable as IF naming conventions have changed drastically
My approach instead finds & extracts the Global Unicast Address- whatever the IF might be named. The IPv6 address could be configured for wlan0
- or any other name- and my bash snippet will successfully extract and expand it as a variable in a config file requiring the listening address to be specified.
IPV6GLOBALUNICAST="$(ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1)"
Paste below onto the CLI of a host with an IPv6 address configured to test it:
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 |
The other approaches mentioned here WILL FAIL if the IF is not named eth0
. And in the world of SystemD, IF names are far from predictable as IF naming conventions have changed drastically
My approach instead finds & extracts the Global Unicast Address- whatever the IF might be named. The IPv6 address could be configured for wlan0
- or any other name- and my bash snippet will successfully extract and expand it as a variable in a config file requiring the listening address to be specified.
IPV6GLOBALUNICAST="$(ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1)"
Paste below onto the CLI of a host with an IPv6 address configured to test it:
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 |
The other approaches mentioned here WILL FAIL if the IF is not named eth0
. And in the world of SystemD, IF names are far from predictable as IF naming conventions have changed drastically
My approach instead finds & extracts the Global Unicast Address- whatever the IF might be named. The IPv6 address could be configured for wlan0
- or any other name- and my bash snippet will successfully extract and expand it as a variable in a config file requiring the listening address to be specified.
IPV6GLOBALUNICAST="$(ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1)"
Paste below onto the CLI of a host with an IPv6 address configured to test it:
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
The other approaches mentioned here WILL FAIL if the IF is not named eth0
. And in the world of SystemD, IF names are far from predictable as IF naming conventions have changed drastically
My approach instead finds & extracts the Global Unicast Address- whatever the IF might be named. The IPv6 address could be configured for wlan0
- or any other name- and my bash snippet will successfully extract and expand it as a variable in a config file requiring the listening address to be specified.
IPV6GLOBALUNICAST="$(ip -6 addr|awk '{print $2}'|grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'|cut -d '/' -f1)"
Paste below onto the CLI of a host with an IPv6 address configured to test it:
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 yesterday
answered Feb 7 at 9:07
F1LinuxF1Linux
1215
1215
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