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.
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.1IPv4 network mask: 255.255.255.0 DHCP server remember not to select "enable server"
3. Create two VMS for CentOS6 and specify two NICs respectively.
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.101Netmask: 255.255.255.0Gateway: 192.168.145.1
...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 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 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 txqueuelen:1000 RX bytes:22247 (21.7 KiB) TX bytes:22532 (22.0 KiB)...
4.2 install the dhcp Software Package
sudo yum install dhcp
Ddns-update-style interim; # indicates the dynamic information update mode of dhcp server and dns server ignore client-updates; # ignore client updates subnet 192.168.145.0 netmask 255.255.255.0 {# It means that the IP address I allocated is in the network segment 192.168.145.0 subnet mask 255.255.255.255.0 range 192.168.145.200 192.168.145.210; # The IP address range of the lease is option domain-name-servers ns.example.org; option domain-name "example.org"; option routers 192.168.145.101; # vro address, here is the IP address of the current dhcp machine option subnet-mask 255.255.255.0; # default subnet mask-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 fixed-address 192.168.145.155 of the dhcp client; # allocating ip addresses to the specified mac address }}
User = dhcpd group = dhcpd to 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
...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 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.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 txqueuelen:1000 RX bytes:7049 (6.8 KiB) TX bytes:2430 (2.3 KiB)...