本文介绍了如何让 dhcp 服务器侦听虚拟机 vm 中的广播请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 udhcpd,这是一个带有 busy box轻量级 dhcp 服务器.

I am working on udhcpd, a light weight dhcp server that comes with busy box.

我进行了一些代码更改并测试那些我需要运行 udhcpd 的代码,从客户端向其发送请求(以获取 ip)并查看其响应.

I have made some code changes and to test those i need to run udhcpd, send it request (to obtain ip) from a client and view its response.

这需要多台机器,对我来说合适的选择是使用多个虚拟机 VM.

This requires multiple machines and the suitable option for me was to use multiple virtual box VMs.

我使用了两个 linux VM(Fedora 用于运行 udhcpd,一个 ubuntu 用于运行 udhcpc - 一个带有用于生成 dhcp 请求的繁忙框的客户端).

I used two linux VM's (Fedora for running udhcpd and a ubuntu for running udhcpc - a client that comes with busy box for generating dhcp requests).

现在虚拟盒子有多种组网方式.我都试过了.最简单的 NAT 允许 vm 使用我的 windows 互联网,无需任何配置.

Now there are multiple modes of networking in virutal box. I have tried them all. NAT the most simple allows vm to use my windows internet without any configuration.

我尝试了各种类型的虚拟盒卡,即仅主机、内部网络,并为 Fedora 分配了一个 192.168.0.1 地址,它是 udhcpd,并从 udhcpc 客户端发送了 dhcp 发现请求.

I tried various types of virtual box cards i.e. host only, internal network and assigned a 192.168.0.1 address to fedora which is udhcpd and sent dhcp discover requests from udhcpc clients.

两者都在同一个接口上,即 eth0,我可以看到从 0.0.0.0 到 255.255.255.255 的 dhcp 发现广播请求.但是 udhcpd - dhcp 服务器,从不接收和响应请求.

Both are on the same interface i.e. eth0 and i can see the broadcast request from 0.0.0.0 to 255.255.255.255 for dhcp discover. But udhcpd - the dhcp server, never receives and answers the request.

我也尝试过首先为 dhcp 客户端分配一个 ip,即 192.168.0.2.

I also tried by assigning an ip to the dhcp client first i.e. 192.168.0.2.

但永远不会得到回应.

如果我使用 NAT 或其他模式,其中 Virtual box 自己的 dhcp 服务器正在运行,那么正是该服务器响应 dhcp discover 并且我的 udhcpd 仍然来自繁忙的 box 没有选择数据包.

If i use NAT or another mode in which Virtual box own's dhcp server is running, then it is that server which responds to the dhcp discover and still my udhcpd from busy box does not pick the packets.

感觉跟udhcpd服务器的子网掩码有关系.

I feel it has something to do with the subnet mask may be of udhcpd server.

有人知道吗?

推荐答案

糟糕的是,fedora VM(ip 表)中的防火墙默认阻止传入连接.

My bad, the firewall in fedora VM(ip tables) was blocking incoming connections by default.

这是允许这样做的方法.

Here is the way to allow that.

打开并编辑/etc/sysconfig/iptables

Open and edit /etc/sysconfig/iptables

vi/etc/sysconfig/iptables

vi /etc/sysconfig/iptables

将会有几个类似如下的条目:

There would be several entries like the following:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5800 -j ACCEPT

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5900 -j ACCEPT

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5900 -j ACCEPT

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 6000 -j ACCEPT

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 6000 -j ACCEPT

我为我的 dhcp 端口添加了一个条目,如下所示:

I added an entry for my dhcp port as follows:

-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 67 -j ACCEPT

保存并关闭文件.重启iptables:

Save and close the file. Restart iptables:

service iptables restart

请注意,命令在基于 ubuntu 或 debian 的 Linux 发行版上会有所不同,因为这些平台上的 ip 表可能不会作为服务运行.也寻找被广泛记录的操作系统特定操作.

Note that commands would differ on ubuntu or debian based Linux distribution because ip tables on these platforms might not run as a service. Look for OS specific manipulation too which is widely documented.

这篇关于如何让 dhcp 服务器侦听虚拟机 vm 中的广播请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-15 03:59