GNS
VMware虚拟机
两台CentOS7作为客户机
两台CentOS7作为服务器
1.DHCP服务与DHCP中继
2.DNS服务
3.WEB服务
4.三层交换机
1.二层交换机的配置
sw-2#conf t
sw-2(config)#no ip routing
sw-2(config)#vlan 10,20,100
sw-2(config-vlan)#ex
sw-2(config)#int f1/0
sw-2(config-if)#sw mo acc
sw-2(config-if)#sw acc vlan 10
sw-2(config-if)#int f1/1
sw-2(config-if)#sw mo acc
sw-2(config-if)#sw acc vlan 20
sw-2(config)#int range f1/2 -3
sw-2(config-if-range)#sw mo acc
sw-2(config-if-range)#sw acc vlan 100
sw-2(config-if-range)#int f1/4
sw-2(config-if)#sw mo tr
sw-2(config-if)#sw tr
sw-2(config-if)#sw tr en do
sw-2(config-if)#ex
2.三层交换机的配置
sw-3#conf t
sw-3(config)#vlan 10,20,100
sw-3(config-vlan)#ex
sw-3(config)#int vlan 10
sw-3(config-if)#ip add 192.168.10.1 255.255.255.0
sw-3(config-if)#ip helper-add
sw-3(config-if)#ip helper-address 192.168.100.100
sw-3(config-if)#no sh
sw-3(config-if)#int vlan 20
sw-3(config-if)#ip add 192.168.20.1 255.255.255.0
sw-3(config-if)#ip helper-address 192.168.100.100
sw-3(config-if)#no shut
sw-3(config-if)#int vlan 100
sw-3(config-if)#ip add 192.168.100.1 255.255.255.0
sw-3(config-if)#ip helper-address 192.168.100.100
sw-3(config-if)#no shut
sw-3(config-if)#int f1/4
sw-3(config-if)#sw mo tr
sw-3(config-if)#sw tr en do
3.DHCP服务器的配置
[root@localhost ~]# yum install dhcp* -y
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO=static
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="433eee57-c5db-46eb-8760-97e1b994a199"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
~
[root@localhost ~]#systemctl restart network
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.10 192.168.10.100;
option routers 192.168.10.1;
option domain-name-servers 192.168.100.99;
default-lease-time 600;
max-lease-time 7200;
}
subnet 192.168.20.0 netmask 255.255.255.0 {
range 192.168.20.10 192.168.20.100;
option routers 192.168.20.1;
option domain-name-servers 192.168.100.99;
default-lease-time 600;
max-lease-time 7200;
}
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.10 192.168.100.100;
option routers 192.168.100.1;
option domain-name-servers 192.168.100.99;
default-lease-time 600;
max-lease-time 7200;
host dns {
hardware ethernet 00:0c:29:0b:69:b8;
fixed-address 192.168.100.99;
}
}
4.DNS服务器和apache服务器的配置
[root@localhost ~]# yum install bind httpd -y
[root@localhost ~]# systemctl restart network
[root@localhost ~]# ifconfig
ens33: flags=4163 mtu 1500
inet 192.168.100.99 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::d5e8:9ff7:efc1:5ec prefixlen 64 scopeid 0x20
ether 00:0c:29:0b:69:b8 txqueuelen 1000 (Ethernet)
RX packets 641940 bytes 951403897 (907.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 197675 bytes 12117665 (11.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1 (Local Loopback)
RX packets 28 bytes 2328 (2.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 28 bytes 2328 (2.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099 mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:a6:6b:64 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]#
[root@localhost ~]# vim /etc/named.conf
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; };
配置dns的区域配置文件
[root@localhost ~]# vim /etc/named.rfc1912.zones
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "baidu.com" IN {
type master;
file "baidu.com.zone";
allow-update { none; };
};
复制dns区域数据配置文件模板
[root@localhost ~]# cd /var/named
[root@localhost named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@localhost named]# cp -p named.localhost baidu.com.zone
[root@localhost named]#
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
www IN A 192.168.100.99
ftp IN CNAME www
开启DNS服务,关闭防火墙
[root@localhost named]# systemctl restart named
[root@localhost named]# systemctl stop firewalld.service
[root@localhost named]# setenforce 0
配置apache服务,且开启服务
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
ServerName www.baidu.com:80
Listen 192.168.100.99:80
#Listen 80
[root@localhost ~]# systemctl restart httpd
注:在配置DHCP和DNS的配置文件时,要注意格式必须正确,否则易出错。此外,服务器的防火墙和SElinux需要关闭,要不然服务可能不生效。在配置DNS的区域数据配置文件时,复制模板需要保持原有权限。