3

Using one or two command line, how do we know a particular network interface (e.g eth0) is connecting using dhcp or static ip?

can we do this using similar commands like sudo cat?

  • 1
    cat /etc/network/interfaces should list that out. If entry for your interface is something like iface eth0 inet dhcp where eth0 is interface, it could wlan0 for wifi or any other interface. For static, it should read out iface eth0 inet static. – dhruvvyas90 Nov 19 '15 at 10:19
  • 1
    @dastaan mine is iface eth0 inet manual , what does manual means? same as static? I am looking for a script based solution to determine the Pi's networking methods (in this case, first find out if is dhcp or static ) – Dennis Nov 19 '15 at 10:23
  • 2
    Go through this answer on the unix SE. Link : unix.stackexchange.com/questions/128439/… Each option in interfaces file is explained in great detail. Hope it helps. – dhruvvyas90 Nov 19 '15 at 10:26
  • Does it work? If it does why do you care. The link @dastaan posted is probably irrelevant if you are using a recent image. What version? If you want help post /etc/network/interfaces in full as well as version. – Milliways Nov 19 '15 at 11:25
  • @Milliways You might be true as this might not apply to newer jessie images. – dhruvvyas90 Nov 19 '15 at 11:56
1

Examine processor status for a process by the name dhclient. Usually its pid will be listed under /run/dhclient..pid.

This process will not be run on statically configured addressed interfaces

Example: On a DHCP addressed eth0 RPi.

root 1711 1 0 07:58 ? 00:00:00 dhclient -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases eth0

root@homerpi:/# ls -l /run/dhclient.eth0.pid -rw-r--r-- 1 root root 5 Nov 19 07:58 /run/dhclient.eth0.pid

Or as suggested earlier, examine the /etc/network/interfaces for its ip address assignment mode

You could try /usr/bin/awk '/eth0/' /etc/network/interfaces

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.