ArticleDirectory
- 1.1 get Single IP Address by Interface
- 1.2 get every interfaces IP Address
- 2.1 get external IP address using lynx
- 2.2 get external IP address using curl
Original
1. Get internal IP address (es) on Linux Shell/command line1.1 get Single IP Address by Interface
Returns plain IP address.
/Sbin/Ifconfig $1 | Grep "Inet ADDR" | Awk-F:'{Print $2 }' | Awk '{Print $1 }' # Example usage ##/Sbin/IfconfigEth0| Grep "Inet ADDR" | Awk-F:'{Print $2 }' | Awk '{Print $1 }'10.20.10.1 |
Create simple bash function (exampleINT-IP) With following command.
FunctionINT-IP{ /Sbin/Ifconfig $1 | Grep "Inet ADDR" | Awk-F:'{Print $2 }' | Awk '{Print $1 }';} # Example usage ##INT-IP eth010.20.10.1 |
1.2 get every interfaces IP Address
Returns every interface and IP address pairs.
/Sbin/Ifconfig |Grep -B1 "Inet ADDR" |Awk '{If ($1 = "Inet") {print $2} else if ($2 = "Link") {printf "% s :", $1 }}' |Awk-F:'{Print $1 ":" $3 }' # Example output ##Eth0: 10.20.10.1eth1: 10.20.1.168lo: 127.0.0.1 |
Create simple bash function (exampleINT-IPS) With following command.
FunctionINT-IPS{ /Sbin/Ifconfig |Grep -B1 "Inet ADDR" |Awk '{If ($1 = "Inet") {print $2} else if ($2 = "Link") {printf "% s :", $1 }}' |Awk-F:'{Print $1 ":" $3 }';} # Example usage ##Int-ipseth0: 10.20.10.1eth1: 10.20.1.168lo: 127.0.0.1 |
2. Get external IP address on Linux Shell/command line
I use here whatismyip.org service.
2.1 get external IP address using lynx
Returns plain IP address.
Lynx -- dump http://ipecho.net/plain # example output #80.10.10.80 |
Verified
Create simple bash function (exampleEXT-IP) With following command.
FunctionEXT-IP() { Lynx -- DumpHTTP://Ipecho.net/Plain;} # Example usage ##Ext-ip80.10.10.80 |
2.2 get external IP address using curl
Returns plain IP address.
Curl http://Ipecho.net/Plain;Echo # Example output ##80.10.10.80 |
Create simple bash function (exampleEXT-IP) With following command.
FunctionEXT-IP() {Curl http://Ipecho.net/Plain;Echo;} # Example usage ##Ext-ip80.10.10.80 |