Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #256276
| From | Gregory Seidman <gsslist+debian@anthropohedron.net> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: what's the right way to resolve localhost's IPs |
| Date | 2023-03-22 21:40 +0100 |
| Message-ID | <Gcdpv-emR7-3@gated-at.bofh.it> (permalink) |
| References | <GbViV-ebLW-5@gated-at.bofh.it> <GbW5j-ech4-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Wed, Mar 22, 2023 at 10:06:40AM +0800, Jeremy Ardley wrote:
>
> On 22/3/23 09:12, fh@dnsbed.com wrote:
> > Hello,
> >
> > In my shell script, how to get the localhost's IPs (eth0 and eth1)
> > correctly?
> > I know I can run 'ifconfig' and grep etc, but it's maybe not that
> > graceful.
>
> On Debian the preferredĀ command is
>
> root@debian12:~# ip a
[...]
> You can also output in .json format
>
> root@debian12:~# ip -j a
[...]
>
> and if you write a script like this (and make it write protected and
> executable)
[...]
For those of us who like using jq for this kind of thing:
#!/bin/sh
ip -j a | jq -r '
.[] | {
"name": .ifname,
"addr": .addr_info |
map(select(.family == "inet")) |
.[0].local
} |
select(.addr) |
.name + ": " + .addr'
> you can do
>
> ip -j a | ./ipv4_addresses.py
> lo: 127.0.0.1
> enp7s0: 10.31.40.68
>
> or on a fancier setup
>
> ip -j a | ./ipv4_addresses.py
> lo: 127.0.0.1
> eth0: 10.31.40.4
> eth0: 10.31.40.5
> eth0: 10.31.40.101
> docker0: 172.17.0.1
>
> > --
>
> Jeremy
> (Lists)
--Gregory
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
what's the right way to resolve localhost's IPs fh@dnsbed.com - 2023-03-22 02:20 +0100
Re: what's the right way to resolve localhost's IPs Jeremy Ardley <jeremy@ardley.org> - 2023-03-22 03:10 +0100
Re: what's the right way to resolve localhost's IPs fh@dnsbed.com - 2023-03-22 03:40 +0100
Re: what's the right way to resolve localhost's IPs Gregory Seidman <gsslist+debian@anthropohedron.net> - 2023-03-22 21:40 +0100
Re: what's the right way to resolve localhost's IPs Tom Furie <tom@furie.org.uk> - 2023-03-22 22:20 +0100
Re: what's the right way to resolve localhost's IPs Greg Wooledge <greg@wooledge.org> - 2023-03-22 22:50 +0100
Re: what's the right way to resolve localhost's IPs Jeremy Ardley <jeremy@ardley.org> - 2023-03-23 00:10 +0100
Re: what's the right way to resolve localhost's IPs Greg Wooledge <greg@wooledge.org> - 2023-03-23 00:40 +0100
Re: what's the right way to resolve localhost's IPs Jeremy Ardley <jeremy@ardley.org> - 2023-03-23 01:00 +0100
Re: what's the right way to resolve localhost's IPs Nicolas George <george@nsup.org> - 2023-03-23 08:50 +0100
Re: what's the right way to resolve localhost's IPs Jeremy Ardley <jeremy@ardley.org> - 2023-03-23 09:00 +0100
Re: what's the right way to resolve localhost's IPs Lee <ler762@gmail.com> - 2023-03-23 12:00 +0100
Re: what's the right way to resolve localhost's IPs Emanuel Berg <incal@dataswamp.org> - 2023-03-30 07:50 +0200
Re: what's the right way to resolve localhost's IPs fh@dnsbed.com - 2023-03-30 10:10 +0200
csiph-web