Get interface IP address from terminal
Posted: | Updated: | Tags: linux til networkingGrabbing just an IP address from a network interface can be useful for scripting. In the example below the assumed interface is eth0
.
ip a show eth0 | grep "inet " | cut -d' ' -f6 | cut -d/ -f1
You can then save this into a variable and use it in other commands.
local_ip=$(ip a show eth0 | grep "inet " | cut -d' ' -f6 | cut -d/ -f1)
python3 -m http.server 8000 --bind $local_ip
hugo server --bind $local_ip --baseURL=http://$local_ip