路由器的搭建与DHCP服务

本文详细介绍如何在虚拟环境中配置路由器及DHCP服务,包括设置网络环境、配置防火墙、开启路由器服务,以及搭建和测试DHCP服务器的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

路由器的搭建

配置环境:

在真机中使用root用户输入命令virt-manager打开虚拟机控制

我们把desktop当作我们实验用的路由器,默认情况下之有一块网卡,现在需要我们给desktop虚拟机添加一块虚拟网卡

我们可以看到现在desktop中已经存在两块网卡了

现在我们配置server上的ip为1.1.1.146,此时由于ip问题,主机与server之间无法进行通信

配置路由器

我们先删除desktop中原有的网络配置

开始配置我们的两块网卡,使它们的ip段和我们的真机和虚拟机分别相同,随后重启服务,查看网络配置信息:

再次配置实验环境

1.我们需要在server上设置网关:

然后用route -n 查看我们配置好的网关,这里已经配置好了

2.我们要在desktop上保证防火墙的开启

3.我们要在desktop上开启路由器服务 firewalld-cmd --add-masquerade

准备完成,测试实验结果

在做实验之前,我们发现server无法与主机进行通信

做完上述操作,我们发现server能够通过路由器与主机进行通信了

 

DHCP服务

注释:由于没有拷贝djcp服务的相关文件,现用文字陈述步骤

实验环境

我们准备两台虚拟机来进行实验

desktop 中的 ip:172.25.254.146  我们使用desktop来配置dhcp服务

server 中不设置ip并删除默认配置,我们用server来测试dhcp服务

配置dhcp服务器

打开dhcp的配置文件/usr/share/doc/dhcp*/dhcpd.conf.example该文件,此为dhcp的配置文件

拷贝该文件到dhcp的配置文件cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf

配置我们所需要的dhcp服务器,下列为配置完成之后的文件内容:

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name “westos";   ---- 设置名称
option domain-name-servers 172.25.254.250;
  ---- 设置ip为提供dns服务的ip

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

# This is a very basic subnet declaration.

subnet 172.25.254.0 netmask 255.255.255.0 {    ---- 第一行为dhcp所在的网段和子网掩码
  range 172.25.5.60 172.25.5.70;    ---- 第二行为dhcp分配ip的范围
  option routers 172.25.254.111;   ----第三行为网关
}

 

systemctl start dhcpd ---- 开启服务

测试实验结果

vim /etc/sysconfig/network-scripts/ifcfg-eth0 ---- 设置server的ip地址为dhcp自动获取

systemctl restart network ---- 设置完成后重启网络

ifconfig ---- 查看ip是否在dhcp设置的范围中     

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值