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 icanhazip.com

This will return just your IP address.

This is another way to get this information.

[email protected]:~/Documents$ curl ipinfo.io/ip

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

jason@jason-desktop:~/Documents/ipinfo/src$ dig 8.8.8.8
 
; <<>> DiG 9.10.3-P4-Ubuntu <<>> 8.8.8.8
;; 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
 
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1280
;; QUESTION SECTION:
;8.8.8.8.                       IN      A
 
;; ANSWER SECTION:
8.8.8.8.                0       IN      A       8.8.8.8
 
;; Query time: 0 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; 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
0.0.0.0         172.31.16.1     0.0.0.0         UG        0 0          0 eth0
10.8.0.0        10.8.0.2        255.255.255.0   UG        0 0          0 tun1194
10.8.0.2        0.0.0.0         255.255.255.255 UH        0 0          0 tun1194
172.31.16.0     0.0.0.0         255.255.240.0   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 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
    inet 172.31.20.16/20 brd 172.31.31.255 scope global eth0
    inet6 fe80::4d6:3aff:fea8:8213/64 scope link
    inet 10.8.0.1 peer 10.8.0.2/32 scope global tun1194

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

Leave a Reply