Dhcp enable in linux

Dynamic Host Configuration Protocol (DHCP)

The Dynamic Host Configuration Protocol (DHCP) is a network service that enables host computers to be automatically assigned settings from a server as opposed to manually configuring each network host. Computers configured to be DHCP clients have no control over the settings they receive from the DHCP server, and the configuration is transparent to the computer’s user.

note: this package was called dhcp3-server in versions prior to precise 12.04 LTS.

Installation

At a terminal prompt, enter the following command to install dhcpd:

sudo apt-get install isc-dhcp-server

You will probably need to change the default configuration by editing /etc/dhcp3/dhcpd.conf to suit your needs and particular configuration.

You also need to edit /etc/default/isc-dhcp-server to specify the interfaces dhcpd should listen to. By default it listens to eth0.

Also, you have to assign a static ip to the interface that you will use for dhcp. If you will use eth0 for providing addresses in the 192.168.1.x subnet then you should assign for instance ip 192.168.1.1 to the eth0 interface using NetworkManager. Without this step you will get an error from dhcpd when starting the service.

Configuration

The error message the installation ends with might be a little confusing, but the following steps will help you configure the service:

Most commonly, what you want to do is assign an IP address randomly. This can be done with settings as follows:

# Sample /etc/dhcpd.conf # (add your comments here) default-lease-time 600; max-lease-time 7200; option subnet-mask 255.255.255.0; option broadcast-address 192.168.1.255; option routers 192.168.1.254; option domain-name-servers 192.168.1.1, 192.168.1.2; option domain-name "mydomain.example"; subnet 192.168.1.0 netmask 255.255.255.0 range 192.168.1.10 192.168.1.100; range 192.168.1.150 192.168.1.200; >

This will result in the DHCP server giving a client an IP address from the range 192.168.1.10-192.168.1.100 or 192.168.1.150-192.168.1.200. It will lease an IP address for 600 seconds if the client doesn’t ask for a specific time frame. Otherwise the maximum (allowed) lease will be 7200 seconds. The server will also «advise» the client that it should use 255.255.255.0 as its subnet mask, 192.168.1.255 as its broadcast address, 192.168.1.254 as the router/gateway and 192.168.1.1 and 192.168.1.2 as its DNS servers.

If you need to specify a WINS server for your Windows clients, you will need to include the netbios-name-servers option, e.g.

option netbios-name-servers 192.168.1.1;

Start and stop service

sudo service isc-dhcp-server restart sudo service isc-dhcp-server start sudo service isc-dhcp-server stop

dhcp3-server and multiple interfaces

Источник

Читайте также:  Linux and windows utc

How to configure the Ubuntu DHCP client

Dynamic Host Configuration Protocol, abbreviated as DHCP, is a client-server protocol that enables a DHCP server to assign an IP address and other related configuration parameters such as default gateway and subnet mask to a DHCP client on a network.

The DHCP protocol is necessary because it prevents network or system administrators from manually configuring IP addresses for new machines added to the network or computer system that are moved from one subnet to another.

Through the ’lease’, the DHCP server allocates the IP addresses to the DHCP clients. The lease time depends on how long the client system requires the connection or DHCP configuration.

We will talk about the configuration of a DHCP client on Ubuntu Linux distribution in this article. We have assumed in this article that the DHCP server is already set up on your other machine, or you can also install it from this URL.

DHCP client configuration on Ubuntu

To set up the DHCP client on your Ubuntu system, first, check the network interface name by running the following command:

Once the network interface name is identified, you need to make some changes to the network interfaces file for DHCP client configuration. So, open the ‘/etc/network/interfaces’ file in your favorite text editor by using the following command:

Now, use the following syntax to configure the dhcp client:

Here, the network interface name is ‘enp1s0’; we have changed the above lines into the following format:

Save and close the above configuration file. Now, restart the network manager services by running the following command:

Verify the NetworkManager service running status by executing the following command:

When during the booting process, this system should request network parameters from the DHCP server.

To manually execute the DHCP process, the dhclient command can be used. If the DHCP server assigns no IP to the DHCP client, then use the following command renew or release the IP address. Wait for a while; the DHCP server will automatically assign IP addresses to the client machine.

Using the ‘ifconfig’ command can view the interface name.

Configure DHCP through netplan

In most Ubuntu distribution, networking is controlled or managed through the netplan program. Therefore, in this situation, you need to edit the netplan configuration files. To edit the appropriate file configuration, navigate into the ‘/etc/netplan’ directory and open that file.

Add the following lines in this file:

Save the above configuration by using ‘Ctrl+O’ in this file and exit from this window by pressing ‘Ctrl+x’.

Now, run the below-mentioned command to apply changes:

Читайте также:  Add debian repo to astra linux

Configure DHCP client through Ubuntu desktop environment

You can also use another virtual machine with Ubuntu 20.04 Desktop as a DHCP client. In Ubuntu, the default configuration method is set as DHCP. If it does not take an IP director from the DHCP server, change the IPV4 setting of your network. Click go into the ‘Setting’ and move into the network wired or wireless settings. The following window should display on your system:

Set your entire IPV4 configuration similar to the above-displayed screenshot.

Now, show the network details by clicking on the ‘Detail’ tab as follows:

Verify the configuration by running the following command:

You will see that the IP is allocated to the network interface.

You can also use the host machine on your system as a DHCP client. However, to get IP, do not reboot your host machine because, in this case, Virtualbox will be powered down, so there is no DHCP running on the system.

It is important to note that if you are using mobile devices or host machines as a DHCP client, most of the chances are that they have already been connected to this network. However, they will request the same IP to the DHCP server that was allocated before. However, if the IP does not fall in your defined range then, a request will be sent to the router.

Conclusion

We have seen in this article how to configure a DHCP client using different ways on Ubuntu distribution. All commands we have implemented on the Ubuntu 20.04 environment. DHCP client configuration is very simple. So that, in just a few minutes, you can easily set up a DHCP client on your system using the above-mentioned steps.

About the author

Samreena Aslam

Samreena Aslam holds a master’s degree in Software Engineering. Currently, she’s working as a Freelancer & Technical writer. She’s a Linux enthusiast and has written various articles on Computer programming, different Linux flavors including Ubuntu, Debian, CentOS, and Mint.

Источник

About Dynamic Host Configuration Protocol (DHCP)

The Dynamic Host Configuration Protocol (DHCP) is a network service that enables host computers to be automatically assigned settings from a server as opposed to manually configuring each network host. Computers configured to be DHCP clients have no control over the settings they receive from the DHCP server, and the configuration is transparent to the computer’s user.

The most common settings provided by a DHCP server to DHCP clients include:

  • IP address and netmask
  • IP address of the default-gateway to use
  • IP addresses of the DNS servers to use

However, a DHCP server can also supply configuration properties such as:

The advantage of using DHCP is that any changes to the network, such as a change in the DNS server address, only need to be changed at the DHCP server, and all network hosts will be reconfigured the next time their DHCP clients poll the DHCP server. As an added advantage, it is also easier to integrate new computers into the network, as there is no need to check for the availability of an IP address. Conflicts in IP address allocation are also reduced.

Читайте также:  Linux iso virtual machine

DHCP configuration

A DHCP server can provide configuration settings using the following methods:

Manual allocation (MAC address)

This method uses DHCP to identify the unique hardware address of each network card connected to the network, and then supplies a static configuration each time the DHCP client makes a request to the DHCP server using that network device. This ensures that a particular address is assigned automatically to that network card, based on its MAC address.

Dynamic allocation (address pool)

In this method, the DHCP server assigns an IP address from a pool of addresses (sometimes also called a range or scope) for a period of time (known as a lease) configured on the server, or until the client informs the server that it doesn’t need the address anymore. This way, the clients receive their configuration properties dynamically and on a “first come, first served” basis. When a DHCP client is no longer on the network for a specified period, the configuration is expired and released back to the address pool for use by other DHCP clients. After the lease period expires, the client must renegotiate the lease with the server to maintain use of the same address.

Automatic allocation

Using this method, the DHCP automatically assigns an IP address permanently to a device, selecting it from a pool of available addresses. Usually, DHCP is used to assign a temporary address to a client, but a DHCP server can allow an infinite lease time.

The last two methods can be considered “automatic” because in each case the DHCP server assigns an address with no extra intervention needed. The only difference between them is in how long the IP address is leased; in other words, whether a client’s address varies over time.

Available servers

Ubuntu makes two DHCP servers available:

  • isc-dhcp-server :
    This server installs dhcpd , the dynamic host configuration protocol daemon. Although Ubuntu still supports isc-dhcp-server , this software is no longer supported by its vendor. Find out how to install and configure isc-dhcp-server .
  • isc-kea :
    Kea was created by ISC to replace isc-dhcp-server – It is supported in Ubuntu releases from 23.04 onwards. Find out how to install and configure isc-kea .

References

  • The isc-dhcp-server Ubuntu Wiki page has more information.
  • For more /etc/dhcp/dhcpd.conf options see the dhcpd.conf man page.
  • ISC dhcp-server
  • ISC Kea Documentation

Источник

Оцените статью
Adblock
detector