24.Linux系统下动态网络源部署方法(dhcpd)
1.安装dhcp软件 注意:安装时需要有配置好的yum仓库,关于yum仓库的配置,祥见Linux下系统的软件安装以及yum源配置(yum仓库搭建、yum命令、rpm命令)
[root@servser ~]# yum install dhcp -y
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-27.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
PackageArchVersionRepositorySize
================================================================================
Installing:
dhcpx86_6412:4.2.5-27.el7rhel7.0506 k
Transaction Summary
================================================================================
Install1 Package
Total download size: 506 k
Installed size: 1.4 M
Downloading packages:
dhcp-4.2.5-27.el7.x86_64.rpm| 506 kB00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 12:dhcp-4.2.5-27.el7.x86_641/1
Verifying: 12:dhcp-4.2.5-27.el7.x86_641/1
Installed:
dhcp.x86_64 12:4.2.5-27.el7
Complete!
文章图片
2.配置动态网络 注意:配置防火墙关闭或者将dhcp服务加入防火墙白名单,详见LInux下防火墙的基本管理(查看、火墙伪装、添加防火墙白名单)
[root@servser ~]# systemctl start dhcpd##安装完成后打开dhcpd服务
[root@servser ~]# systemctl status dhcpd.service##可以看到,服务打不开
dhcpd.service - DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service;
disabled)
Active: failed (Result: exit-code) since Mon 2019-02-18 11:52:33 EST;
13s ago
Docs: man:dhcpd(8)
man:dhcpd.conf(5)
Process: 31524 ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid (code=exited, status=1/FAILURE)
Main PID: 31524 (code=exited, status=1/FAILURE)
Feb 18 11:52:33 servser.westos.com dhcpd[31524]: you want, please write a su...n
Feb 18 11:52:33 servser.westos.com dhcpd[31524]: in your dhcpd.conf file for...t
Feb 18 11:52:33 servser.westos.com dhcpd[31524]: to which interface eth0 is ...*
Feb 18 11:52:33 servser.westos.com dhcpd[31524]: Feb 18 11:52:33 servser.westos.com dhcpd[31524]: Feb 18 11:52:33 servser.westos.com dhcpd[31524]: Not configured to listen on...!
Feb 18 11:52:33 servser.westos.com dhcpd[31524]: Feb 18 11:52:33 servser.westos.com dhcpd[31524]: This version of ISC DHCP is...e
Feb 18 11:52:33 servser.westos.com systemd[1]: dhcpd.service: main process e...E
Feb 18 11:52:33 servser.westos.com systemd[1]: Unit dhcpd.service entered fa....
Hint: Some lines were ellipsized, use -l to show in full.
文章图片
[root@servser ~]# vim /etc/dhcp/dhcpd.conf##打开配置文件,发现配置文件为空,需要查看模板
[root@servser ~]# cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#see /usr/share/doc/dhcp*/dhcpd.conf.example
#see dhcpd.conf(5) man page
#
[root@servser ~]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf##复制模板过来
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@servser ~]# vim /etc/dhcp/dhcpd.conf##编辑动态网络配置文件
文章图片
##写入:
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
## option definitions common to all supported networks...
option domain-name "westos.com";
option domain-name-servers 172.25.68.100;
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.# This is a very basic subnet declaration.subnet 172.25.68.0 netmask 255.255.255.0 {
range 172.25.68.101 172.25.68.200;
option routers 172.25.68.100;
}
##其中:
option domain-name "westos.com";
option domain-name-servers 172.25.68.100; |
DNS,配置获取到网络的DNS服务域名和域名服务器的IP |
default-lease-time 600; | 默认租约时间 |
max-lease-time 7200; | 最大租约时间 |
subnet 172.25.68.0 netmask 255.255.255.0 |
子网掩码 |
range 172.25.68.101 172.25.68.200; | 可获取的动态IP范围 |
option routers 172.25.68.100; | 获取到网络的网关 |
eth0: flags=4163
inet 172.25.68.101netmask 255.255.255.0broadcast 172.25.68.255
inet6 fe80::5054:ff:fe00:440bprefixlen 64scopeid 0x20
ether 52:54:00:00:44:0btxqueuelen 1000(Ethernet)
RX packets 370bytes 35553 (34.7 KiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 338bytes 36819 (35.9 KiB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0
eth1: flags=4163
ether 52:54:00:24:53:64txqueuelen 1000(Ethernet)
RX packets 156bytes 10332 (10.0 KiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 0bytes 0 (0.0 B)
TX errors 0dropped 0 overruns 0carrier 0collisions 0
lo: flags=73
inet 127.0.0.1netmask 255.0.0.0
inet6 ::1prefixlen 128scopeid 0x10
looptxqueuelen 0(Local Loopback)
RX packets 275bytes 22000 (21.4 KiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 275bytes 22000 (21.4 KiB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0
[root@dhcp_test ~]# cd /etc/sysconfig/network-scripts/##切换目录
[root@dhcp_test network-scripts]# ls
ifcfg-eth0-1ifdown-pppifup-ethifup-sit
ifcfg-loifdown-routesifup-ipppifup-Team
ifdownifdown-sitifup-ipv6ifup-TeamPort
ifdown-bnepifdown-Teamifup-isdnifup-tunnel
ifdown-ethifdown-TeamPortifup-plipifup-wireless
ifdown-ipppifdown-tunnelifup-plusbinit.ipv6-global
ifdown-ipv6ifupifup-postnetwork-functions
ifdown-isdnifup-aliasesifup-pppnetwork-functions-ipv6
ifdown-postifup-bnepifup-routes
[root@dhcp_test network-scripts]# cp ifcfg-eth0-1 ifcfg-eth1##复制配置文件
[root@dhcp_test network-scripts]# vim ifcfg-eth1##编辑配置文件
##写入
TYPE=Ethernet
BOOTPROTO=dhcp
NAME=eth1
ONBOOT=yes
DEVICE=eth1
[root@dhcp_test network-scripts]# systemctl restart network重启网络服务
[root@dhcp_test network-scripts]# ifconfig
eth0: flags=4163
inet 172.25.68.101netmask 255.255.255.0broadcast 172.25.68.255
inet6 fe80::5054:ff:fe00:440bprefixlen 64scopeid 0x20
ether 52:54:00:00:44:0btxqueuelen 1000(Ethernet)
RX packets 1469bytes 130431 (127.3 KiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 1048bytes 121340 (118.4 KiB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0
eth1: flags=4163
inet 172.25.68.108netmask 255.255.255.0broadcast 172.25.68.255##可以看到eth1成功获得到了动态IP
inet6 fe80::5054:ff:fe24:5364prefixlen 64scopeid 0x20
ether 52:54:00:24:53:64txqueuelen 1000(Ethernet)
RX packets 360bytes 20100 (19.6 KiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 22bytes 3891 (3.7 KiB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0
lo: flags=73
inet 127.0.0.1netmask 255.0.0.0
inet6 ::1prefixlen 128scopeid 0x10
looptxqueuelen 0(Local Loopback)
RX packets 275bytes 22000 (21.4 KiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 275bytes 22000 (21.4 KiB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0
文章图片
文章图片
文章图片
文章图片
##查看日志也可以看到动态IP获取的来源
Feb 18 12:50:43 localhost NetworkManager: DHCPREQUEST on eth1 to 255.255.255.255 port 67 (xid=0x410b580d)
Feb 18 12:50:43 localhost dhclient[4482]: DHCPACK from 172.25.68.100 (xid=0x410b580d)
Feb 18 12:50:43 localhost NetworkManager: DHCPACK from 172.25.68.100 (xid=0x410b580d)
Feb 18 12:50:43 localhost dhclient[4482]: bound to 172.25.68.108 -- renewal in 234 seconds.
Feb 18 12:50:43 localhost NetworkManager: bound to 172.25.68.108 -- renewal in 234 seconds.
Feb 18 12:50:43 localhost NetworkManager[664]:
Feb 18 12:50:43 localhost NetworkManager[664]:
Feb 18 12:50:43 localhost NetworkManager[664]:
Feb 18 12:50:43 localhost NetworkManager[664]:
Feb 18 12:50:43 localhost NetworkManager[664]:
Feb 18 12:50:43 localhost NetworkManager[664]:
Feb 18 12:50:43 localhost NetworkManager[664]:
Feb 18 12:50:43 localhost NetworkManager[664]:
【24.Linux系统下动态网络源部署方法(dhcpd)】
文章图片
推荐阅读
- 开学第一天(下)
- 【故障公告】周五下午的一次突发故障
- 生活随笔|好天气下的意外之喜
- MongoDB,Wondows下免安装版|MongoDB,Wondows下免安装版 (简化版操作)
- 汇讲-勇于突破
- Android中的AES加密-下
- 说的真好
- 放下心中的偶像包袱吧
- 如何在Mac中的文件选择框中打开系统隐藏文件夹
- Linux下面如何查看tomcat已经使用多少线程