How To Configure DHCP on OpenWRT router

First uninstall pre-installed dnsmasq:

/etc/init.d/dnsmasq stop
opkg remove dnsmasq

Then install the ISC DHCP server app:

opkg install http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/oldpackages/isc-dhcp-server-ipv4_4.2.4-3_ar71xx.ipk

dhcp_install

Once that is done run:

nano /etc/dhcpd.conf

and replace the content with this:

# Show that we want to be the only DHCP server in this network:
authoritative;

option domain-name "myHome.com";
option domain-name-servers 192.168.0.1, 192.168.0.2;
#DHCP Scope:
subnet 192.168.0.0 netmask 255.255.255.0 {
#DHCP range
range 192.168.0.100 192.168.0.130;
#default gateway
option routers 192.168.0.1;
}

default-lease-time 691200; # 8 days
max-lease-time 864000; # 10 days

# Static assignments
host PC1 {
hardware ethernet 00:11:22:33:44:55;
fixed-address 192.168.0.10;
}

host PC2 {
hardware ethernet 00:88:77:77:66:66;
fixed-address 192.168.0.11;
}

Save the file and start the service

/etc/init.d/dhcpd start

To see dhcpd leases run:

more /var/dhcpd.leases

# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.2.4

lease 192.168.1.100 {
  starts 4 2015/03/05 17:57:24;
  ends 4 2015/03/05 17:59:24;
  tstp 4 2015/03/05 17:59:24;
  cltt 4 2015/03/05 17:57:24;
  binding state free;
  hardware ethernet 11:22:33:55:44:33;
  client-hostname "Windows7-PC";
}
lease 192.168.1.102 {
  starts 4 2015/03/05 18:19:06;
  ends 4 2015/03/05 18:21:06;
  tstp 4 2015/03/05 18:21:06;
  cltt 4 2015/03/05 18:19:06;
  binding state free;
  hardware ethernet 11:33:55:ee:ff:55;
  client-hostname "mobile-phone";
}

Job done. To install DNS follow here.

How to deploy proxy settings via DHCP

1. Install IIS and make some config changes:

  1. In IIS Manager, right-click the website or website directory for which you want to add a MIME type, and click Properties.
  2. Click the HTTP Headers tab.
  3. Click Mime Types.
  4. Click New.
  5. In the Extension box, enter the file name extension: .pac
  6. In the MIME type box, enter the MIME type description: application/x-ns-proxy-autoconfig
  7. Click OK and then restart the IIS service.
  8. then go to c:inetpubwwroot and create proxy folder

 2. create wpad.PAC file and copy it to the created proxy folder

example pac file:

function FindProxyForURL(url, host)
{

        // Add hostname exceptions for sites you do not want to
        // proxy e.g. internal servers

        if(shExpMatch(url,”*.google.com/*”)) { return “DIRECT”; }

        // if(shExpMatch(url,”*.bypassthis.com:*/*”)) { return “DIRECT”; }
        // End hostname exceptions

        // If you want to allow a specific IP range to go direct, use the line
        // below or remove it

        if(isInNet(host, “192.168.1.0”, “255.255.255.0”)) { return “DIRECT”; }

        // End network exceptions

        // Always bypass for localhost – make sure these 3 lines remain
        if (shExpMatch(host, “localhost*”) || shExpMatch(host, “127.0.0.1*”)) { return “DIRECT”; }

        // The browser is on a specific network, so send it a specific proxy to use
        // This is useful for multi-subnet networks with multiple CensorNet servers
        // Remove if you do not need this

        // if (isInNet(host, “10.0.41.0”, “255.255.255.0”)) {
        //        return “PROXY 10.0.41.15:8080”;
        // }

    // Proxy if PC is on local LAN

    if (isInNet(myIpAddress(), “192.168.1.0”, “255.255.255.0”))

    return “PROXY 192.168.1.15:8080”;

    else

    return “DIRECT”;
       

}

3. make sure you can download the wpad.pac file, – so go to your browser and type in the URL: http://IP_address/proxy/wpad.pac

4. modify DHCP

To create an option 252 entry in DHCP

  1. Click Start, point to All Programs, point to Administrative Tools, and then click DHCP.
  2. In the console tree, right-click the applicable DHCP server, click Set Predefined Options, and then click Add.
  3. In Name, type WPAD.
  4. In Code, type 252.
  5. In Data type, select String, and then click OK.
  6. In String, type http://Computer_Name:Port/wpad.dat where:
    • Computer_Name is the fully qualified domain name of the ISA Server computer.
    • Port is the port number on which automatic discovery information is published. You can specify any port number. By default, ISA Server publishes automatic discovery information on port 8080.
  7. Right-click Server options, and then click Configure options.
  8. Confirm that Option 252 is selected.