Red Hat 服务配置实验day02

day02

1.再配置两台相同环境的

分别取名为client1,client2,细节不说了,克隆不克隆随你,mac别一样就行~~

2.配置网卡

sever,client1,client2,配置相同的虚拟网卡,别选0,1,8,这三个一般别的nat,桥接等等模式会默认配置,想知道的看虚拟网络编辑器那里就知道为什么了,这里不细说,这里我们选了5~~

Red Hat 服务配置实验day02

3.配置sever虚拟机

首先配置network,如下~~

Red Hat 服务配置实验day02

之后就可以一直敲了~~

[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# yum install dhcp-server.x86_64 -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:02:05 ago on Tue 29 Jun 2021 12:41:53 PM CST.
Dependencies resolved.
================================================================================
 Package             Architecture   Version                  Repository    Size
================================================================================
Installing:
 dhcp-server         x86_64         12:4.3.6-40.el8          base         529 k

Transaction Summary
================================================================================
Install  1 Package

Total size: 529 k
Installed size: 1.2 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Running scriptlet: dhcp-server-12:4.3.6-40.el8.x86_64                     1/1 
  Installing       : dhcp-server-12:4.3.6-40.el8.x86_64                     1/1 
  Running scriptlet: dhcp-server-12:4.3.6-40.el8.x86_64                     1/1 
  Verifying        : dhcp-server-12:4.3.6-40.el8.x86_64                     1/1 
Installed products updated.

Installed:
  dhcp-server-12:4.3.6-40.el8.x86_64                                            

Complete!
[root@localhost ~]# cat /etc/dhcp/dhcpd.conf 
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp-server/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
[root@localhost ~]# cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf    //路径写上面查看到的
cp: overwrite '/etc/dhcp/dhcpd.conf'? y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf 

配置如下

# which we don't really recommend.

//在此之前的subnet的代码块都删掉,或者你注释掉,之后配置如下
# A slightly different configuration for an internal subnet.
subnet 1.1.1.0 netmask 255.255.255.0 { //网段和子网号
  range 1.1.1.2 1.1.1.3; //想要分配出的ip
  option domain-name-servers 1.1.1.1; //网关服务器地址,因为我们选择自己找所以网关是自己
  option domain-name "zaunekko.example.org";//随意取
  option routers 1.1.1.1; //同上即可
  default-lease-time 600; //最少租期
  max-lease-time 7200; //最大租期
}
                                                                        

退出来,启动dhcp服务~~

[root@localhost ~]# systemctl restart dhcpd.service 

成功~~

4.配置client01,client02有线连接

两个都恢复快照,打开network,重新打开一下有线连接,即可发现ip地址已经被配置,分别为刚刚所想配置的1.1.1.2和1.1.1.3,这里我是client02的ip是1.1.1.3~~

5.继续回来配置server

根据作业所示,需要更改1.1.1.3的固定分配地址为1.1.1.100~~

那么就ping一下,就会有arp缓存,就能知道对应的ip对应的mac地址了,应该都记得arp原理吧~~

[root@localhost ~]# arp -a
? (210.30.48.7) at <incomplete> on ens160
? (1.1.1.3) at 00:0c:29:5f:2a:44 [ether] on ens160 //复制此mac地址
? (203.107.6.88) at <incomplete> on ens160
? (1.1.1.2) at 00:0c:29:7c:aa:c9 [ether] on ens160
? (192.168.116.2) at <incomplete> on ens160

接下来更改dhcpd.conf,配置如下

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf 

//找到此段,大致为70行
host fantasia {
  hardware ethernet 00:0c:29:5f:2a:44;  //为上步mac地址
  fixed-address 1.1.1.100; //想分配的固定ip
}

退出来,重新启动dhcp服务~~

[root@localhost ~]# systemctl restart dhcpd.service 

成功~~

6.查看client的ip分配是否成功

打开对应的client主机,我这里是client1,重新打开一下有线连接,即可发现ip地址已经被配置为1.1.1.100~~

如下图所示~~

Red Hat 服务配置实验day02

至此,你就可以交作业了,建议再创个快照~~

day02 附加(添加中继)

这里我们直接将server和client1调整到第10块虚拟网卡,client2调整到第15块虚拟网卡,并且为clinet1再添加一个网络适配器,调整到第15块虚拟网卡~~

准备工作做好之后~~

1.配置sever

首先network配置如下~~

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Qr3XvddH-1624950383985)(https://www.zaunekko.com/download/image/web/12.png)]

因为继刚刚所敲的,然后,只需要敲~~

[root@localhost ~]# route add default gw 1.1.1.2  //因为原来的client1是这个ip,我们想让他做中继

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf  //重新配置一下
subnet 1.1.1.0 netmask 255.255.255.0 { 
  range 1.1.1.2 1.1.1.3;
  option domain-name-servers 1.1.1.2; //更改为client1的
  option domain-name "zaunekko.example.org";
  option routers 1.1.1.2;
  default-lease-time 600;
  max-lease-time 7200;
}
subnet 100.100.100.0 netmask 255.255.255.0 { 
  range 100.100.100.2 100.100.100.3;
  option domain-name-servers 100.100.100.1; //更改为client1另外一个网卡的
  option domain-name "zaunekko.example.org";
  option routers 100.100.100.1;
  default-lease-time 600;
  max-lease-time 7200;
}


[root@localhost ~]# systemctl restart dhcpd.service 

成功~~

2.配置client1

重新打开一下有线连接~~

配置会变成此~~

Red Hat 服务配置实验day02

此时打开第二个网卡并且记住名字,并且配置为如下~~

Red Hat 服务配置实验day02

完成之后~~

Red Hat 服务配置实验day02

之后可以敲了~~

[root@localhost yum.repos.d]# setenforce 0
[root@localhost yum.repos.d]# systemctl stop firewalld.service
[root@localhost yum.repos.d]# vim /etc/sysctl.conf

//添加如下~~
net.ipv4.ip_forward = 1;

[root@localhost yum.repos.d]# sysctl -p
sysctl: setting key "net.ipv4.ip_forward": Invalid argument
net.ipv4.ip_forward = 1;
[root@localhost yum.repos.d]# cat /proc/sys/net/ipv4/ip_forward
1
//发现成功
[root@localhost yum.repos.d]# yum install dhcp-relay.x86_64 
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 1:41:08 ago on Tue 29 Jun 2021 12:53:09 PM CST.
Dependencies resolved.
================================================================================
 Package            Architecture   Version                   Repository    Size
================================================================================
Installing:
 dhcp-relay         x86_64         12:4.3.6-40.el8           base         236 k

Transaction Summary
================================================================================
Install  1 Package

Total size: 236 k
Installed size: 348 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : dhcp-relay-12:4.3.6-40.el8.x86_64                      1/1 
  Running scriptlet: dhcp-relay-12:4.3.6-40.el8.x86_64                      1/1 
  Verifying        : dhcp-relay-12:4.3.6-40.el8.x86_64                      1/1 
Installed products updated.

Installed:
  dhcp-relay-12:4.3.6-40.el8.x86_64                                             

Complete!
[root@localhost yum.repos.d]# cp /lib/systemd/system/dhcrelay.service /etc/systemd/system/
[root@localhost yum.repos.d]# vim /etc/systemd/system/dhcrelay.service 
//编辑如下

[Unit]
Description=DHCP Relay Agent Daemon
Documentation=man:dhcrelay(8)
Wants=network-online.target
After=network-online.target

[Service]
Type=notify
ExecStart=/usr/sbin/dhcrelay -d --no-pid 1.1.1.1 -i ens160 -i ens224
StandardError=null

[Install]
WantedBy=multi-user.target


[root@localhost yum.repos.d]# systemctl --system daemon-reload 
[root@localhost yum.repos.d]# systemctl restart dhcrelay.service 
[root@localhost yum.repos.d]# 

成功~~

3.查看client2

重新打开一下client2的有线连接~~

如下~~

Red Hat 服务配置实验day02

发现成功~~

上一篇:PXE无人值守自动装机系统


下一篇:Linux:配置dhcp服务器和dhcp中继