Bash ip addresses: Difference between revisions

From I Will Fear No Evil
Jump to navigation Jump to search
(Created page with "==Interesting bash commands working with IP Addresses== =Get routable IP address= So far this seems both the simplest and most straightforward way to reliably get our IP address.. <pre> chubbard@kvm03:~$ ip route get 1.2.3.4 | awk '{print $7}' 192.168.15.107 Details without awk: chubbard@kvm03:~$ ip route get 1.2.3.4 1.2.3.4 via 192.168.15.1 dev enp2s0f0 src 192.168.15.107 uid 1000 cache </pre> Category:Bash")
 
 
Line 12: Line 12:
     cache  
     cache  
</pre>
</pre>
 
=Alternate messier way=
<pre>
ip a |grep inet | awk '{print $2}' | grep '^[1-9]'
127.0.0.1/8
192.168.15.107/24
192.168.15.108/24
192.168.122.1/24
</pre>






[[Category:Bash]]
[[Category:Bash]]

Latest revision as of 10:32, 6 February 2024

Interesting bash commands working with IP Addresses

Get routable IP address

So far this seems both the simplest and most straightforward way to reliably get our IP address..

chubbard@kvm03:~$ ip route get 1.2.3.4 | awk '{print $7}'
192.168.15.107

Details without awk:
chubbard@kvm03:~$ ip route get 1.2.3.4 
1.2.3.4 via 192.168.15.1 dev enp2s0f0 src 192.168.15.107 uid 1000 
    cache 

Alternate messier way

ip a |grep inet | awk '{print $2}' | grep '^[1-9]'
127.0.0.1/8
192.168.15.107/24
192.168.15.108/24
192.168.122.1/24