Psychz - Raviteja
Votes: 0Posted On: Oct 25, 2017 05:14:57
This article will help you to configure the network on a CentOS 7 operating system. Configuring network on any operating system involves configuring an IP range for the system. Also, you have to decide whether you want to configure a static IP or dynamic IP. We will guide you towards configuring both.
Prerequisites
1) Operating system: CentOS 7
2) Minimum of one Active network interface
3) Root permission
Static IP configuration
Step 1 - Check the network interfaces by using the command:
ifconfig
The network configuration file in CentOS 7 is stored in “/etc/sysconfig/network-scripts”. There are multiple network files under “network-scripts” directory depending on the number of interfaces configured. The following steps will show you how to bind a range of IPs.
Step 2 - Edit the network interface file to which you want the static IP assigned.
vi /etc/sysconfig/network-scripts/ifcfg-enp2s0
Note: This file can be edited using a VI editor to configure static IP in the server. The different parameters to be added are:
BOOTPROTO – It is the protocol to be implemented during Boot time. It has to be changed to “static” for static IP configuration.
IPADDR – Edit the IP address in the IPADDR field
PREFIX – Add the IP range that has to be configured.
NETWORK – Add the network IP of the IP range.
GATEWAY – Add the Gateway IP
DNS - Add the address of the DNS server.
Save and close the file.
Step 3 - Restart the network services by the command
Systemctl restart network
DHCP Configuration on CentOS 7
DHCP server Installation
1.Please run the following command to install DHCP server.
yum -y install dhcp
2.Once the server is installed, copy the sample configuration file.
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
3.Once the sample configuration file is copied, we edit the configuration file using vi editor.
vi /etc/dhcp/dhcpd.conf
DHCP file configuration
1. Edit the "dhcpd.conf" file with the help of an editor and modify it as follows.
# specify domain name
option domain-name "linux.host";
# specify name server's hostname or IP address
option domain-name-servers dlp.srv.world;
# default lease time
default-lease-time 600;
# max lease time
max-lease-time 7200;
# If the DHCP server is to be declared valid
authoritative;
# specify network address and subnet mask
subnet 192.168.1.0 netmask 255.255.255.0 {
# specify the range of lease IP address
range dynamic-bootp 192.168.1.200 192.168.1.254;
# specify broadcast address
option broadcast-address 192.168.1.255;
# specify default gateway
option routers 192.168.1.1;
}
As we can see in the latter part of this configuration, a subnet "192.168.1.0" is defined with a netmask of 255.255.255.0, that is 256 IPs. Also, default lease time of 600 is provided which means that the DHCP will reserve an IP for only 600 seconds by default. The maximum lease time that can be allotted is set to 7200 seconds.
Other parameters that are provided are the broadcast address, the DNS servers among others.
The following command is used to make this DHCP server the official DHCP server for the local network.
authoritative;
Once the changes are made, restart the DHCP service for the changes to take effect.
systemctl start dhcpd
systemctl enable dhcpd