centos 7.5 dnsmasq 安装或者 升级版本

1.离线安装

①通过https://pkgs.org/ 下载安装包 dnsmasq-2.76-16.el7_9.1.x86_64.rpm,dnsmasq-2.76-16.el7.x86_64.rpm  

通过 rpm -ivh dnsmasq-2.76-16.el7.x86_64.rpm,rpm -Uvh dnsmasq-2.76-16.el7_9.1.x86_64.rpm, 安装

2.修改配置

 

2.1配置dnsmasq.conf文件

      ①resolv-file:从文件读取 DNSMasq 上游的 DNS 服务器配置

    开启strict-order
      listen-address选项用于设置dnsmasq监听的IP地址。 要使用您的CentOS/RHEL服务器在LAN上侦听DHCPDNS请求,请如图所示将listen-address选项设置为其LAN IP地址(请记住包括127.0.0.1)。 请注意,服务器IP必须是静态的。

listen-address=::1,127.0.0.1,192.168.70.167

④ addn-hosts:从文件读取本地 DNS 域名和 IP 的对应关系

2.2 vim /etc/resolv.conf

  ①配置 

  ②修改 /etc/resolv.conf文件由本地守护程序(尤其是NetworkManager)维护,因此任何用户进行的更改都将被覆盖。 为了防止这种情况,请使用chattr命令通过设置不可变文件属性(禁用对文件的写访问)来对其进行写保护。

# chattr +i /etc/resolv.conf
# lsattr /etc/resolv.conf

 

2.3 vim /etc/hosts.dnsmasq

1
2
3
192.168.56.1  www.taobai.com
192.168.56.2  www.taobai.com
192.168.56.3  www.taobai.com

3.启动

1
2
3
4
5
6
7
① . systemctl daemon-reload
 
②  systemctl enable dnsmasq
 
③  systemctl start dnsmasq
 
④  systemctl status dnsmasq

  

如果正在运行Firewalld服务,则需要在防火墙配置中打开DNSDHCP服务,以允许来自LAN上主机的请求传递到dnsmasq服务器。

1
2
3
# firewall-cmd --add-service=dns --permanent
# firewall-cmd --add-service=dhcp --permanent
# firewall-cmd --reload

4.测试

两台硬件终端通过域名能通

 参考:https://cloud.tencent.com/developer/article/1662602

 

5.升级

5.1 下载

http://www.thekelleys.org.uk/dnsmasq/dnsmasq-2.86.tar.gz  下面下载最新的安装包

 

5.2 解压

 

tar -zxvf dnsmasq-2.86.tar.gz -C /usr/local

 

5.3 编译安装

cd  dnsmasq-2.86
make install

5.4  编辑启动脚本

命令: vim /etc/init.d/dnsmasq

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
#
# Startup script for the <span class='wp_keywordlink_affiliate'><a href="http://itgeeker.net/tag/dns/" title="View all posts in DNS" target="_blank">DNS</a></span> caching server
#
# chkconfig: - 49 50
# description: This script starts your DNS caching server
# processname: dnsmasq
# pidfile: /var/run/dnsmasq
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
dnsmasq=/usr/local/sbin/dnsmasq
[ -f $dnsmasq ] || exit 0
RETVAL=0
# See how we were called.
case "$1" in
start)
if [ $UID -ne 0 ] ; then
echo "User has insufficient privilege."
exit 4
fi
echo -n "Starting dnsmasq: "
daemon $dnsmasq $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dnsmasq
;;
stop)
if test "x`pidof dnsmasq`" != x; then
echo -n "Shutting down dnsmasq: "
killproc dnsmasq
fi
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dnsmasq /var/run/dnsmasq.pid
;;
status)
status dnsmasq
RETVAL=$?
;;
reload)
echo -n "Reloading dnsmasq: "
killproc dnsmasq -HUP
RETVAL=$?
echo
;;
force-reload)
# new configuration takes effect only after restart
$0 stop
$0 start
RETVAL=$?
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
condrestart)
if test "x`/sbin/pidof dnsmasq`" != x; then
$0 stop
$0 start
RETVAL=$?
fi
;;
*)
echo "Usage: $0 {start|stop|restart|reload|condrestart|status}"
exit 2
esac
exit $RETVAL

5.5 赋予执行权限

1
chmod +x /etc/init.d/dnsmasq  

到此如果需要修改配,按照2执行就行。

参照步骤3 启动

6.升级完检查

升级完成之后,find / -name dnsmasq 使用此命令查找

 

完了之后要确定这两个版本号是否一致,不一致的话使用 cp /usr/local/sbin/dnsmasq /usr/sbin/dnsmasq 拷贝,如果配置文件不一致的要拷贝配置

 

 

 

 

6.异常处理

1>.安装的时候可能会出现如下错误,如果没有错误忽略下面的1>,2>。

 

2>解决办法:执行make CFLAGS=-std=c99   gcc 的问题)

 

 

 

 

在执行 试一下就好了

make

make install

 

 

 

升级参考文档 https://www.cnblogs.com/wclwcw/p/8806256.html

 

posted on   朝颜陌  阅读(1460)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示