RedHat7服务器配置

记录这学期学的一些RedHat上的dhcp、dns、web服务器的配置

dhcp

1.由于虚拟机也提供了dhcp服务,因此用nat或host-only时会选用虚拟机的dhcp服务,因此要在虚拟网络编辑器中取消分配dhcp

2.移除virbr0虚拟网卡;
https://blog.csdn.net/csdn_immortal/article/details/81068259

3.配置静态ip,要与dhcp子网在同一网段;

vi /etc/sysconfig/network-scripts/ifcfg-eno16777736

修改内容:

BOOTPROTO=static
IPADDR=192.168.2.5
GATEWAY=192.168.2.1

4.配置dhcp

vi /etc/dhcp/dhcpd.conf

修改后内容如下:

ddns-update-style interim;
ignore client-updates;

subnet 192.168.2.0 netmask 255.255.255.0 {

# --- default gateway
        option routers 192.168.2.1;
        option subnet-mask 255.255.255.0;
        range dynamic-bootp 192.168.2.50 192.168.2.60;
        default-lease-time 21600;
        max-lease-time 43200;

}                                                                  

5.开始用service dhcpd start启动dhcp,但出现Redirecting to /bin/systemctl start dhcpd.service;

改用systemctl start dhcpd.service启动dhcp服务

用systemctl status dhcpd.service查看服务状态

用netstat -unlp查看dhcp监听端口:

67/udp  服务端
68/udp  客户端

6.客户机重新获取ip;

dns

主配置文件:

vi /etc/named.conf

配置过后内容:

[root@localhost named]# cat /etc/named.conf
options {
    directory    "/var/named";
};

zone "." IN {
    type hint;
    file "named.ca";
};

zone "localhost" IN {
    type master;
    file "named.localhost";
};

zone "0.0.127.in-addr-arpa" IN {
    type master;
    file "named.loopback";
};

zone "gtf.com" IN {
    type master;
    file "gtf.com.zone";
};

检测语法是否出错:

named-checkconf

在主配置文件中配置域:

区域格式:

zone "ZONE NAME" IN {
    type {master|slave|hint|forward};
};

主区域:

file "区域数据文件";

从区域:

file "区域数据文件"
masters {主DNS服务器地址;};

根区域(固定):

zone "." IN {
    type hint;
    file "named.ca";
};

建立区域文件

建立正向区域(要与上面主配置文件的配置域中的区域数据文件名相同):

cd /var/named/

vi gtf.com.zone

检测语法错误:

named-checkzone "gtf.com" /var/named/gtf.com.zone

配置过后内容:

[root@localhost named]# cat gtf.com.zone
$TTL 600
gtf.com.    IN    SOA    test.gtf.com.     admin.gtf.com. (
                2019052519
                10800
                3600
                604800
                463500 )
@        IN    NS    test.gtf.com.
test        IN    A    192.168.2.8
www        IN    CNAME    test.gtf.com.

配置该文件需要更改权限:

chomd 640 gtf.com.zone

启动dns

启动dns服务:

systemctl start named.service

查看dns服务状态:

systemctl status named.service

查看53端口是否打开

netstat -antlpe | grep named 

验证配置

[root@localhost named]# host test.gtf.com
test.gtf.com has address 192.168.2.8

在其他主机上测试,需指定dns服务器地址:

vi /etc/resolv.conf
nameserver 192.168.2.5

web

主配置文件:

vi /etc/httpd/conf/httpd.conf

配置的内容:

Listen 80
Include conf.modules.d/*.conf
User apache
Group apache

ServerAdmin root@sh.com
ServerName test.gtf.com:80
DocumentRoot "/var/www/html"
DirectoryIndex index.html index.htm
AddDefaultCharset UTF-8

之后在/var/www/html目录下创建index.html写入内容后,即可访问http://192.168.2.5来访问这个web服务(192.168.2.5是我虚拟机的静态ip地址)

之后修改/var/named/gtf.com.zone,将test对应的ip地址修改为虚拟机的ip地址,即可通过test.gtf.com`来访问web服务