zoukankan      html  css  js  c++  java
  • DHCP configurations in Ubuntu

    Configuring DHCP server

    If you have two network cards in your ubuntu server you need to select which interface you want to use for  DHCP server listening.By default it listens to eth0.

    You can change this by editing  /etc/default/dhcp3-server file

    sudo vi /etc/default/dhcp3-server

    Find this line

    INTERFACES="eth0"

    Replace with the following line

    INTERFACES="eth1"

    Save and exit.This is optional. COOL~~

    Next you need to make a backup copy of /etc/dhcp3/dhcpd.conf file

    cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.back

    Edit /etc/dhcp3/dhcpd.conf file using the following command

    sudo vi /etc/dhcp3/dhcpd.conf

    Using address pool method

    You need to change the following sections in /etc/dhcp3/dhcpd.conf file

    default-lease-time 600;
    max
    -lease-time 7200;

    option subnet
    -mask 255.255.255.0;
    option broadcast
    -address 192.168.1.255;
    option routers 
    192.168.1.254;
    option domain
    -name-servers 192.168.1.1, 192.168.1.2;
    option domain
    -name ¡°yourdomainname.com¡±;

    subnet 
    192.168.1.0 netmask 255.255.255.0 {
        range 
    192.168.1.10 192.168.1.200;
    }
     save and exit the file

    This will result in the DHCP server giving a client an IP address from the range 192.168.1.10-192.168.1.200 . It will lease an IP address for 600 seconds if the client doesn¡¯t ask for a specific time frame. Otherwise the maximum (allowed) lease will be 7200 seconds. The server will also ¡°advise¡± the client that it should use 255.255.255.0 as its subnet mask, 192.168.1.255 as its broadcast address, 192.168.1.254 as the router/gateway and 192.168.1.1 and 192.168.1.2 as its DNS servers.

    Using MAC address method

    This method is you can reserver some of the machines or all the machines with fixed ip address.In the following example i am using fixed ip address for server1,server2,printer1 and printer2

    default-lease-time 600;
    max
    -lease-time 7200;

    option subnet
    -mask 255.255.255.0;
    option broadcast
    -address 192.168.1.255;
    option routers 
    192.168.1.254;
    option domain
    -name-servers 192.168.1.1, 192.168.1.2;
    option domain
    -name ¡°yourdomainname.com¡±;

    subnet 
    192.168.1.0 netmask 255.255.255.0 {
        range 
    192.168.1.10 192.168.1.200;
    }

    host server1 {
        hardware ethernet 
    00:1b:63:ef:db:54;
        fixed
    -address 192.168.1.20;
    }

    host server2 {
        hardware ethernet 
    00:0a:95:b4:d4:b0;
        fixed
    -address 192.168.1.21;
    }

    host printer1 {
        hardware ethernet 
    00:16:cb:aa:2a:cd;
        fixed
    -address 192.168.1.22;
    }

    host printer2 {
        hardware ethernet 
    00:0a:95:f5:8f:b3;
        fixed
    -address 192.168.1.23;
    }

     Now you need to restart dhcp server using the following command

    sudo /etc/init.d/dhcp3-server restart

    Configure Ubuntu DHCP Client

    If you want to configure your ubuntu desktop as DHCP client following this procedure

    You need to open /etc/network/interfaces file

    sudo vi /etc/network/interfaces

    make sure you have the following lines (eth0 is an example)

    auto lo eth0
    iface eth0 inet dhcp
    iface lo inet loopback

     Save and exit the file

    You need to restart networking services using the following command

    sudo /etc/init.d/networking restart

    How to find DHCP server IP address

    You need to use the following commands

    sudo dhclient

    or

    tail -n 15 /var/lib/dhcp3/dhclient.*.leases

  • 相关阅读:
    使用DevExpress 控件开发通用查询控件(Winform)
    SQL 排序函数
    SQL Server 消除科学计数法
    Excel VBA 的GetOpenFilename 方法
    分布式定时任务利用分布式定时任务框架xxljob实现任务动态发布
    java 同时启动多个项目
    Jooq配置与使用
    java 线上诊断工具arthas使用记录及k8s使用
    k8s脚本
    输入汉字获得拼音(VB.net)
  • 原文地址:https://www.cnblogs.com/super119/p/1904396.html
Copyright © 2011-2022 走看看