How to find out if Ubuntu is using DHCP (Ubuntu 12.04 LTS GUI)

86,720

Solution 1

Right click on the Network Manager icon on Ubuntu top panel and select edit. Go to Wired Network or Wireless Network tab and select the network name. Click on the edit button and go to IPv4 settings tab on the new window. If the method is Automatic (DHCP) you are using dhcp.

Other method is cat /var/log/syslog and check for some thing like below

DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 6
DHCPOFFER from 10.100.1.254
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 10.100.1.254

If you have some thing similar to above. You are using DHCP (IP addresses could be different)

Solution 2

I'm using debian but directories should be the same or similar. Check if you have the directory /var/lib/dhcp. Then:

ls -lrt /var/lib/dhcp/

You should see files named /var/lib/dhcp/dhclient-random-numbers-eth1.lease. Look for the most recent file associated with the interface you're interested in and open it up:

cat /var/lib/dhcp/dhclient-...-eth1.lease

The output should be something like this:

lease {
  interface "eth1";
  fixed-address 192.168.10.12;
  rebind 4 2012/08/02 03:56:17;
  expire 4 2012/08/02 04:41:17;
}

If /var/lib/dhcp directory doesn't exist or if it is empty, you're most likely not getting your IPs from DHCP.

Solution 3

A pedantic note on an old post: the contents of /etc/network/interfaces will tell you how the interfaces MAY have been managed at boot (or after running service networking restart). It is not definitive. It does not tell you how a given interface was assigned at any given moment. For example, given a DHCP managed interface I can easily kill dhclient and use ifconfig to statically assign any IP I want to an interface (I can assign an IP address in the HCHP managed range just to cause more confusion).

Maybe another admin did this to test something and forgot to clean up. Or I can run dhclient eth0 on an interface with a static assignment now DHCP will manage the interface. Or another admin maybe have made a typo and now avahi has dynamically configured the interface with a link-local address.

Sure, these things don't happen every day, but it's only under development conditions or in weird situations where I have ever asked myself, "Just how did this interface get configured?" Under normal circumstances I never find myself asking this question.

In general, I believe the answer is "No, you can't know for sure." The kernel does not maintain a record, as far as know. The best you can do is to grep through the usual suspects in /var/log/. But if someone came in an manually assigned a static IP address then you're out of luck.

Solution 4

Use command:

cat /etc/network/interfaces

It will show you all interfaces and which one of them are using dhcp.

Whether dhcp is fixed or dynamic you must check on your Virtual Machine configuration. If you are using VM Ware then under edit you got Virtual Networking properties. There you will be able to check if for particular virtual interface you got dhcp reservations for specific machines. If you did not checked it yet then we can assume you did not changed default configuration which is dynamic. You can setup reservation if you wish.

Details of NAT configuration in VM Ware environment: click.

If bridged connection:

f you use bridged networking, your virtual machine needs to have its own identity on the network. For example, on a TCP/IP network, the virtual machine needs its own IP address. Your network administrator can tell you whether IP addresses are available for your virtual machine and what networking settings you should use in the guest operating system. Generally, your guest operating system may acquire an IP address and other network details automatically from a DHCP server, or you may need to set the IP address and other details manually in the guest operating system.

If you use bridged networking, the virtual machine is a full participant in the network. It has access to other machines on the network and can be contacted by other machines on the network as if it were a physical computer on the network.


Be aware that if the host computer is set up to boot multiple operating systems and you run one or more of them in virtual machines, you need to configure each operating system with a unique network address. People who boot multiple operating systems often assign all systems the same address, since they assume only one operating system will be running at a time. If you use one or more of the operating systems in a virtual machine, this assumption is no longer true.

Share:
86,720

Related videos on Youtube

Kevdog777
Author by

Kevdog777

If I told you about me, then I wouldn't be so mysterious!

Updated on September 18, 2022

Comments

  • Kevdog777
    Kevdog777 over 1 year

    How can I find out if my IP address is DHCP, Fixed or Dynamic?

    I need to tell my network administrator what the IP address is, that my Virtual Machine is using. I know the numbers, but I don't know if it is fixed or not.

    I have tried: ifconfig and that returned my IP address.

    • Warren Young
      Warren Young over 11 years
      A network administrator should know from the raw IP address whether it's dynamic or static. (Or at least, be able to guess with high certainty.) DHCP should always be using a dedicated pool of addresses, and static IP'd machines must never use an address in that pool, else they risk an IP collision. If you need a static address within the DHCP pool, many DHCP servers offer a way to assign a fixed value based on DHCP client ID or MAC address, but that's still DHCP.
    • Kevdog777
      Kevdog777 over 11 years
      Thank you @WarrenYoung, but the network admin has a full list of all the IP addresses I have used, so there won't be any collisions.
  • hayath786
    hayath786 over 11 years
    That probably won't work on Ubuntu which usually uses NetworkManager and not /etc/network/interfaces.
  • mnmnc
    mnmnc over 11 years
    I use Backtrack which is based on Ubuntu. If the path is different it will probably be very similar.
  • Kevdog777
    Kevdog777 over 11 years
    Yeah that didn't work, it says (with and without using sudo): auto lo iface lo inet loopback - unless it has worked, but I don't understand what was just written there.
  • mnmnc
    mnmnc over 11 years
    It did work. You do not have an IP address for eth0. Check in Virtual Machine configuration what type of network did you choose upon Virtual Machine creation. You might have selected option "host only" but you should have used 'NAT'.
  • mnmnc
    mnmnc over 11 years
    Go in here for NAT configuration in VM Ware: vmware.com/support/ws55/doc/ws_net_configurations_changing.h‌​tml
  • Kevdog777
    Kevdog777 over 11 years
    I chose bridged as I normally do with all the other machines I have created.
  • mnmnc
    mnmnc over 11 years
    If you have used bridged than you got Internet Access on your Virtual Machine but not on the Host Machine. Use arp command to see if you see the IP address of your router or your ISP ip address.
  • mnmnc
    mnmnc over 11 years
    Are you using multiple VM's concurrently ? All with Bridged network? Please see my updated answer.
  • Kevdog777
    Kevdog777 over 11 years
    Ahh, I see. It is DHCP. Thank you for your help.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 11 years
    /etc/network/interfaces is the “manual” way of configuring network interfaces. Backtrack is a distribution for playing with network configurations, so it unsurprisingly favors the manual way. Ubuntu is a distribution intended to be configured automatically by preference and through the GUI when necessary, so it unsurprisingly favors Network Manager.
  • Kevdog777
    Kevdog777 over 11 years
    Thank you for your answer, but as I am using the User Interface, I got it sorted. But thanks again.
  • amin
    amin almost 11 years
    @Gilles Of course there are numerous server installations of Ubuntu which, as far as I know, will use this 'manual' non-GUI method.
  • Kevdog777
    Kevdog777 almost 9 years
    This is a very long-winded answer - and only the real part in this "answer" is the last paragraph.