实例:
1:分配IP地址
公司有60 台计算机,IP 地址段为192.168.1.2-192.168.1.254,子网掩码是255.255.255.0,网关为192.168.1.1,保留地址段192.168.1.2-192.168.1.30 网段地址给服务器配置,客户端可以使用的地址段为192.168.1.100—192168.1.200,其余剩下的IP 地址为保留地址。
实验环境:
我的虚拟机使用桥接模式是否可行? 不行,因为你的局域网中有可能就有DHCP服务器,这样你就很难让你的客户端是从你的DHCP服务器获得IP地址。另外,也可能造成公司局域网中其它机器因为获得了你DHCP服务器上的IP地址,而上不了网。
xuegod63.cn :192.168.0.63 虚拟机网卡: vmnet4
xuegod64.cn :192.168.0.64 虚拟机网卡: vmnet4
[root@xuegod63 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
[root@xuegod63 ~]# service network restart
1):修改DHCP配置文件
[root@xuegod63 ~]# vim /etc/dhcp/dhcpd.conf
只保留:
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.100 192.168.0.200;
option domain-name-servers 192.168.0.1;
option domain-name "internal.example.org";
option routers 192.168.0.1;
option broadcast-address 192.168.0.255;
default-lease-time 600;
max-lease-time 7200;
}
2):重启dhcp服务
[root@xuegod63 ~]# service dhcpd restart
然后xuegod64改为自动获取IP地址。


将xuegod63和xuegod64 的网卡模式改为:
然后xuegod64改为自动获取IP地址。
查看:
[root@xue63 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:12:EC:1E
inet addr:192.168.0.200 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe12:ec1e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5084 errors:0 dropped:0 overruns:0 frame:0
TX packets:5087 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:664380 (648.8 KiB) TX bytes:521089 (508.8 KiB)
3)查看默认网关
[root@xue63 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
4)查看DNS
[root@xue63 ~]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
search internal.example.org com
nameserver 192.168.0.1
5)查看租约数据库文件
[root@xuegod64 dhcp]# cat /var/lib/dhcpd/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.1.1-P1
server-duid "\000\001\000\001\030\233\206H\000\014)H\200\237";
lease 192.168.0.200 {
starts 3 2013/01/30 07:30:16;
ends 3 2013/01/30 07:40:16;
cltt 3 2013/01/30 07:30:16;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:12:ec:1e;
}
2:IP 地址绑定
在DHCP 中的IP 地址绑定用于给客户端分配固定IP 地址。比如服务器需要使用固定IP 地址就可以使用IP 地址绑定,通过MAC 地址与IP 地址的对应关系为指定的物理地址计算机分配固定IP地址。
整个配置过程需要用到 host 声明和hardware、fixed-address 参数。
(1)host 主机名 {......}
作用:用于定义保留地址
(2)hardware 类型 硬件地址
作用:定义网络接口类型和硬件地址。常用类型为以太网(ethernet),地址为MAC 地址。
(3)fixed-address IP 地址
作用:定义DHCP 客户端指定的IP 地址。
[root@xuegod63 ~]# vim /etc/dhcp/dhcpd.conf # 找到对应的子网范围,修改成以下内容
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.100 192.168.0.200;
option domain-name-servers 192.168.0.1;
option domain-name "internal.example.org";
option routers 192.168.0.1;
option broadcast-address 192.168.0.255;
default-lease-time 600;
max-lease-time 7200;
host xuegod63 { #这一段内容,要写在subnet字段中,和subnet配合使用。
hardware ethernet 00:0C:29:12:ec:1e;
fixed-address 192.168.0.251;
}
}
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-05/143470.htm
