DHCP installation and configuration of Linux machines on VirtualBox

Source: Internet
Author: User

Because to simulate the DHCP environment in the home machine, but by the home machine and the network condition limit, finally thought is not possible to use the VirtualBox to simulate this kind of situation, said does, the following is my practice step.

1. First of all, in order to not affect the other machines in the home Internet and other virtual machine use, we allocate two network cards per virtual machine
The first NIC uses NAT mode to connect to the extranet.
The second NIC uses host-only mode to connect to the intranet.

2. Because VirtualBox will create a "VirtualBox host-only Ethernet Adapter" network by default, and this network will turn on the DHCP service by default, in order not to affect other virtual machines, we create a new host-only network

Open the network-only host (host-only) network, global settings, manage, and then add a network that is named "VirtualBox host-only Ethernet Adapter #2 ″ with the following configuration information:

Host virtual network Interface IPV4 address: 192.168.145.1ipv4 netmask: 255.255.255.0 DHCP Server Remember not to select "Enable Server"

3. Create a new two CentOS6 virtual machine, specify two network cards respectively
The first NIC uses NAT mode to connect to the extranet.
The second NIC uses the host-only mode, where you should remember to select the new "VirtualBox host-only Ethernet Adapter #2 ″ in the previous step.

4. Start the first virtual machine, we will use this machine as a DHCP server

4.1 Modify the network configuration, because "VirtualBox host-only Ethernet Adapter #2 ″ does not have DHCP enabled, so we want to specify a static IP for eth2, here we use the following configuration

address:192.168.145.101netmask:255.255.255.0gateway:192.168.145.1

Restart the network using the sudo service network restart after the modification is complete and use Ifconfig to view the network at this time

eth1 Link encap:ethernet HWaddr 08:00:27:1f:20:36 inet addr:10.0.2.15 bcast:10.0.2.255 mask:255.255. 255.0 Inet6 addr:fe80::a00:27ff:fe1f:2036/64 scope:link up broadcast RUNNING multicast mtu:1500 Metri          C:1 RX packets:18333 errors:0 dropped:0 overruns:0 frame:0  TX packets:11113 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:22103029  (21.0 MiB)  TX bytes:605438 (591.2 KiB) eth2 Link encap:ethernet HWaddr 08:00:27:06:c0:75 inet addr:192.168.145.101 bcast:192.168.145.255 mask:255.255.255.0 inet6 addr:fe80::a00:27ff:fe06:c075/64 scope:link up BROADCAS          T RUNNING multicast mtu:1500 metric:1 RX packets:131 errors:0 dropped:0 overruns:0 frame:0 TX packets:112 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:22247 (21. 7 KiB) TX bytes:22532 (22.0 KiB) ...
4.2 Installing DHCP packages

sudo yum install DHCP

4.3. Edit the DHCP configuration file/etc/dhcp/dhcpd.conf, you can refer to/usr/share/doc/dhcp-*/dhcpd.conf.sample, the following is the configuration file content I use

Ddns-update-style Interim;      #表示dhcp服务器和dns服务器的动态信息更新模式  ignore client-updates;          #忽略客户端更新   Subnet 192.168.145.0 netmask 255.255.255.0 {         #意思是我所分配的ip地址所在的网段为192.168.145.0 Subnet Mask is 255.255.255.0  range 192.168.145.200 192.168.145.210;             #租用IP地址的范围  option domain-name-servers ns.example.org;  Option Domain-name "example.org";  option routers 192.168.145.101;                    #路由器地址, here is the IP address of the current DHCP machine  option Subnet-mask 255.255.255.0;                  #子网掩码  default-lease-time;                            #默认租约时间  max-lease-time 7200;                               #最大租约时间}

4.4. Edit the/ETC/RC.D/INIT.D/DHCPD file to
USER=DHCPDGROUP=DHCPD Change to User=rootgroup=root

Note: If you do not make this modification, there will be "can ' t chown new lease File:operation not permitted" error in "/var/log/messages" file when starting DHCP.

4.5. Start the DHCP service

sudo service dhcpd start

5. Test, start the second virtual machine, and then use Ifconfig to view the network situation, you can see the IP address requested is 192.168.145.200

eth1 Link encap:ethernet HWaddr 08:00:27:1c:29:8a inet addr:10.0.2.15 bcast:10.0.2.255 mask:255.255. 255.0 Inet6 addr:fe80::a00:27ff:fe1c:298a/64 scope:link up broadcast RUNNING multicast mtu:1500 Metri          C:1 RX packets:15 errors:0 dropped:0 overruns:0 frame:0  TX packets:19 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:10383 (10.1 KiB) TX bytes:1935 (1.8 KiB) eth2 Link encap:ethernet HWaddr 08:00:27:e4:60:1a inet addr:192.168.145.20 0 bcast:192.168.145.255 mask:255.255.255.0 inet6 addr:fe80::a00:27ff:fee4:601a/64 scope:link up BROAD          CAST RUNNING multicast mtu:1500 metric:1 RX packets:53 errors:0 dropped:0 overruns:0 frame:0 TX packets:17 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:7049 (6.8 K IB) TX bytes:2430 (2.3 KiB) ...

DHCP installation and configuration of Linux machines on VirtualBox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.