V
V
vldanch2019-07-19 10:20:55
linux
vldanch, 2019-07-19 10:20:55

How can you determine which interface has received an ip address in linux?

It is necessary to drive into the variable the interface that received the ip address by default.
How to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgen, 2019-07-19
@etaliorum

ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'

There are even more ways (click)

P
pfg21, 2019-07-19
@pfg21

get data about assigned ip for available interfaces.
for example, ifconfig, ip address, depending on which ip-tools you have enabled in the operating system.

ifconfig
$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.0.16  netmask 255.255.255.0  broadcast 10.0.0.255
        inet6 fe80::88:888:8888:8888  prefixlen 64  scopeid 0x20<link>
        inet6 fd16:8888:8888::8888  prefixlen 128  scopeid 0x0<global>
        inet6 fd16:8888:8888:0:8888:8888:8888:8888  prefixlen 64  scopeid 0x0<global>
        ether 00:88:88:88:88:88  txqueuelen 1000  (Ethernet)
        RX packets 16593458  bytes 1762450276 (1.7 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2821823  bytes 450737366 (450.7 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Локальная петля (Loopback))
        RX packets 7147199  bytes 357521334 (357.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7147199  bytes 357521334 (357.5 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ip address
$ ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:88:88:88:88:88 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.16/24 brd 10.0.0.255 scope global dynamic eth0
       valid_lft 15167sec preferred_lft 15167sec
    inet6 fd16:8888:8888::8888/128 scope global noprefixroute
       valid_lft forever preferred_lft forever
    inet6 fd16:8888:8888:0:8888:8888:8888:8888/64 scope global mngtmpaddr noprefixroute
       valid_lft forever preferred_lft forever
    inet6 fe80::88:8888:8888:8888/64 scope link
       valid_lft forever preferred_lft forever

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question