Obsolete tools: nslookup & ifconfig

nslookup and ifconfig are two well-known tools for configuration the network of Unix/Linux hosts and checking whether DNS is working properly.

ifconfig was part of the 4.2BSD distribution in 1983 for the first time and quickly became the standard tool for network configuration - even commerical Unices like Solaris or HP-UX integrated the utility.

Some Linux distributions don't use ifconfig anymore (e.g. ArchLinux) - other distributions (e.g. SuSE/SLES and Fedora) are advising that this tool will be missing someday:

1# man ifconfig
2...
3       WARNING: Ifconfig is obsolete on system with Linux  kernel  newer  than
4       2.0. On  this  system  you  should  use ip. See the ip manual page for
5       details
6...
7NOTE
8       This program is obsolete! For replacement check ip addr and ip link.
9       For statistics use ip -s link.

Solaris 11 introduced a new command for network configuration: ipadm (thanks for the hint, Prometheus!).

ip works beginning with Linux 2.2. It is more modern and also includes amongst others the functionality of the route and arp utilities.

Here are some of the most used ifconfig/route commands and their ip pendants:

Taskifconfig/routeip
Show all NICs
ifconfig
ip addr show
Show specific NIC
ifconfig eth0
ip addr show eth0
Disable NIC
ifconfig eth0 down
ip link set eth0 down
Enable NIC
ifconfig eth0 up
ip link set eth0 up
Assign IP
ifconfig eth0 [IP] netmask [NM]
ip addr [IP]/[CIDR] dev eth0
Show routing table
route
netstat -r
ip route
Set standard route
route add default gw [IP] eth0
ip route add default via [IP]

Of course ip has a lot of more features - just a few of them:

  • Enable/disable MTU and Promiscuous Mode
  • Configure Multicasting and VLANs
  • ARP table maintenance

Similar to ifconfig - nslookup is also obsolete for a long time. There are two replacement tools that are able to do more: host and dig. The open DNS server bind advises not to use nslookup (source):

Due to its arcane user interface and frequently inconsistent behavior, we do not recommend the use of nslookup. Use dig instead.

Here are some commonly used nslookup commands and their dig pendants.

Tasknslookupdig
Forward lookup
nslookup google.de
dig google.de
dig +short google.de
Reverse lookup
nslookup [IP]
dig -x [IP]
dig +short -x [IP]
Use specific DNS server
nslookup google.de [DNS]
dig @[DNS] google.de
dig @[DNS] +short google.de
Ask for MX records
nslookup -query=mx google.de
dig google.de MX
dig +short google.de MX
Specific timeout
nslookup -timeout=42 google.de
dig google.de +time=42
dig +short google.de +time=42

The option +short ist really useful if you just want to get a IP or a hostname. By default, dig also prints some additional information like the IP and response time of the used DNS sever:

 1; <<>> DiG 9.9.2-P2 <<>> google.de
 2;; global options: +cmd
 3;; Got answer:
 4;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33883
 5;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
 6
 7;; OPT PSEUDOSECTION:
 8; EDNS: version: 0, flags:; udp: 16384
 9;; QUESTION SECTION:
10;google.de.                     IN      A
11
12;; ANSWER SECTION:
13google.de.              300     IN      A       173.194.44.56
14google.de.              300     IN      A       173.194.44.55
15google.de.              300     IN      A       173.194.44.63
16
17;; Query time: 66 msec
18;; SERVER: 208.67.222.222#53(208.67.222.222)
19;; WHEN: Sun Apr  7 17:18:22 2013
20;; MSG SIZE  rcvd: 86
21
22# dig +short google.de
23173.194.44.55
24173.194.44.56
25173.194.44.63

It's also a good idea to have a look at the manpage of dig because it offers a lot of additional features in addition to the mentioned functions. 🙂

Translations: