Installation and configuration of DHCP for Linux machines on VirtualBox

Source: Internet
Author: User

Installation and configuration of DHCP for Linux machines on VirtualBox

Because the DHCP environment should be simulated on the home machine, but due to the limitations of the home machine and network conditions, I finally thought about whether VirtualBox can be used to simulate this situation, the following are my practical steps.

1. First, in order not to affect the Internet access and use of other virtual machines on the home, we assign two NICs to each virtual machine.
The first ENI uses the NAT mode to connect to the Internet.
The second ENI uses the Host-Only mode to connect to the Intranet.

2. virtualBox creates a "VirtualBox Host-Only Ethernet Adapter" network by default, and the DHCP service is enabled by default. To avoid affecting other virtual machines, we create a Host-Only network.

Choose manage> global Settings> network> Host-Only network, and add, A network named "VirtualBox Host-Only Ethernet Adapter #2" is generated. The configuration information is as follows:

Host Virtual Network Interface
IPv4 address: 192.168.145.1
IPv4 network mask: 255.255.255.0
 
DHCP server
Do not select "enable server"

3. Create two VMS for CentOS6 and specify two NICs respectively.
The first ENI uses the NAT mode to connect to the Internet.
The second Nic uses the Host-Only mode. 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 the DHCP server.

4.1 modify the network configuration. Because "VirtualBox Host-Only Ethernet Adapter #2" does not enable DHCP, We need to specify a static IP for eth2. Here we use the following configuration

Address: 192.168.145.101
Netmask: 255.255.255.0
Gateway: 192.168.145.1

After the modification, use "sudo service network restart" to restart the network. In this case, use ifconfig to view the network

...
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 Metric: 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 FIG: 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 broadcast 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 FIG: 1000
RX bytes: 22247 (21.7 KiB) TX bytes: 22532 (22.0 KiB)
...

4.2 install the dhcp Software Package

Sudo yum install dhcp

4.3. edit the dhcp configuration file/etc/dhcp/dhcpd. conf, see/usr/share/doc/dhcp-*/dhcpd. conf. sample. The following is the content of the configuration file I used.

Ddns-update-style interim; # indicates the dynamic information update mode of the dhcp server and dns Server
Ignore client-updates; # ignore client updates


Subnet 192.168.145.0 netmask 255.255.255.0 {# indicates that the IP address I allocated is in the CIDR Block 192.168.145.0 and the subnet mask is 255.255.255.0.
Range 192.168.145.200 192.168.145.210; # The range of rented IP addresses
Option domain-name-servers ns.example.org;
Option domain-name "example.org ";
Option routers 192.168.145.101; # vro address, which is the IP address of the current dhcp server
Option subnet-mask limit 255.0; # subnet mask
Default-lease-time 600; # default lease time
Max-lease-time 7200; # maximum lease time
Host myhost {# Set host Declaration
Hardware ethernet 08: 00: 27: 2C: 30: 8C; # specify the mac address of the dhcp Client
Fixed-address 192.168.145.155; # assign an ip address to the specified mac address
}
}

4.4. Edit the/etc/rc. d/init. d/dhcpd file

User = dhcpd
Group = dhcpd

Change

User = root
Group = root

Note: If this modification is not done, the "Can't chown new lease file: Operation not permitted" error will appear in the "/var/log/messages" file when DHCP is started.

4.5. Start the DHCP service

Sudo service dhcpd start

5. test and start the second virtual machine. Then, use ifconfig to view the network conditions. The requested IP address 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 Metric: 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 FIG: 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.200 Bcast: 192.168.145.255 Mask: 255.255.255.0
Inet6 addr: fe80: a00: 27ff: fee4: 601a/64 Scope: Link
Up broadcast 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 FIG: 1000
RX bytes: 7049 (6.8 KiB) TX bytes: 2430 (2.3 KiB)
...

 

Build a DHCP server in Linux

Configure the master-slave DNS server and DDNS under DHCP in CentOS

SUSE Linux 11 pxe + DHCP + tftp + ftp Unattended Installation

How to Set up a DHCP server in Linux

Step-by-step implementation of DHCP server in Linux

Build a DHCP server in CentOS 6.5

Setting up a DHCP server in Linux (RHEL5.2)

This article permanently updates the link address:

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.