Ifconfig DHCP : Configure Your DHCP from the Command Line

ifconfig dhcpLinux/UNIX based systems offer an assortment of commands to their users to help them set up local networks as well as connect to the internet. The ifconfig command is the DHCP utility program that is found in Unix-based operating systems. It allows you to configure your TCP/IP address parameters, and to control and query it in general. If you’re familiar with Windows operating systems, you might recognize the ipconfig command that lets you access the Windows DHCP client. The ifconfig command in UNIX is similar to the ipconfig command. If you’re new to Linux and are unfamiliar with the basics, you can take this introductory course to Linux. Tweaking the DHCP configuration is fairly advanced stuff, so we don’t recommend that you do it unless you really know what you’re doing.

What is DHCP?

Before we explain the ifconfig command in detail, do you know what DHCP means exactly? DHCP stands for Dynamic Host Configuration Protocol. It is a network protocol that lets a server assign an IP address to a computer that is present on its network. This IP address is unique and no other computer on the network will have the same IP address. If you successfully receive an IP address from a DHCP server, you will be able to connect to and use the network the server has access to. DHCP servers are commonly used by Internet Service Providers (ISPs). When you connect to your internet, your ISP probably assigns you a unique IP address through the DHCP server. This IP address is reserved for you for the duration you are logged on. To learn more about network communication, try out this course.

Some ISPs assign static IP addresses as an alternative to dynamic IPs. Static IP addresses aren’t always the best alternative- other computers on the network may have the same static addresses as yours, which will cause conflicts. Using a DHCP to assign a unique address each time is usually the better option. If you’d like to understand TCP/IP better, this course can help you.

Ifconfig Commands to Configure DHCP

The most common use of the ifconfig command is to disable or enable an interface and to set up an interface IP address and netmask.  System administrators also use the command to receive information about the network interface parameters so they can troubleshoot problems, if any. (If you’d like to master Linux command lines, check out this course.)

We’ll give you ifconfig commands you’re most likely to need if you’re working with a DHCP server. If you’re using the DHCPv6 version, you need to specify the inet6 keyword after the inconfig command. If you’re using the DHCPv4 version, you just leave it blank:

Starting a DHCP client

ifconfig interface [inet6] dhcp start

This command lets you connect to the DHCP server. In technical terms, the dhcpagent that is present on your computer connects to the DHCP server and requests an IP address and configuration options for you. This command lets a user connected to a server access a changed configuration, which a system administrator might have updated in real time. For example: a new subnet mask value.

Request Network Parameters without the IP Address

ifconfig interface [inet6] dhcp inform

This commands returns the parameters of the network you are connected to, sans the IP address. The dhcpagent will connect to the DHCP server and request for the information. This command is mostly used on networks on which the computers have static addresses assigned to them. You already know the static address in such cases, but you don’t have the updated network information.

Releasing the IP Address

ifconfig interface [inet6] dhcp release

You may need to leave the network to join another one, or you may want to renew your current IP address. In such cases, you can use this command to release your IP address. In general, an IP address is released automatically when your session expires. This may happen at an interval (a few hours) or it may happen when you log off the network.

Releasing the IP Address without informing the DHCP Server

ifconfig interface [inet6] dhcp drop

What if you want to reboot your system and don’t want to lose IP address you’ve been assigned (so that your system administrator can track your network sessions better, for example)? You can do that with the ifconfig interface dhcp drop command. The dhcp command will stop your connection without information the remote server. This means that the DHCP server will keep reserving the IP address it assigned to your system earlier. You can now reboot and continue with the same IP address you’d been using.

Pinging the DHCP Server

ifconfig interface [inet6] dhcp ping

How do you determine if you’re connected to the DHCP server? You can ping it with the command given above. If you’re connected to the DHCP server, you will be returned a ping. If you’re not returned a ping, you’re either not connected to the server or there’s a problem with your connection. This command is useful for troubleshooting, but not as useful as the next command.

The current Network Interface DHCP Status

ifconfig interface [inet6] dhcp status

This is a very useful command- both for checking the status of the DHCP client and for troubleshooting. The command will return a lot of useful information. You can check to see if an IP address has been assigned to your system, if the interface you’ve set up is the primary interface ([PRIMARY]) and the number of requests your system made to the DHCP server. It will tell you how many requests were declined and accepted. You will also be able to see when the lease on your IP address was obtained and when an automatic renewal (if any) will occur.

Extending the Lease on the IP Address

ifconfig interface [inet6] dhcp extend

Sometimes you have to manually extend the lease on your IP address (though it generally happens automatically) or you may want to begin a new session. You can do that with the above command.

If you want to learn more ifconfig commands, you should check out the official source page of the version of UNIX you’re using. For example, the FreeBSD official webpage gives several additional in-depth commands. Alternatively, you can learn more about Linux/UNIX by signing up for this Linux crash course.