Bash ip addresses
		
		
		
		Jump to navigation
		Jump to search
		
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