Can I run a DHCP server on an ubuntu VM under vmware and serve the host?

Maybe this will not be as clear as you would like it, but in short this is it:

  1. The VM must have a bridged network card, so that it can contact the outside world. In VMWare you can set this before you start the machine.
  2. (I usually set the servers network card to a fixed address).
  3. Follow the documentation here to set up the dhcp server. Or you can use dnsmasq, which is a bit easier.
  4. Windows 7 will automatically get the address, if everything is ok with ubuntu.

But may I ask that why do you want a configuration like this?


  1. start your VM with network setting Bridge Network Card
  2. start ubuntu server and install the DHCP server

    sudo apt-get install dhcp3-server or isc-dhcp-server
    
  3. Configure it:

    sudo nano /etc/dhcp/dhcpd.conf
    

    add the following lines

    subnet 192.168.1.0 
    netmask 255.255.255.0
    
    { range 192.168.1.150 192.168.1.200; 
    option routers 192.168.1.254;
    option domain-name-servers 192.168.1.1, 192.168.1.2;
    default-lease-time 600; max-lease-time 7200;
    }
    

    Then run

    sudo service isc-dhcp-server restart
    

    you are done

In case you are getting errors that it cannot start, proceed with the following steps:

  1. restart your Ethernet card

    sudo ifdown ethx  
    

    it shut down your Ethernet, x means 0,1,2... use ifconfig for this

  2. now restart your Ethernet

    sudo ifup ethx  
    
  3. restart your network manager

    sudo service network-manager stop
    
    sudo service network-manager start
    
    sudo service isc-dhcp-server restart 
    

    (restart may give you error because your dhcp server is not already running you can try start)

  4. one reason behind this is IPV6 so disable it

    sudo nano /etc/sysctl.conf
    

    add the following lines to file

    # # IPv6    
    net.ipv6.conf.all.disable_ipv6 = 1
    net.ipv6.conf.default.disable_ipv6 = 1
    net.ipv6.conf.lo.disable_ipv6 = 1
    
  5. Enter following command to restart sysctl settings:

    sudo sysctl -p
    

Important note

Disable DHCP of your router because ubuntu use DHCP of your router by default or some router having DHCP enable has ability to disable the DHCP server machine. I don't know why.

if you want to give static ip to your linux machine then do the following but it depends

Edit the interfaces file:

sudo nano /etc/network/interfaces

add the following lines for example

auto eth0
iface eth0 inet static
        address 192.168.1.100
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1