forked from dunwu/linux-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-dns.sh
More file actions
32 lines (28 loc) · 825 Bytes
/
set-dns.sh
File metadata and controls
32 lines (28 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
###################################################################################
# 在 /etc/resolv.conf 中设置 DNS 服务器
# 在 /etc/hosts 中设置本机域名
# @author: Zhang Peng
###################################################################################
ip='127.0.0.1'
function getDeviceIp() {
ip=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')
}
function setDNSServer() {
echo -e "设置DNS服务器"
cat >> /etc/resolv.conf << EOF
nameserver 114.114.114.114
nameserver 8.8.8.8
EOF
}
function setHosts() {
getDeviceIp
host=`hostname`
cat >> /etc/hosts << EOF
${ip} ${host}
EOF
}
######################################## MAIN ########################################
echo -e "\n>>>>>>>>> 配置系统环境"
setDNSServer
setHosts