Linux DHCP服务器配置实验
实验1.DHCP配置服务器
设置服务器
添加本地网络适配器
打开虚拟网络编辑器。查看子网,将DHCP关闭 设置网络连接:
设置DHCP
1.下载DHCP:可以将网卡切换会NAT模式,下载DHCP后切回。
[root@localhost ~]# yum -y install dhcp
2.打开DHCP配置文件:
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf # # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.example # see dhcpd.conf(5) man page # ~
复制/usr/share/doc/dhcp*/dhcpd.conf.example。
将/usr/share/doc/dhcp*/dhcpd.conf.example文件内容复制到dhcpd.conf上。
[root@localhost ~]# cp -p /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
编辑dhcpd.conf
# option definitions common to all supported networks... option domain-name "example.org"; option domain-name-servers ns1.example.org, ns2.example.org; # A slightly different configuration for an internal subnet. subnet 192.168.100.0 netmask 255.255.255.224 { range 192.168.100.10 192.168.100.20; #地址池 option routers 192.168.100.100;#网关 default-lease-time 600; #租期:600s max-lease-time 7200; #最长租期:7200s }
启动DHCP:
[root@localhost ~]# systemctl start dhcpd Job for dhcpd.service failed because the control process exited with error code. See "systemctl status dhcpd.service" and "journalctl -xe" for details.
查看DHCP状态
[root@localhost dhcp]# netstat -anup | grep dhcpd udp 0 0 0.0.0.0:67 0.0.0.0:* 5719/dhcpd
2.设置PC
将PC网卡设成与Linux一样的
进入主机打开ipconfig
扩展:设置win10固定IP地址
我们可以更改数据将win10的ip地址设置为固定的地址 1.找到pc的MAC地址:
ipconfig /all 复制物理地址后的数字粘贴到dhcpd.conf配置文件中:
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf 省略部分 ....... 70 host fantasia { 71 hardware ethernet 00:0C:29:6F:2A:D3; 72 fixed-address 193.168.100.88; #设置想要设置的网段下的IP地址。可以超过地址池。 73 } 省略部分 .......
重启network,DHCP
[root@localhost ~]# systemctl restart network [root@localhost ~]# systemctl restart dhcpd
查看DHCPD状态
[root@localhost ~]# netstat -anup | grep dhcpd udp 0 0 0.0.0.0:67 0.0.0.0:* 6375/dhcpd
释放PC源IP地址:ipconfig /release
重新获取地址:ipconfig /renew
实验2.ensp获取Linux服务器地址池地址
二层交换机:配置vlan Sw [sw]vlan batch 10 20 192 [sw]int e0/0/1 [sw-Ethernet0/0/1]p l a [sw-Ethernet0/0/1]p d v 10 [sw-Ethernet0/0/1]int e0/0/2 [sw-Ethernet0/0/2]p l a [sw-Ethernet0/0/2]p d v 20 [sw-Ethernet0/0/2]int e0/0/4 [sw-Ethernet0/0/4]p l a [sw-Ethernet0/0/4]p d v 192
三层路由:配置vlanif ip。 RW [RW]vlan batch 10 20 192 [RW]int vlan 10 [RW-Vlanif10]ip a 192.168.10.1 24 [RW-Vlanif10]int vlan 20 [RW-Vlanif20]ip a 192.168.20.1 24 [RW-Vlanif20]int vlan 192 [RW-Vlanif192]ip a 192.168.192.1 24
Linux 配置文件加入网关:
Vim /etc/sysconfig/network--scripts/ifcfg-ens33 GATEWAY=192.168.40.1
更新网络
[root@localhost ~]# systemctl restart network
开启dhcp
[RW-Vlanif10]dhcp selct relay [RW-Vlanif20]dhcp selct relay [RW-Vlanif192]dhcp selct relay
将服务器网络地址注入接口:
[RW-Vlanif192]dhcp relay server-ip 192.168.40.66 [RW-Vlanif10]dhcp relay server-ip 192.168.40.66 [RW-Vlanif20]dhcp relay server-ip 192.168.40.66
PC1获取网址,ping通Linux
PC2获取网址,ping通Linux
如果没有将Linux服务器网络地址注入接口将获取不到网址。并ping不通
上一篇:
Java架构师技术进阶路线图
下一篇:
常见协议端口号和IP地址