Skip to content

Latest commit

 

History

History
195 lines (137 loc) · 4.29 KB

dhcp.md

File metadata and controls

195 lines (137 loc) · 4.29 KB

DHCP

Dynamic Host Configuration Protocol - broadcasts for an IP address on the local LAN network at layer 2 using Mac addresses.

A DHCP server receives this and responds with an IP address from its preconfigured pool of IP addresses.

This IP lease is usually for 24 hours. If the client renews it before the expiry it keeps the address, otherwise the IP returns to the pool and will be reassigned to another client when it requests an IP.

DHCP Clients

DHClient

https://linux.die.net/man/8/dhclient

dhclient

DHCP Servers

ISC DHCPd

https://www.isc.org/dhcp/

Available on Linux and Mac.

Battle tested but deprecated.

Being replaced by Kea

https://www.isc.org/dhcp_migration/

DHCP Test Clients

DHCPing

Install on Mac:

brew install dhcping

Without specifying the expected -s it seems to get no answer. I'm sure this behaviour was different on Linux back in the day... or perhaps I'm thinking of a different DHCP testing client...

sudo dhcping -s 192.168.1.254

output:

Got answer from: 192.168.1.254

DHCPdump

brew install dhcpdump
sudo dhcpdump -i en0

Mac DHCP Server + PXE boot install Debian Linux

Run DHCP to point to your TFTP Server for PXE boot

Install ISC DHCPd:

brew install isc-dhcp

Remind yourself of the start commands and config location later if you need it:

brew info isc-dhcp

Create a file /opt/homebrew/etc/dhcpd.conf with contents like this, change the IP addresses to suit your needs:

# dhcpd.conf
#
# for ISC dhcpd

# ignore this
option domain-name "hari.org";
# public DNS - you don't need to change this
option domain-name-servers 4.2.2.1, 4.2.2.2;

allow booting;
allow bootp;

default-lease-time 600;
max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

log-facility local7;

# XXX: Edit IPs
subnet 192.168.1.0 netmask 255.255.255.0 {
  range dynamic-bootp 192.168.1.3 192.168.1.253;  # XXX: Edit
  option routers 192.168.1.254;  # XXX: Edit
  filename       "/pxelinux.0";
  next-server    192.168.1.89;  # XXX: Edit
}

Run dhcpd in the foreground for a little while:

sudo /opt/homebrew/opt/isc-dhcp/sbin/dhcpd -f -cf /opt/homebrew/etc/dhcpd.conf en0

Download Debian netinstall to TFTP for PXE boot

from DevOps-Bash-tools:

debian_netinstall_pxesetup.sh

This sets up /private/tftpboot directory with the Debian stable distribution.

Start TFTP

You can start it manually on the command line or download TftpServer to easily start/stop the built-in Mac tftp server via a GUI.

Start the the tftp server which will serve out /private/tfpboot.

WARNING: TFTP is unauthenticated and accessible to anybody on the network, do not put anything in there that is sensitive and do not run it longer than you have to

You can also start the TFTP server manually:

Manual CLI Method

Ensure the file /System/Library/LaunchDaemons/tftp.plist exists with this contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <true/>
    <key>Label</key>
    <string>com.apple.tftpd</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/libexec/tftpd</string>
        <string>-i</string>
        <string>/private/tftpboot</string>
    </array>
    <key>inetdCompatibility</key>
    <dict>
        <key>Wait</key>
        <true/>
    </dict>
    <key>InitGroups</key>
    <true/>
    <key>Sockets</key>
    <dict>
        <key>Listeners</key>
        <dict>
            <key>SockServiceName</key>
            <string>tftp</string>
            <key>SockType</key>
            <string>dgram</string>
        </dict>
    </dict>
</dict>
</plist>

Start tftpd:

sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist
sudo launchctl start com.apple.tftpd

At this point you can PXE boot and install off the network.

When done, stop tftpd:

sudo launchctl stop com.apple.tftpd
sudo launchctl unload /System/Library/LaunchDaemons/tftp.plist