isc-dhcp-server
#dhcps
#安装
apt install isc-dhcp-server
#topo
# 创建命名空间
ip netns add ns
#创建veth接口
ip link add ns-veth0 type veth peer name h-veth0
#ns-veth0放入命名空间
ip link set ns-veth0 netns ns
#配置ns的接口
ip -netns ns link set ns-veth0 up
ip -netns ns link set lo up
ip -netns ns addr add 10.1.1.1/32 dev lo
ip -netns ns addr add 192.168.3.1/24 dev ns-veth0
ip -netns ns addr //查看
#配置dhcps
/etc/dhcp/dhcpd.conf
```
subnet 192.168.3.0 netmask 255.255.255.0 {
range 192.168.3.2 192.168.3.254;
option routers 192.168.3.1, 192.168.3.1;
}
```
#配置dhcp启动的接口
/etc/default/isc-dhcp-server
```
INTERFACESv4="ns-veth0"
```
#启动dhcpd服务
chmod 777 /var/lib/dhcp/dhcpd.leases
ip netns exec ns dhcpd -cf /etc/dhcp/dhcpd.conf -lf /var/lib/dhcp/dhcpd.leases
ps -aux | grep dhcp
#配置host的接口
ip link set h-veth0 up
dhclient h-veth0 //获取ip地址
#测试
ip addre show h-veth0
ping 10.1.1.1 -c 3
ping 192.168.3.1 -c 3
ip route
#删除
ip netns add ns
ip link del h-veth0
ISC DHCP 4.4 Manual Pages - dhcpd