目录
搭建环境介绍
虚拟机中仅主机模式下,同时关闭虚拟机DHCP网卡服务
关闭防火墙和SElinux情况
命令如下:
关闭防火墙:chkconfig iptables off
关闭SELinux:vim /etc/sysconfig/selinux 修改配置文件的中的为SELINUX=disabled
一、DHCP服务器搭建
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
安装hdcp服务器
yum -y install dhcp
修改配置文件(dhcpd.conf)
1.找到配置文件模板进行替换。
[root@CetnOS6-02 ~]# cp -a /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
2.修改配置文件里面的内容
[root@CetnOS6-02 ~]# vim /etc/dhcp/dhcpd.conf
将配置文件的其他subnet声明注释掉。
subnet 192.168.10.0 netmask 255.255.255.224 {
range 192.168.10.100 192.168.10.110;
# option domain-name-servers ns1.internal.example.org;
# option domain-name "internal.example.org";
# option routers 10.5.5.1;
# option broadcast-address 10.5.5.31;
default-lease-time 600;
max-lease-time 7200;
}
模版详细解释:
subnet 192.168.88.0 netmask 255.255.255.0 { #声明要分配的网段和子网掩码
range 192.168.88.3 192.168.88.254; #声明可用 IP 地址池
option domain-name "atguigu.com" ; #设置 DNS 域
option domain-name-servers 8.8.8.8 ; #设置 DNS 服务器地址
option routers 192.168.88.2; #默认网关的地址
option broadcast-address 192.168.88.255; #广播地址(可不写)
default-lease-time 600; #默认租约(s)
max-lease-time 7200; #最大租约(s)
}
需要注意:“ { }缺失、每行结尾;” ,以及分配的网段和子网掩码必须和当前的网卡的网段保持一致,不一致服务无法启动,直接报错。
启动服务
[root@CetnOS6-02 ~]# service dhcpd start
正在启动 dhcpd: [确定]
[root@CetnOS6-02 ~]# netstat -tlun | grep 67
udp 0 0 0.0.0.0:67 0.0.0.0:*
#服务启动成功。
3.通过客户机验证HDCP服务器运行情况。
[root@Cent0S-03 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:23:E8:75
inet addr:192.168.10.100 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe23:e875/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:46643 errors:0 dropped:0 overruns:0 frame:0
TX packets:3164 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:59141951 (56.4 MiB) TX bytes:214084 (209.0 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:276 (276.0 b) TX bytes:276 (276.0 b)
4.读取日志文件查看验证HDCP运行
[root@CetnOS6-02 ~]# tail -10 /var/log/messages
Oct 30 10:59:17 CetnOS6-02 dhcpd: DHCPDISCOVER from 00:0c:29:23:e8:75 via eth0
Oct 30 10:59:18 CetnOS6-02 dhcpd: ns1.example.org: temporary name server failure
Oct 30 10:59:18 CetnOS6-02 dhcpd: ns2.example.org: temporary name server failure
Oct 30 10:59:18 CetnOS6-02 dhcpd: DHCPOFFER on 192.168.10.100 to 00:0c:29:23:e8:75 (Cent0S-03) via eth0
Oct 30 10:59:18 CetnOS6-02 dhcpd: Wrote 0 class decls to leases file.
Oct 30 10:59:18 CetnOS6-02 dhcpd: Wrote 0 deleted host decls to leases file.
Oct 30 10:59:18 CetnOS6-02 dhcpd: Wrote 0 new dynamic host decls to leases file.
Oct 30 10:59:18 CetnOS6-02 dhcpd: Wrote 1 leases to leases file.
Oct 30 10:59:18 CetnOS6-02 dhcpd: DHCPREQUEST for 192.168.10.100 (192.168.10.20) from 00:0c:29:23:e8:75 (Cent0S-03) via eth0
Oct 30 10:59:18 CetnOS6-02 dhcpd: DHCPACK on 192.168.10.100 to 00:0c:29:23:e8:75 (Cent0S-03) via eth0
二、HDCP中固定地址分发
1.获取客户机的mac地址
[root@CentOS-04 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:4D:28:4F
inet addr:192.168.10.101 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe4d:284f/64 Scope:Link
2.修改服务器的配置文件给客户机指定IP地址
[root@CetnOS6-02 ~]# vim /etc/dhcp/dhcpd.conf
host fantasia {
hardware ethernet 00:0C:29:4D:28:4F;
#客户机的mac地址
fixed-address 192.168.10.110;
#绑定分发的IP地址
}
重启HDCP服务,否则无法进行分发IP地址。
[root@CetnOS6-02 ~]# service dhcpd restart
关闭 dhcpd: [确定]
正在启动 dhcpd: [确定]
通过查看日志验证发送成功。
Oct 30 11:23:01 CetnOS6-02 dhcpd: DHCPREQUEST for 192.168.10.110 from 00:0c:29:4d:28:4f via eth0
Oct 30 11:23:01 CetnOS6-02 dhcpd: ns1.example.org: temporary name server failure
Oct 30 11:23:01 CetnOS6-02 dhcpd: ns2.example.org: temporary name server failure
Oct 30 11:23:01 CetnOS6-02 dhcpd: DHCPACK on 192.168.10.110 to 00:0c:29:4d:28:4f via eth0
三、DHCP服务的超级作用域
1. 同一个网卡增加第二个网段。
[root@CetnOS6-02 ~]# cd /etc/sysconfig/network-scripts/
[root@CetnOS6-02 network-scripts]# cp -a ifcfg-eth0 ifcfg-eth0:0
#给同一张网卡增加IP地址。
[root@CetnOS6-02 network-scripts]# vim ifcfg-eth0:0
#修改配置文件
IPADDR=192.168.99.20
#因为是同一个网卡,只需要更改的网卡IP
[root@CetnOS6-02 network-scripts]# ifup eth0:0
#启动网卡,并查看运行结果
Determining if ip address 192.168.99.20 is already in use for device eth0...
[root@CetnOS6-02 network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E7:DA:51
inet addr:192.168.10.20 Bcast:192.168.10.255 Mask:255.255.255.
2.修改配置文件,启动转发功能并且刷新配置。
[root@CetnOS6-02 ~]# vim /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
# 启动转发只需修改成1。
[root@CetnOS6-02 ~]# sysctl -p #刷新配置文件
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
3.修改文件:vim /etc/dhcp/dhcpd.conf
#文件里面的其他相关配置视情况不用的可以全部注释掉。
shared-network 10-99 {
#网卡的IP地址号码段
subnet 192.168.10.0 netmask 255.255.255.0 {
option routers 192.168.10.20;
range 192.168.10.21 192.168.10.21;
}
subnet 192.168.99.0 netmask 255.255.255.0 {
option routers 192.168.99.20;
range 192.168.99.110 192.168.99.115;
}
}
重新启动服务
[root@CetnOS6-02 ~]# service dhcpd restart
关闭 dhcpd: [确定]
正在启动 dhcpd: [确定]
四、HDCP中继功能
服务器网段设置:
DHCP服务器: eth0(192.168.10.20) VMnet10
DHCP中继: eth0(192.168.10.30) VMnet10
eth1(100.100.100.30) VMnet11
外网客户机: eth0(IP地址自动获取) VMnet11
1、HDCP服务器设置网关
修改网卡配置文件eth0,向文件里面添加网关信息:GATEWAY=192.168.10.30
2、修改配置dhcpd配置文件
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.30 192.168.10.35;
option routers 192.168.10.30;
}
#实验中并未用到该地址池分配IP,但是DHCP服务启动需要地址。
subnet 100.100.100.0 netmask 255.255.255.0 {
range 100.100.100.111 100.100.100.112;
option routers 100.100.10.30;
}
#声明两个subnet,其他无关可以不做操作或删除
3.修改中继服务器网卡
[root@Cent0S-03 network-scripts]# cp ifcfg-eth0 ifcfg-eth1
#建立eth1网卡配置文件
DEVICE=eth1
#这里需要修改名字为当前网卡名
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
USERCTL=no
PEERDNS=yes
IPV6INIT=no
IPADDR=100.100.100.30
#修改ip地址
NETMASK=255.255.255.0
重新启动网卡
[root@Cent0S-03 network-scripts]# service network restart
正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: Determining if ip address 192.168.10.30 is already in use for device eth0...
[确定]
弹出界面 eth1: Determining if ip address 100.100.100.30 is already in use for device eth1...
[确定]
4.修改配置文件:vim /etc/sysconfig/dhcrelay
INTERFACES="eth0 eth1"
#添加的网卡名称
DHCPSERVERS="192.168.10.20"
#添加HDCP服务的ip地址,不是中继器的IP。
5.开启路由转发
修改配置文件:vim /etc/sysctl.conf 里面的为 net.ipv4.ip_forward = 1
然后刷新配置:sysctl -p
6.启动中继服务:service dhcrelay start
7.测试外网主机。
Oct 30 13:13:57 CetnOS6-02 dhcpd: DHCPDISCOVER from 00:0c:29:4d:28:4f via 100.100.100.30
Oct 30 13:13:58 CetnOS6-02 dhcpd: ns1.example.org: temporary name server failure
Oct 30 13:14:03 CetnOS6-02 dhcpd: ns2.example.org: temporary name server failure
Oct 30 13:14:03 CetnOS6-02 dhcpd: DHCPOFFER on 100.100.100.111 to 00:0c:29:4d:28:4f (CentOS-04) via 100.100.100.30
Oct 30 13:14:03 CetnOS6-02 dhcpd: DHCPDISCOVER from 00:0c:29:4d:28:4f (CentOS-04) via 100.100.100.30
Oct 30 13:14:03 CetnOS6-02 dhcpd: DHCPOFFER on 100.100.100.111 to 00:0c:29:4d:28:4f (CentOS-04) via 100.100.100.30
Oct 30 13:14:03 CetnOS6-02 dhcpd: DHCPREQUEST for 100.100.100.111 (192.168.10.20) from 00:0c:29:4d:28:4f (CentOS-04) via 100.100.100.30
Oct 30 13:14:03 CetnOS6-02 dhcpd: DHCPACK on 100.100.100.111 to 00:0c:29:4d:28:4f (CentOS-04) via 100.100.100.30