|
| 1 | +--- |
| 2 | +title: "Installing and Configuring a DHCP Server" |
| 3 | +linkTitle: "Install a DHCP Server" |
| 4 | +description: This guide walks you through setting up `isc-dhcp-server` on your xCore board. |
| 5 | +--- |
| 6 | + |
| 7 | +## Why Set Up a DHCP Server? |
| 8 | + |
| 9 | +The xCore board serves as the central hub in an internal network used by your robot. |
| 10 | +The xCore includes a microcontroller (STM32) which talks directly with the Linux system. To enable this, we create a private network on `eth0` with a static IP and assign dynamic IPs to connected devices using DHCP. |
| 11 | +The STM32 will acquire an IP address automatically. |
| 12 | + |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## Step 1: Set Static IP on `eth0` |
| 17 | + |
| 18 | +We will assign a static IP `172.16.78.1` to `eth0`. You can do this using the built-in network configuration utility: |
| 19 | + |
| 20 | +```bash |
| 21 | +sudo nmtui |
| 22 | +``` |
| 23 | + |
| 24 | +1. Select **Edit a connection** |
| 25 | +2. Choose your **Wired connection** |
| 26 | +3. Set **IPv4 Configuration** to **Manual** |
| 27 | +4. Add: |
| 28 | + - Address: `172.16.78.1` |
| 29 | + - Netmask: `255.255.255.0` |
| 30 | + - Gateway: leave blank |
| 31 | +5. Save and **Activate** the connection |
| 32 | + |
| 33 | +> 💡 You may also use `nmcli` instead: |
| 34 | +```bash |
| 35 | +sudo nmcli con mod "Wired connection 1" ipv4.method manual ipv4.addresses 172.16.78.1/24 |
| 36 | +sudo nmcli con up "Wired connection 1" |
| 37 | +``` |
| 38 | + |
| 39 | +Verify the result by running `ip -4 address show dev eth0`. |
| 40 | +The expected output should be: |
| 41 | +```bash |
| 42 | +robot@robot:~ $ ip -4 address show dev eth0 |
| 43 | +2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 |
| 44 | + inet 172.16.78.1/24 brd 172.16.78.255 scope global noprefixroute eth0 |
| 45 | + valid_lft forever preferred_lft forever |
| 46 | +``` |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +## Step 2: Install the DHCP Server |
| 51 | + |
| 52 | +```bash |
| 53 | +sudo apt-get update |
| 54 | +sudo apt-get install isc-dhcp-server -y |
| 55 | +``` |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## Step 3: Configure DHCP Server |
| 60 | + |
| 61 | +### Edit default interface |
| 62 | + |
| 63 | +Open `/etc/default/isc-dhcp-server`: |
| 64 | + |
| 65 | +```bash |
| 66 | +sudo nano /etc/default/isc-dhcp-server |
| 67 | +``` |
| 68 | + |
| 69 | +Find and modify this line: |
| 70 | + |
| 71 | +```bash |
| 72 | +INTERFACESv4="eth0" |
| 73 | +``` |
| 74 | + |
| 75 | +Save the configuration by pressing `CTRL+O`, `ENTER`. Then exit nano by pressing `CTRL+X`. |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +### Add DHCP configuration |
| 80 | + |
| 81 | +Edit the main DHCP config file: |
| 82 | + |
| 83 | +```bash |
| 84 | +sudo nano /etc/dhcp/dhcpd.conf |
| 85 | +``` |
| 86 | + |
| 87 | +Replace the config with the following: |
| 88 | + |
| 89 | +```conf |
| 90 | +default-lease-time 600; |
| 91 | +max-lease-time 7200; |
| 92 | +authoritative; |
| 93 | +
|
| 94 | +subnet 172.16.78.0 netmask 255.255.255.0 { |
| 95 | + interface eth0; |
| 96 | + range 172.16.78.150 172.16.78.200; |
| 97 | + option routers 172.16.78.1; |
| 98 | + option domain-name-servers 172.16.78.1; |
| 99 | + option domain-name "robot.local"; |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +## Step 4: Start the DHCP Server |
| 106 | + |
| 107 | +```bash |
| 108 | +sudo systemctl start isc-dhcp-server |
| 109 | +``` |
| 110 | + |
| 111 | +Enable it at boot: |
| 112 | + |
| 113 | +```bash |
| 114 | +sudo systemctl enable isc-dhcp-server |
| 115 | +``` |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +## Verification |
| 120 | + |
| 121 | +Run: |
| 122 | + |
| 123 | +```bash |
| 124 | +sudo systemctl status isc-dhcp-server |
| 125 | +``` |
| 126 | + |
| 127 | +Make sure the output includes `active (running)`. |
| 128 | + |
| 129 | +Try to ping your STM32: |
| 130 | +Get the assigned IP by running `cat /var/lib/dhcp/dhcpd.leases` |
| 131 | + |
| 132 | +**Example output:** |
| 133 | +```bash |
| 134 | +robot@robot:~ $ cat /var/lib/dhcp/dhcpd.leases |
| 135 | +# The format of this file is documented in the dhcpd.leases(5) manual page. |
| 136 | +# This lease file was written by isc-dhcp-4.4.3-P1 |
| 137 | + |
| 138 | +# authoring-byte-order entry is generated, DO NOT DELETE |
| 139 | +authoring-byte-order little-endian; |
| 140 | + |
| 141 | +server-duid "\000\001\000\001/\244\342\375,\317gJ\305\345"; |
| 142 | + |
| 143 | +lease 172.16.78.150 { |
| 144 | + starts 3 2025/04/30 13:33:05; |
| 145 | + ends 3 2025/04/30 13:43:05; |
| 146 | + cltt 3 2025/04/30 13:33:05; |
| 147 | + binding state active; |
| 148 | + next binding state free; |
| 149 | + rewind binding state free; |
| 150 | + hardware ethernet d8:47:8f:91:b9:6c; |
| 151 | +} |
| 152 | +``` |
| 153 | + |
| 154 | +Then you should be able to ping the STM32: |
| 155 | +```bash |
| 156 | +robot@robot:~ $ ping 172.16.78.150 |
| 157 | +PING 172.16.78.150 (172.16.78.150) 56(84) bytes of data. |
| 158 | +64 bytes from 172.16.78.150: icmp_seq=1 ttl=255 time=0.354 ms |
| 159 | +``` |
0 commit comments