Bash script to get all IP addresses

后端 未结 12 2419
-上瘾入骨i
-上瘾入骨i 2020-12-28 22:51

I am trying to write a bash script to get all IP addresses on a server. The script should work on all major distros. Here is what I have:

ifconf         


        
12条回答
  •  滥情空心
    2020-12-28 23:20

    Simply using hostname you can get a list of all your IP addresses, using the -I flag.

    i.e.

    $ hostname --all-ip-addresses || hostname -I
    10.10.85.100 10.20.85.100 10.30.85.100
    

    whereas

    $ hostname --ip-address || hostname -i
    ::1%1 127.0.0.1
    

    Centos7 (k3.10.0)

提交回复
热议问题