我试图在两台VirtualBox机器上实现DHCP,这两台机器都运行Ubuntu16.10(一台作为客户端,一台作为服务器),主机是Windows 10。
我该怎么做呢?
一步一步的教程将是非常感谢的,因为我是一个初学者。
发布于 2017-04-18 10:30:39
首先,我们应该确保我们的VM与互联网的连接,我们将通过在每台机器上启用NAT适配器来实现这一点(如果还没有启用),我们的机器也应该坐在同一个网络上,所以我们将创建一个仅限于主机的网络,并通过向每台机器添加一个新的主机--只有适配器--来添加这两台机器。
在“VirtualBox from file
”菜单中选择“preferences
”,在“VirtualBox首选项”窗口中选择“网络”,然后选择“仅承载网络”。毕竟,通过单击+
标志,添加一个新的主机专用网络。
中
现在,对于这两台Ubuntu虚拟机,右击每个虚拟机,选择settings
,转到网络部分。确保Adapter 1
是活动的,并附加到Nat
上,单击Adapter 2
,检查Enable Network Adapter
并为Attached to
选择Host-Only adapter
。单击“确定”保存这些设置。
我们将使用dnsmasq
作为我们的DHCP,它相当小,对我们的目的来说已经足够好了,所以要安装它,运行:
sudo apt-get install dnsmasq
然后,我们应该启用dnsmasq功能,在这样做之前,我们可以通过运行以下命令查看或网络接口:
ifconfig -a
我们应该得到类似的东西:
enp0s3
是或第一个适配器,您还记得Nat接口吗?它已经有了一个IP (10.0.2.15),我们与这个接口没有任何关系,我们只是创建它来访问Internet,如果需要安装一些东西等等。
enp0s8
连接到我们的vboxnet0
网络,我们只是在第一节中创建它,我们应该将这个接口列表到DHCP请求并响应它们。
现在让我们回到为dnsmas
启用DHCP服务器功能,只需运行以下命令:
sudo nano /etc/dnsmasq.conf
它将在dnsmasq
编辑器中打开nano
配置文件。有一些行我们应该取消注释并将我们的配置添加到这些行中:
interface=enp0s8
bind-interfaces
dhcp-range=192.168.100.10,192.168.100.20,24h
您也可以将它们粘贴到这个配置文件中,对于interface
,我们应该使用enp0s8
,我们刚刚讨论过了吧?
dhcp-range
是我们要分配给请求的范围,从:192.168.100.10
到192.168.100.20
,租约时间为24
小时。
现在我们应该给我们的enp0s8
接口一个IP地址,例如:
sudo ifconfig enp0s8 192.168.100.1
sudo ifconfig enp0s8 up
您也可以编辑interfaces
文件并为此接口分配静态IP。
毕竟,我们应该启动dnsmasq
守护进程:
sudo systemctl start dnsmasq.service
打开您的另一台Ubuntu机器,它应该在默认情况下安装了网络管理器,并且到这个网络的连接应该已经存在了。默认方法是使用DHCP,所以您不必做任何事情。只要启用新的网络,名称应该是Wired Connection 2
,并完成,您的接口将得到一个IP。
如果您查看网络信息,可以看到此接口的IP位于我们在DHCP服务器中设置的范围内:
您还可以运行sudo dhclient enp0s3
,以获得用于enp0s3接口的IP。
发布于 2017-04-18 09:08:55
首次安装dhcp server
sudo apt install isc-dhcp-server
然后选择接口卡与威尔dhcp server
工作。
sudo nano /etc/default/isc-dhcp-server
# Defaults for isc-dhcp-server initscript
# sourced by /etc/init.d/isc-dhcp-server
# installed at /etc/default/isc-dhcp-server by the maintainer scripts
#
# This is a POSIX shell fragment
#
# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPD_CONF=/etc/dhcp/dhcpd.conf
# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPD_PID=/var/run/dhcpd.pid
# Additional options to start dhcpd with.
# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACES="eth0"
在这种情况下,nic是eth0
配置子网
sudo nano /etc/dhcp/dhcpd.conf
所有及以上的评论把这个
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.xxx 192.168.0.xxx;
option routers 192.168.0.x;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.0.255;
option domain-name-servers xxx.xxx.xxx.xxx;
default-lease-time 86400;
max-lease-time 86400;
}
重新启动服务
sudo service isc-dhcp-server restart
对于客户端,可以通过dhcp
选择car配置。
试试看。
https://askubuntu.com/questions/906151
复制相似问题