自動部署dhcp服務 指令碼

2021-08-29 01:31:58 字數 1747 閱讀 6920

基本的東西都在了,需要用的拿出來組合一下就ok了

#! /bin/bash

yum -y install dhcp

\cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf

read -p "請輸入網段" wd

read -r "請輸入子網掩碼" zwym

sed -i -r "/^subnet/s/((([0-9]|1[0-9]|2[0-4][0-9]|25[0-5])\.)([0-9]|1[0-9]|2[0-4][0-9]|25[0-5]))/$wd/" /etc/dhcpd.conf

sed -i -r "/^subnet/s/((([0-9]|1[0-9]|2[0-4][0-9]|25[0-5])\.)([0-9]|1[0-9]|2[0-4][0-9]|25[0-5]))/$zwym/2" /etc/dhcpd.conf

sed -i '2 a option domain-name-servers 8.8.8.8;' /etc/dhcpd.conf

sed -i '2 a max-lease-time 7200;' /etc/dhcpd.conf

sed -i '2 a default-lease-time 600;' /etc/dhcpd.conf

sed -i '/default gateway/,+24d' /etc/dhcpd.conf

sed -ri '/^subnet/a \\toption routers 192.168.1.254;' /etc/dhcpd.conf

sed -ri '/^subnet/a \\toption subnet-mask 255.255.255.0;' /etc/dhcpd.conf

sed -ri '/^subnet/a \\trange 192.168.1.100 192.168.1.200;' /etc/dhcpd.conf

sed -ri '/^subnet/a \\trange 192.168.1.50 192.168.1.60;' /etc/dhcpd.conf

service dhcpd start

優化sed -i 's/dhcpdargs=/dhcpdargs="eth0"/' /etc/sysconfig/dhcpd 

開啟dhcp 中繼

sed -i '/net.ipv4.ip_forward/s/0/1/' /etc/sysctl.conf 

sysctl -p

echo  "dhcrelayargs=\"eth0\"" >/etc/sysconfig/dhcrelay 

echo  "dhcpservers=\"192.168.1.254\"" >>/etc/sysconfig/dhcrelay 

service dhcrelay start

或者sed -i '/dhcrelayargs=/s/""/"eth0"/' /etc/sysconfig/dhcrelay

sed -i '/dhcpservers=/s/""/"192.168.1.254"/' /etc/sysconfig/dhcrelay

sed -i '/dhcrelayargs=/s/""/"eth0"/'/etc/sysconfig/dhcrelay 

客戶端 檢查

dhclient -d eth0

伺服器檢視dhcp 分配資訊

/var/lib/dhcpd/dhcpd.leases

客戶端檢視 

/var/lib/dhclinet/dhclient.leases

dhcp軟體 DHCP服務部署

dhcp作用 dynamic host configure protocol 自動為客戶機分配ip位址dhcp優點 減少工作量 避免ip衝突 提高位址利用率dhcp相關概念dhcp協議埠是 67 68 可以通過命令 netstat an 檢視 dhcp協議埠 dhcp原理 dhcp租約過程,分為4個...

DHCP服務部署

安裝dhcp軟體包 yum y install dhcp 預設dhcp並沒有配置檔案,複製相應配置檔案 cp usr share doc dhcp server dhcpd.conf.example etc dhcp dhcpd.conf root master cat etc dhcp dhcpd...

自動部署指令碼

author wangyang buildtime 12 06 05 desc 自動部署指令碼 currentdir pwd 判斷命令是否成功執行 isok 依次執行命令 rm rf sessionserver tradecore tradeweb isok deploy.log tar xzvf ...