Skip to content

Instantly share code, notes, and snippets.

@khalidx
Created March 1, 2017 17:37
Show Gist options
  • Save khalidx/9e945e6b5fb6aac3b7dc7ffa75144cc2 to your computer and use it in GitHub Desktop.
Save khalidx/9e945e6b5fb6aac3b7dc7ffa75144cc2 to your computer and use it in GitHub Desktop.
Ubuntu: Get only the IP address of a network interface
#!/bin/bash
# Syntax: ifconfig <interface-name> | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1
# Example: Get the IP address of the eth0 network interface
ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment