2022-05-20 21:19:06 +02:00
|
|
|
---
|
2022-12-16 11:46:32 +01:00
|
|
|
title: "DHCP Server and Routing"
|
2022-11-19 15:25:20 +01:00
|
|
|
visible: true
|
2022-05-20 21:19:06 +02:00
|
|
|
---
|
|
|
|
|
2022-06-06 18:36:45 +02:00
|
|
|
[toc]
|
2022-12-16 11:46:32 +01:00
|
|
|
|
2022-05-20 21:19:06 +02:00
|
|
|
## Installation
|
2022-12-16 11:46:32 +01:00
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[shroot]
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
```sh
|
|
|
|
apt install isc-dhcp-server
|
|
|
|
```
|
2022-05-20 21:19:06 +02:00
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[/shroot]
|
|
|
|
|
2022-05-20 21:19:06 +02:00
|
|
|
## Configuration
|
2022-12-16 11:46:32 +01:00
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
Edit `/etc/default/isc-dhcp-server`
|
|
|
|
|
|
|
|
```
|
2023-06-02 19:25:19 +02:00
|
|
|
INTERFACESv4="[INTERFACE 1] [INTERFACE 2]"
|
2023-02-19 15:21:41 +01:00
|
|
|
```
|
2022-12-16 11:46:32 +01:00
|
|
|
|
|
|
|
Edit `/etc/dhcp/dhcpd.conf` to set a subnet
|
2022-05-20 21:19:06 +02:00
|
|
|
|
|
|
|
```
|
2023-06-02 19:25:19 +02:00
|
|
|
subnet [NETADDRESS] netmask [SUBNETMASK] {
|
|
|
|
range [FIRST DHCP] [LAST DHCP];
|
|
|
|
option subnet-mask [SUBNETMASK];
|
|
|
|
option routers [GATEWAY];
|
|
|
|
option domain-name "[NAME]";
|
|
|
|
option domain-name-servers [DNS SERVER];
|
2022-05-20 21:19:06 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-12-16 11:46:32 +01:00
|
|
|
Edit `/etc/network/interfaces`
|
|
|
|
|
2022-05-20 21:19:06 +02:00
|
|
|
```
|
2023-06-02 19:25:19 +02:00
|
|
|
auto [INTERFACE]
|
|
|
|
iface [INTERFACE] inet static
|
|
|
|
address [ADDRESS]
|
|
|
|
network [NETADDRESS]
|
|
|
|
netmask [NETMASK]
|
|
|
|
broadcast [BROADCAST]
|
2022-05-20 21:19:06 +02:00
|
|
|
```
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
Enable the interface
|
2022-05-20 21:19:06 +02:00
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[shroot]
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
```sh
|
2023-06-02 19:25:19 +02:00
|
|
|
ifup [INTERFACE]
|
2023-02-19 15:21:41 +01:00
|
|
|
```
|
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[/shroot]
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
Restart DHCP Server
|
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[shroot]
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
```sh
|
|
|
|
systemctl restart isc-dhcp-server.service
|
|
|
|
```
|
2022-05-20 21:19:06 +02:00
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[/shroot]
|
|
|
|
|
2022-05-20 21:19:06 +02:00
|
|
|
### Enable routing
|
2022-12-16 11:46:32 +01:00
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[shroot]
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
```sh
|
|
|
|
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.d/80-forwarding.conf
|
|
|
|
sysctl -p /etc/sysctl.d/80-forwarding.conf
|
|
|
|
```
|
2022-05-20 21:19:06 +02:00
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[/shroot]
|
|
|
|
|
|
|
|
[shroot]
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
```sh
|
2023-06-02 19:25:19 +02:00
|
|
|
iptables -t nat -A POSTROUTING -o [WAN INTERFACE] -j MASQUERADE
|
|
|
|
iptables -A FORWARD -i [LAN INTERFACE] -j ACCEPT
|
2023-02-19 15:21:41 +01:00
|
|
|
```
|
2022-05-20 21:19:06 +02:00
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[/shroot]
|
|
|
|
|
2022-05-20 21:19:06 +02:00
|
|
|
Make iptables permanent
|
2023-02-19 15:21:41 +01:00
|
|
|
Select `Yes` during the installation to save current rules
|
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[shroot]
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
```sh
|
|
|
|
apt install iptables-persistent
|
|
|
|
```
|
2022-05-20 21:19:06 +02:00
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[/shroot]
|
|
|
|
|
2022-05-20 21:19:06 +02:00
|
|
|
### Enable DHCP-managed fixed IP address
|
2022-12-16 11:46:32 +01:00
|
|
|
|
2022-05-20 21:19:06 +02:00
|
|
|
```
|
2023-06-02 19:25:19 +02:00
|
|
|
host [HOSTNAME] {
|
|
|
|
hardware ethernet [MAC ADDRESS];
|
|
|
|
fixed-address [IP ADDRESS];
|
2022-05-20 21:19:06 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Dynamic DNS
|
2022-12-16 11:46:32 +01:00
|
|
|
|
|
|
|
_Needs a supported DNS like BIND or PowerDNS_
|
2023-09-27 18:35:51 +02:00
|
|
|
[Configure your DNS server to accept updates](/linux/services/powerdns)
|
2022-05-20 21:19:06 +02:00
|
|
|
Add the following snippet to your `/etc/dhcp/dhcpd.conf` file
|
2022-12-16 11:46:32 +01:00
|
|
|
How to generate the key is also described in the DNS article
|
2022-05-20 21:19:06 +02:00
|
|
|
|
2022-12-16 11:46:32 +01:00
|
|
|
```
|
2022-05-20 21:19:06 +02:00
|
|
|
ddns-updates on;
|
|
|
|
ddns-update-style interim;
|
|
|
|
update-static-leases on;
|
|
|
|
|
|
|
|
ddns-domainname "testpdns";
|
|
|
|
ddns-rev-domainname "in-addr.arpa.";
|
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
key "[KEYNAME]" {
|
2022-05-20 21:19:06 +02:00
|
|
|
algorithm hmac-md5;
|
2023-06-02 19:25:19 +02:00
|
|
|
secret "[KEY]";
|
2022-05-20 21:19:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
zone testpdns {
|
|
|
|
primary 127.0.0.1;
|
2023-06-02 19:25:19 +02:00
|
|
|
key [KEYNAME];
|
2022-05-20 21:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
zone 7.168.192.in-addr.arpa. {
|
|
|
|
primary 127.0.0.1;
|
2023-06-02 19:25:19 +02:00
|
|
|
key [KEYNAME];
|
2022-05-20 21:19:06 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Client
|
2022-12-16 11:46:32 +01:00
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
DHCP Request
|
2022-05-20 21:19:06 +02:00
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[shroot]
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
```sh
|
|
|
|
dhclient -v
|
|
|
|
```
|
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[/shroot]
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
Release IP
|
|
|
|
|
2023-06-02 19:25:19 +02:00
|
|
|
[shroot]
|
|
|
|
|
2023-02-19 15:21:41 +01:00
|
|
|
```sh
|
2023-06-02 19:25:19 +02:00
|
|
|
dhclient -v -r
|
2023-02-19 15:21:41 +01:00
|
|
|
```
|
2023-06-02 19:25:19 +02:00
|
|
|
|
|
|
|
[/shroot]
|