虚拟机中linux的DHCP配置

562 阅读1分钟

1 配置DHCP服务器IP

ifconfig eth0 10.10.1.10
ifconfig eth0:1 10.10.1.1
ifconfig eth0:2 172.168.1.1
ifconfig eth0:3 172.168.2.1

2 DHCP相关设置

windows → 网络共享中心 → 属性 → 更改适配器设置 → vmnet1 → 属性 → IPV4 → 开启DHCP

vmware → 编辑 → 虚拟网络编辑 → 勾选使用本地DHCP

3 配置主配文件

(1)复制样板

cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample  /etc/dhcpd.conf   //使用样板

(2)打开主配文件

vim /etc/dhcpd.conf

(3)编辑主配文件

  1 ddns-update-style interim;
  2 ignore client-updates;
  3 shared-network xxx {						//单网卡多网段需要加上这个
  4 subnet 10.10.1.10 netmask 255.255.255.0 {	//设置子网的网段和掩码
  5 
  6 # --- default gateway
  7     option routers          10.10.1.1;		//默认网关
  8     option subnet-mask      255.255.255.0;	//客户端IP的子网掩码
  9 	//域名服务器
 10     option nis-domain       "xxxcollege.net";	//nis服务器域名
 11     option domain-name      "xxxcollege.net";	//DNS服务器域名
 12     option domain-name-servers  10.10.1.10;//DNS服务器IP
 13 
 14     option time-offset      -18000; # Eastern Standard Time
 15 #   option ntp-servers      192.168.1.1;
 16 #   option netbios-name-servers 192.168.1.1;
 17 # --- Selects point-to-point node (default is hybrid). Don't change this unl    ess
 18 # -- you understand Netbios very well
 19 #   option netbios-node-type 2;
 20 
 21     range dynamic-bootp 192.168.0.128 192.168.0.254;  //DHCP池范围
 22     default-lease-time 21600;
 23     max-lease-time 43200;
 24 
 25     # we want the nameserver to appear at a fixed address
 26     host xxx {
 27         next-server marvin.redhat.com;		//可以删除这条
 28         hardware ethernet 12:34:56:78:AB:CD; //这里要改成被分配的主机的物理地址
 29         fixed-address 207.175.42.254;		//为该物理地址指定IP
 30     }
 31 }}

4 测试

service dhcpd restart			//重启DHCP
service network restart			//重启网卡

windows也要在网络连接中禁用再启用重启,若都与指定IP相同则成功