搭建DHCP中继服务(2)

CentOS 7下搭建DHCP中继服务详解

[root@localhost ~]# ifconfig //查看网卡信息 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //此时无法获取IP地址 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 47 bytes 30451 (29.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 122 bytes 13596 (13.2 KiB) ...//省略部分内容... [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 //进入ens33网卡配置文件 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static //更改dhcp为static配置静态IP地址 DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=2ef6b862-5201-48c5-a450-23b3720ab3a0 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.100.100 //配置IP地址 NETMASK=255.255.255.0 //配置子网掩码 GATEWAY=192.168.100.1 //配置网关 ~ ~ :wq //保存退出 [root@localhost ~]# service network restart //重新启动网络服务 Restarting network (via systemctl): [ 确定 ] [root@localhost ~]# ifconfig //查看网卡信息 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //获取静态IP地址 inet 192.168.100.100 netmask 255.255.255.0 broadcast 192.168.100.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 48 bytes 30694 (29.9 KiB) ...//省略部分内容... [root@localhost ~]# vim /etc/dhcp/dhcpd.conf //进入dhcp服务主配置文件 # # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.example //显示dhcp配置文件模板位置 # see dhcpd.conf(5) man page # ~ ...//省略部分内容... ~ :r /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example //将dhcpd配置文件模板写入主配置文件 //写入的著配置文件: # # dhcpd.conf # # Sample configuration file for ISC dhcpd # # option definitions common to all supported networks... option domain-name "example.org"; option domain-name-servers ns1.example.org, ns2.example.org; default-lease-time 600; max-lease-time 7200; # Use this to enble / disable dynamic dns updates globally. #ddns-update-style none; # If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. #authoritative; # Use this to send dhcp log messages to a different log file (you also # have to hack syslog.conf to complete the redirection). log-facility local7; # No service will be given on this subnet, but declaring it helps the # DHCP server to understand the network topology. subnet 10.152.187.0 netmask 255.255.255.0 { } //主要在此处做出更改 # This is a very basic subnet declaration. subnet 10.254.239.0 netmask 255.255.255.224 { range 10.254.239.10 10.254.239.20; option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org; } //更改后的配置文件信息: ...//省略部分内容... # No service will be given on this subnet, but declaring it helps the # DHCP server to understand the network topology. subnet 192.168.100.0 netmask 255.255.255.0 { //更改IP网段 range 192.168.100.100 192.168.100.200; //可以分配的IP地址范围 option routers 192.168.100.1; //网关信息(注意,每段结束以;结尾) } //注意最后的大括号不可删除,否则服务无法开启 subnet 192.168.10.0 netmask 255.255.255.0 { range 192.168.10.100 192.168.10.200; //添加vlan 10网段的地址分配条目 option routers 192.168.10.1; } subnet 192.168.20.0 netmask 255.255.255.0 { range 192.168.20.100 192.168.20.200; //添加vlan 20网段的地址分配条目 option routers 192.168.20.1; } # This is a very basic subnet declaration. :wq //保存退出 //因为我们这边设置了三个vlan,网段都不相同,所以三个网段都要添加 [root@localhost ~]# systemctl start dhcpd //开启dhcp服务 [root@localhost ~]# systemctl status dhcpd //查看服务是否开启 dhcpd.service - DHCPv4 Server Daemon Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled) Active: active (running) since 三 2019-09-04 22:56:05 CST; 14s ago //服务成功开启 Docs: man:dhcpd(8) man:dhcpd.conf(5) Main PID: 5343 (dhcpd) Status: "Dispatching packets..." CGroup: /system.slice/dhcpd.service └─5343 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhc... 9月 04 22:56:05 localhost.localdomain dhcpd[5343]: No subnet declaration for virbr.... ...//省略部分内容... 9月 04 22:56:05 localhost.localdomain systemd[1]: Started DHCPv4 Server Daemon. Hint: Some lines were ellipsized, use -l to show in full.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/c1942abdb57f2ee93d54a4733e1fd7c6.html