代码改变世界

天行健,君子以自强不息

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

摘要

提供DHCP的服务器,自己必须有固定的IP地址

查看有几个网卡配置

root@gateway:/mnt/data/dns.amihome.cn# cd /etc/netplan
root@gateway:/etc/netplan# ls
00-installer-config-wifi.yaml  00-installer-config.yaml

打开有线网卡的配置:

vi 00-installer-config.yaml

初始内容如下:

# This is the network config written by 'subiquity'
network:
  ethernets:
    eno1:
      dhcp4: true
  version: 2

修改后文件内容如下:

# This is the network config written by 'subiquity'
network:
  ethernets:
    eno1:
      addresses:
        - 192.168.3.250/24
      nameservers:
        addresses: [192.168.3.254]
      routes:
        - to: default
          via: 192.168.3.1
      dhcp4: false
  version: 2

让网卡配置立即生效

sudo netplan apply

2、设置DHCP服务要监听的网卡

/etc/default/isc-dhcp-server

文件原始状态如下:

# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)

# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf

# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid

# Additional options to start dhcpd with.
#       Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#       Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4=""     # 此处添加需要提供DHCP服务的网卡名
INTERFACESv6=""

用ifconfig命令列出网络接口:

ifconfig
……
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.250  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 1111::2222:3333:4444:5555  prefixlen 64  scopeid 0x20<link>
        ether 88:11:22:33:44:55  txqueuelen 1000  (Ethernet)
        RX packets 1101183  bytes 913497277 (913.4 MB)
        RX errors 0  dropped 9  overruns 0  frame 0
        TX packets 608061  bytes 521876661 (521.8 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
……

把“eno1”填到下述地方,然后保存退出。

INTERFACESv4="eno1" 

3、重新启动dhcp服务

systemctl restart isc-dhcp-server

4、查看dhcp服务的状态

systemctl status isc-dhcp-server

5、最简单的dhcp设置

vi /etc/dhcp/dhcpd.conf

加入下述内容:

subnet 192.168.3.0 netmask 255.255.255.0 {
        range 192.168.3.20 192.168.3.150;
        option routers 192.168.3.1;
        option domain-name-servers 192.168.3.254;
}

6、给特定MAC地址的设备固定IP

vi /etc/dhcp/dhcpd.conf

加入下述内容:

host DEV-PC {
        hardware ethernet 11:22:33:44:55:66;
        fixed-address 192.168.3.235;
}

参考文章

自建DHCP服务之isc-dhcp-server

请继续阅读。

posted on 2024-04-06 18:22  终南山人  阅读(68)  评论(0编辑  收藏  举报