How to get just the IP address of your Linux machine using curl.

To get just the IP address of your Internet facing Linux machine, use this command.

[email protected]:~/Documents/ipinfo/src$ curl

This will return just your IP address.

This is another way to get this information.

[email protected]:~/Documents$ curl

To get information about a DNS server, use the dig command.

jason@jason-desktop:~/Documents/ipinfo/src$ dig
; <<>> DiG 9.10.3-P4-Ubuntu <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44317
;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
; EDNS: version: 0, flags:; udp: 1280
;                       IN      A
;; ANSWER SECTION:                0       IN      A
;; Query time: 0 msec
;; WHEN: Tue May 10 09:52:37 AEST 2016
;; MSG SIZE  rcvd: 52

To get the gateway IP address of a Linux machine, this command will suffice.

ubuntu /etc/openvpn $ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface         UG        0 0          0 eth0   UG        0 0          0 tun1194 UH        0 0          0 tun1194   U         0 0          0 eth0

List all of the IP addresses on your machine with this command.

ubuntu /etc/openvpn $ ip addr | grep inet
    inet scope host lo
    inet6 ::1/128 scope host
    inet brd scope global eth0
    inet6 fe80::4d6:3aff:fea8:8213/64 scope link
    inet peer scope global tun1194

No comments have been made. Use this form to start the conversation :)

Leave a Reply