Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

DHCP

DHCP (short for Dynamic Host Configuration Protocol) is a client/server protocol that enables a
server to automatically assign an IP address and other related configuration parameters (such as the
subnet mask and default gateway) to a client on a network.
DHCP is important because it prevents a system or network administrator from manually
configuring IP addresses for new computers added to the network or computers that are moved from
one subnet to another.
The IP address assigned by a DHCP server to a DHCP client is on a “lease”, the lease time
normally varies depending on how long a client computer is likely to require the connection or the
DHCP configuration.

Installing DHCP Server in Ubuntu/CentOS


The DCHP server package is available in the official repositories of mainstream Linux
distributions, installing is quite easy, simply run the following command.
# yum install dhcp #CentOS
$ sudo apt install isc-dhcp-server #Ubuntu

Once the installation is complete, configure the interface on which you want the DHCP daemon to
serve requests in the configuration file /etc/default/isc-dhcp-server or /etc/sysconfig/dhcpd.
# vim /etc/sysconfig/dhcpd #CentOS
$ sudo vim /etc/default/isc-dhcp-server #Ubuntu

For example, if you want the DHCPD daemon to listen on eth0, set it using the following
directive.
DHCPDARGS=”eth0”

Save the file and exit.

Configuring DHCP Server in CentOS and Ubuntu


The main DHCP configuration file is located at /etc/dhcp/dhcpd.conf, which should
contain settings of what to do, where to do something and all network parameters to provide to the
clients.
This file basically consists of a list of statements grouped into two broad categories:
• Global parameters: specify how to carry out a task, whether to carry out a task, or what
network configuration parameters to provide to the DHCP client.
• Declarations: define the network topology, state a clients is in, offer addresses for the
clients, or apply a group of parameters to a group of declarations.
Now, open and edit the configuration file to configure your DHCP server.
------------ On CentOS ------------
# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
# vi /etc/dhcp/dhcpd.conf
------------ On Ubuntu ------------
$ sudo vim /etc/dhcp/dhcpd.conf

Start by defining the global parameters which are common to all supported networks, at the top of
the file. They will apply to all the declarations:
option domain-name "tecmint.lan";
option domain-name-servers ns1.tecmint.lan, ns2.tecmint.lan;
default-lease-time 3600;
max-lease-time 7200;
authoritative;

Next, you need to define a sub-network for an internal subnet i.e 192.168.1.0/24 as shown.
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option domain-search "tecmint.lan";
option domain-name-servers 192.168.1.1;
range 192.168.10.10 192.168.10.100;
range 192.168.10.110 192.168.10.200;
}

Note that hosts which require special configuration options can be listed in host statements (see the
dhcpd.conf man page).
Now that you have configured your DHCP server daemon, you need to start the service for the
mean time and enable it to start automatically from the next system boot, and check if its up and
running using following commands.
------------ On CentOS ------------
# systemctl start dhcpd
# systemctl enable dhcpd
# systemctl enable dhcpd

------------ On Ubuntu ------------


$ sudo systemctl start isc-dhcp-server
$ sudo systemctl enable isc-dhcp-server
$ sudo systemctl enable isc-dhcp-server

Next, permit requests to the DHCP daemon on Firewall, which listens on port 67/UDP, by running.
------------ On CentOS ------------
# firewall-cmd --zone=public --permanent --add-service=dhcp
# firewall-cmd --reload

#------------ On Ubuntu ------------


$ sudo ufw allow 67/udp
$ sudo ufw reload

Configuring DHCP Clients


Finally, you need to test if the DHCP server is working fine. Logon to a few client machines on the
network and configure them to automatically receive IP addresses from the server.
Modify the appropriate configuration file for the interface on which the clients will auto-receive IP
addresses.
DHCP Client Setup on CentOS
On CentOS, the interface config files ate located at /etc/sysconfig/network-scripts/.
# vim /etc/sysconfig/network-scripts/ifcfg-eth0

Add the options below:


DEVICE=eth0
BOOTPROTO=dhcp
TYPE=Ethernet
ONBOOT=yes

Save the file and restart network service (or reboot the system).
# systemctl restart network

DHCP Client Setup on Ubuntu


On Ubuntu 16.04, you can configure all interface in the config file /etc/network/interfaces.

$ sudo vi /etc/network/interfaces

Add these lines in it:


auto eth0
iface eth0 inet dhcp

Save the file and restart network services (or reboot the system).
$ sudo systemctl restart networking

On Ubuntu 18.04, networking is controlled by the Netplan program. You need to edit the
appropriate file under the directory /etc/netplan/, for example.
$ sudo vim /etc/netplan/01-netcfg.yaml

Then enable dhcp4 under a specific interface for example under ethernets, ens0, and comment out
static IP related configs:
network:
version: 2
renderer: networkd
ethernets:
ens0:
dhcp4: yes

Save the changes and run the following command to effect the changes.
$ sudo netplan apply

For more information, see the dhcpd and dhcpd.conf man pages.
$ man dhcpd
$ man dhcpd.conf
What is Telnet ?
Telnet is an old network protocol that is used to connect to remote systems over a TCP/IP network.
It connects to servers and network equipment over port 23. Let’s take a look at Telnet command
usage.
It uses a TELNET protocol. However, this protocol has some security defects, but it is one of the
most used networking protocols due to its simplicity. It is not a secure protocol because it transfers
data in unencrypted form. Often Linux user prefers ssh over telnet because ssh transfers data in
encrypted form. This utility is similar to the Remote Desktop feature in Windows. The syntax for
the telnet is as Follows:
1. telnet hostname/IP address

Telnet has been successfully installed and ready for use. Like in the previous example in CentOS 7,
you need to create a login user and log in using the same syntax.

Using telnet to check for open ports


Telnet can also be used to check if a specific port is open on a server. To do so, use the syntax
below.
$ telnet server-IP port

For example, to check if port 22 is open on a server, run


$ telnet 38.76.11.19 22

Sample Output

Installation of Telnet in Ubuntu 18.04


To install telnet protocol in Ubuntu 18.04 execute:
$ sudo apt install telnetd -y

Sample Output
To check whether telnet service is running, execute the command.
$ systemctl status inetd

Sample Output

Next, we need to open port 23 in ufw firewall.


$ ufw allow 23/tcp

Sample Output

Finally, reload the firewall to effect the changes.


$ ufw reload

Telnet has been successfully installed and ready for use.


Creating a login user

In this example, we will create a login user for logging in using the telnet protocol.
# adduser telnetuser

Create a password for the user.

# passwd telnetuser

Specify the password and confirm.


To use telnet command to log in to a server, use the syntax below.
$ telnet server-IP address

For example
$ telnet 38.76.11.19

In the black console, specify the username and password.

Using telnet to check for open ports

Telnet can also be used to check if a specific port is open on a server. To do so, use the syntax
below.
$ telnet server-IP port

For example, to check if port 22 is open on a server, run


$ telnet 38.76.11.19 22

Sample Output

Linux ifconfig
The command ifconfig stands for interface configurator. This command enables us to initialize an
interface, assign IP address, enable or disable an interface. It display route and network interface.
You can view IP address, MAC address and MTU (Maximum Transmission Unit) with ifconfig
command.
Syntax:

1. ifconfig

Look at the above snapshot, it shows the IP address of all three that is eth, lo and wlan.

Get details of specific interface


To find IP address of all three differently, use command
1. ifconfig eth0
2. ifconfig lo
3. ifconfig wlan0
Assigning IP address and Gateway
You can assign IP address and Gateway to an interface but these settings will be disabled after
system reboot.
Syntax:
1. ifconfig eth0 <address> netmask <address>

Enable or Disable specific interface


To enable specific interface,
1. ifup eth0
To disable specific interface,
1. ifdown eth0
Setting MTU size
By default MTU (Maximum Transmission Unit) size is 1500, you can change size as per your wish.
1. Ifconfig eth0 mtu xxxx

2. Replace xxxx with size.

You might also like