ip (program)

ip is the new networking program starting from Debian Stretch replacing the old ifconfig and iptables. It is relatively new but it is worth learning since it is quite robust and rich in features too.

Get Help and Menu

To get the menu or help, simply just call the program:

$ ip
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
       ip [ -force ] -batch filename
where  OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
                   tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
                   netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila }
       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
                    -h[uman-readable] | -iec |
                    -f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |
                    -4 | -6 | -I | -D | -B | -0 |
                    -l[oops] { maximum-addr-flush-attempts } | -br[ief] |
                    -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
                    -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}

It is quite easy to read:

  1. You construct the option you need. They are usually short form (e.g. -V for version).
  2. Then you select the object (or action) you want.

Show Network Interfaces Details

Since ifconfig was replaced, you can use ip to list all address. To do that, simply use:

$ ip address
...

You will get all the necessary network data from interface to specifically connected IP address.

Read Interface IP Address Ranges

To get IP Address ranges from an network interface, you simply use the following command:

$ ip -o addr show <interface> | awk '{print $4}'

Example, for eth0 network interface, it is:

$ ip -o addr show eth0 | awk '{print $4}'
192.168.155.1/24
XXXX::XXXX:XXXX:XXXX:XXXX/64

The first one would be IPv4 format while the second one would be IPv6 format.

Get Public IP Address

To get your public address, simply use curl or wget against ifconfig.me:

$ curl ifconfig.me
<IP ADDRESS>

If you have only wget, then:

$ wget -qO- ifconfig.me
<IP ADDRESS>

That's all about ip program.