2 Configuring Network Addressing

This chapter describes how to configure a DHCP server, DHCP client, and Network Address Translation.

About the Dynamic Host Configuration Protocol

The Dynamic Host Configuration Protocol (DHCP) enables client systems to obtain network configuration information from a DHCP server each time that they connect to the network. The DHCP server is configured with a range of IP addresses and other network configuration parameters that clients need.

When you configure an Oracle Linux system as a DHCP client, the client daemon, dhclient, contacts the DHCP server to obtain the networking parameters. As DHCP is broadcast-based, the client must be on the same subnet as either a server or a relay agent. If a client cannot be on the same subnet as the server, a DHCP relay agent can be used to pass DHCP messages between subnets.

The server provides a lease for the IP address that it assigns to a client. The client can request specific terms for the lease, such as the duration. You can configure a DHCP server to limit the terms that it can grant for a lease. Provided that a client remains connected to the network, dhclient automatically renews the lease before it expires. You can configure the DHCP server to provide the same IP address to a client based on the MAC address of its network interface.

The advantages of using DHCP include:

  • centralized management of IP addresses

  • ease of adding new clients to a network

  • reuse of IP addresses reducing the total number of IP addresses that are required

  • simple reconfiguration of the IP address space on the DHCP server without needing to reconfigure each client

For more information about DHCP, see RFC 2131.

Configuring a DHCP Server

To configure an Oracle Linux system as a DHCP server:

  1. Install the dhcp package:

    sudo yum install dhcp
  2. Edit the /etc/dhcp/dhcpd.conf file to store the settings that the DHCP server can provide to the clients.

    The following example configures the domain name, a range of client addresses on the 192.168.2.0/24 subnet from 192.168.2.101 through 192.168.2.254 together with the IP addresses of the default gateway and the DNS server, the default and maximum lease times in seconds, and a static IP address for the application server svr01 that is identified by its MAC address:

    option domain-name "mydom.org";
    option domain-name-servers 192.168.2.1, 10.0.1.4;
    option broadcast-address 192.168.2.255;
    option routers 192.168.2.1;
    
    subnet 192.168.2.0 netmask 255.255.255.0 {
      range 192.168.2.101 192.168.2.254;
      default-lease-time 10800;
      max-lease-time 43200;
    }
    
    host svr01 {
      hardware ethernet 80:56:3e:00:10:00;
      fixed-address 192.168.2.100;
      max-lease-time 86400;
    }

    The DHCP server sends the information in the option lines to each client when it requests a lease on an IP address. An option applies only to a subnet if you define it inside a subnet definition. In the example, the options are global and apply to both the subnet and host definitions. The subnet and host definitions have different settings for the maximum lease time.

    Note:

    In Oracle Linux 7, the DHCP server no longer reads its configuration from /etc/sysconfig/dhcpd. Instead, it reads /etc/dhcp/dhcpd.conf to determine the interfaces on which it should listen.

    For more information and examples, see /usr/share/doc/dhcp-version/dhcpd.conf.sample and the dhcpd(8) and dhcp-options(5) manual pages.

  3. Touch the /var/lib/dhcpd/dhcpd.leases file, which stores information about client leases:

    sudo touch /var/lib/dhcpd/dhcpd.leases
  4. Enter the following commands to start the DHCP service and ensure that it starts after a reboot:

    sudo systemctl start dhcpd
    sudo systemctl enable dhcpd

For information about configuring a DHCP relay, see the dhcrelay(8) manual page.

Configuring a DHCP Client

To configure an Oracle Linux system as a DHCP client:

  1. Install the dhclient package:

    sudo yum install dhclient
  2. Edit /container/name/rootfs/etc/sysconfig/network-scripts/ifcfg-iface , where iface is the name of the network interface, and change the value of BOOTPROTO to read as:

    BOOTPROTO=dhcp
  3. Edit /etc/sysconfig/network and verify that it contains the following setting:

    NETWORKING=yes
  4. To specify options for the client, such as the requested lease time and the network interface on which to request an address from the server, create the file /etc/dhclient.conf containing the required options.

    The following example specifies that the client should use the em2 interface, request a lease time of 24 hours, and identify itself using its MAC address:

    interface "em2" {
      send dhcp-lease-time 86400;
      send dhcp-client-identifier 80:56:3e:00:10:00;
    }

    For more information, see the dhclient.conf(5) manual page.

  5. Restart the network interface or the network service to enable the client, for example:

    sudo systemctl restart network

    When the client has requested and obtained a lease, information about this lease is stored in /var/lib/dhclient/dhclient-interface.leases.

For more information, see the dhclient(8) manual page.

About Network Address Translation

Network Address Translation (NAT) assigns a public address to a computer or a group of computers inside a private network with a different address scheme. The public IP address masquerades all requests as going to one server rather than several servers. NAT is useful for limiting the number of public IP addresses that an organization must finance, and for providing extra security by hiding the details of internal networks.

The netfilter kernel subsystem provides the nat table to implement NAT in addition to its tables for packet filtering. The kernel consults the nat table whenever it handles a packet that creates a new incoming or outgoing connection.

Note:

If your want a system to be able to route packets between two of its network interfaces, you must turn on IP forwarding:

echo 1 > /proc/sys/net/ipv4/ip_forward

You can use the Firewall Configuration GUI (firewall-config) to configure masquerading and port forwarding.