User-Profile-Image
hankin
  • 5
  • 关于
  • 分类
    • 路由器
    • 电脑相关
    • 游戏相关
    • 未分类
    • 服务器相关
    • 数据库
  • 页面
    • 关于
  • 友链
    • 华夏网盟
Help?

Please contact us on our email for need any support

Support
  • 关于
    首页   ›   服务器相关   ›   正文
服务器相关

Centos/Debian编译安装Pcap_DNSProxy——DNS防污染利器

2021-02-22 13:44:26
77  0 0

转自:http://www.senra.me/compile-and-install-pcapdnsproxy-for-centos6/

下面为 centos:

1.准备程序编译环境:编译前需要使用包管理工具安装,或者需要自行编译和安装依赖库

  • 依赖工具/库列表:
  • GCC/g++ 可访问 https://gcc.gnu.org 获取
  • GCC 最低版本要求为 4.9 从此版本开始 GCC 完整支持 C++ 11 标准,4.9 之前的版本对 C++ 11 标准的实现有问题
  • GCC 当前版本可使用 gcc –version 查看,使用旧版本 GCC 强行编译可能会出现无法预料的问题!
  • Bison 可访问 https://www.gnu.org/software/bison 获取
  • M4 可访问 https://www.gnu.org/software/m4 获取
  • Flex 可访问 http://flex.sourceforge.net 获取
  • CMake 可访问 https://cmake.org 获取
  • LibPcap 可访问 http://www.tcpdump.org/#latest-release 获取
  • 获得 root 权限后使用 ./configure -> make -> make install 即可
  • 部分 Linux 发行版可能还需要 LibPcap-Dev 工具的支持
  • Libsodium 可访问 https://github.com/jedisct1/libsodium 获取
  • 编译时如果剥离 Libsodium 的依赖则可跳过编译和安装下表的依赖库和工具,具体参见下文的介绍,不建议使用
  • Libsodium 的编译和安装依赖 Automake/Autoconf 套装工具:
  • aclocal
  • autoscan
  • autoconf 可访问 https://www.gnu.org/software/autoconf 获取
  • autoheader
  • automake 可访问 https://www.gnu.org/software/automake 获取
  • libtool 可访问 https://www.gnu.org/software/libtool 获取
  • 获得 root 权限后进入目录,运行 ./autogen.sh -> ./configure -> make -> make install 即可
  • 部分 Linux 发行版可能还需要 Libsodium-Dev 工具的支持
  • 部分 Linux 发行版可能还需要运行 ldconfig 刷新系统的库缓存

下载完毕后到解压目录先后执行 ./configure – make – sudo make install

2.编译 Pcap_DNSProxy 程序并配置程序属性

  • 切勿更改脚本的换行格式 (UNIX/LF)
  • 使用终端进入 Source/Scripts 目录,使用 chmod 755 CMake_Build.sh 使脚本获得执行权限
  • 使用 ./CMake_Build.sh 执行编译程序
  • 添加参数 –enable-static 即 ./CMake_Build.sh –enable-static 可启用静态编译
  • 脚本所进行的操作:
  • CMake 将编译并在 Release 目录生成 Pcap_DNSProxy 程序
  • 设置 Pcap_DNSProxy 程序以及 PcapDNSProxyService 和 Pcap_DNSProxy.service 服务控制脚本的基本读写可执行权限
  • 设置 Linux_(Un)Install.Systemd.sh 以及 Linux_(Un)Install.SysV.sh 服务控制安装脚本的基本读写可执行权限
  • 从 ExampleConfig 复制默认配置文件到 Release 目录
  • 执行时使用 ./CMake_Build.sh –disable-libsodium 可剥离 Libsodium 的依赖,不建议使用
  • 剥离后编译时将不需要 Libsodium 库的支持
  • 剥离后程序将完全失去支持 DNSCurve/DNSCrypt 协议的功能,且运行时将不会产生任何错误提示,慎用!

3.配置系统守护进程服务

  • 由于不同的 Linux 发行版对系统服务和守护进程的处理方式不同,本步仅供参考
  • 附带的 Linux_Install.Systemd.sh 脚本适用于默认使用 Systemd Init 的系统
  • Linux Debian 8.x 官方发行版以及更新版本系统环境,经测试可直接使用
  • 附带的 Linux_Install.SysV.sh 脚本适用于默认使用 System V Init 的系统
  • Linux Debian 6.x – 7.x 官方发行版系统环境,经测试可直接使用
  • 更多详情可参见下文其它 Linux 发行版服务的说明,以及所使用 Linux 发行版的官方说明
  • 使用 Systemd Init 时:
  • 进入 Release 目录并编辑 Pcap_DNSProxy.service 文件,编辑完成后保存:
  • WorkingDirectory= 项为程序所在目录的绝对路径
  • ExecStart= 项为程序所在目录的绝对路径,并在最后加上程序的名称
  • 在 root 权限下使用 ./Linux_Install.Systemd.sh 执行服务安装脚本,脚本所进行的操作:
  • 将 Pcap_DNSProxy.service 服务控制脚本的所有者更改为 root
  • 安装服务控制脚本到 /etc/systemd/system 目录中
  • 尝试启动 Pcap_DNSProxy 服务,并显示执行操作后服务的状态
  • 以后每次系统启动都将自动启动服务
  • 更多 Systemd 服务控制的方法,参见各 Linux 发行版官方文档的说明
  • 使用 System V Init 时:
  • 进入 Release 目录并编辑 PcapDNSProxyService 文件,编辑完成后保存:
  • NAME 项为程序的名称
  • PATH 项为程序的绝对路径
  • 在 root 权限下使用 ./Linux_Install.SysV.sh 执行服务安装脚本,脚本所进行的操作:
  • 将 PcapDNSProxyService 服务控制脚本的所有者更改为 root
  • 安装服务控制脚本到 /etc/init.d 目录中
  • 尝试启动 PcapDNSProxyService 服务,并显示执行操作后服务的状态
  • 以后每次系统启动都将自动运行脚本启动服务
  • 可直接输入 sh PcapDNSProxyService 不带参数查询用法
  • start – 启动服务
  • stop – 停止服务
  • force-reload/restart – 重启服务
  • status – 服务状态,如果 PID 为空则服务未启动

以上为该项目在Github上的说明文档,想要自己研究的可以去这看看:传送门

参照文档,我们首先需要解决的是GCC的问题,参照我之前写的一篇文章,我们选择devtoolset来获取高版本GCC,需要GCC4.9以上那我们就用devtool3

wget https://copr.fedoraproject.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo -O /etc/yum.repos.d/devtools-3.repo
yum install devtoolset-3-gcc devtoolset-3-binutils devtoolset-3-gcc-c++ devtoolset-3-gcc-gfortran
ln -s /opt/rh/devtoolset-3/root/usr/bin/* /usr/local/bin/
hash -r
gcc –version
这里直接将devtoolset的gcc配置为默认gcc了,需要临时配置的可以参照我的文章

然后接下来其实有点套路,我把这些依赖的configure选项全看了下,发现好几个依赖需要m4,所以我最先装m4,当然在此之前我们最好配置下系统动态链接库

echo -e ‘/usr/local/libn/usr/local/lib64’ > /etc/ld.so.conf.d/local.conf
ldconfig
以下我选择的依赖基本是写文章时最新的stable版本(强迫症福利)

安装m4

cd /opt
wget https://ftp.gnu.org/gnu/m4/m4-1.4.17.tar.gz
tar xzf m4-1.4.17.tar.gz
cd m4-1.4.17
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure
make
make install
ldconfig

安装bison

cd /opt
wget https://ftp.gnu.org/gnu/bison/bison-3.0.4.tar.gz
tar xzf bison-3.0.4.tar.gz
cd bison-3.0.4
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure
make
make install
ldconfig

安装autoconf

cd /opt
wget https://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar xzf autoconf-latest.tar.gz
cd au
toconf-*
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure
make
make install

安装automake

cd /opt
wget https://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz
tar xzf automake-1.15.tar.gz
cd automake-1.15
./bootstrap.sh
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure
make
make install

安装libtool

cd /opt
yum install help2man texinfo -y
wget https://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.gz
tar xzf libtool-2.4.6.tar.gz
cd libtool-2.4.6
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure
make
make install

安装libsodium(这玩意貌似不用autogen,直接configure也行,自己看着办)

cd /opt
wget https://github.com/jedisct1/libsodium/releases/download/1.0.11/libsodium-1.0.11.tar.gz
tar zxf libsodium-1.0.11.tar.gz
cd libsodium-1.0.11
./autogen.sh
./configure
make
make install
ldconfig

安装gettext(libsodium的autogen需要gettext,系统自带的版本不够)

yum install patch -y
cd /opt
wget https://ftp.gnu.org/gnu/gettext/gettext-0.19.8.1.tar.gz
tar xzf gettext-0.19.8.1.tar.gz
cd gettext-0.19.8.1
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./configure
make
make install
ldconfig

安装flex

yum install texinfo-tex -y
cd /opt
wget https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
tar xzf flex-2.6.4.tar.gz
cd flex-2.6.4
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig ./autogen.sh
./configure
make
make install
ldconfig

安装cmake

cd /opt
wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz
tar xzf cmake-3.6.2.tar.gz
cd cmake-3.6.2
./bootstrap
gmake
gmake install
ldconfig

安装libpcap

cd /opt
wget http://www.tcpdump.org/release/libpcap-1.7.4.tar.gz
tar xzf libpcap-1.7.4.tar.gz
cd libpcap-1.7.4
./configure –enable-ipv6
make
make install
ldconfig
千辛万苦终于把依赖搞定了,终于到了编译正主的时候了……正主倒是方便,有编译脚本,直接执行就行了,本来想编译成静态的,可惜貌似因为使用的动态库太多了,加了参数就报错……,不过我试了下把编译完的本体直接丢其它机器上,只要libsodium依赖,其它貌似都不用(如果需要其它的可以试试yum装下)

cd /opt
wget -O Pcap_DNSProxy_v0.4.7.0.tar.gz https://github.com/chengr28/Pcap_DNSProxy/archive/v0.4.7.0.tar.gz
tar xzf Pcap_DNSProxy_v0.4.7.0.tar.gz
cd Pcap_DNSProxy-0.4.7.0/Source/Scripts
chmod 755 CMake_Build.sh
./CMake_Build.sh
编译完的本体在Pcap_DNSProxy-0.4.7.0/Source/Release中,里面还有一堆配置文件以及启动脚本,然而启动脚本有点二……

我选择把程序和配置放到/etc/Pcap_DNSProxy文件夹中

mkdir /etc/Pcap_DNSProxy
cp ../Release/Pcap_DNSProxy /etc/Pcap_DNSProxy/
cp ../Release/*.conf /etc/Pcap_DNSProxy/
cp ../Release/*.txt /etc/Pcap_DNSProxy/
cp ../Release/PcapDNSProxyService /etc/init.d/
然后我们就要开始改启动脚本了,作为centos6我们需要的是PcapDNSProxyService,但是里面的start-stop-daemon是debian的玩意,不过也能在centos上安装

rpm -ivh http://down.senra.me/RPM/start-stop-daemon-1.18.2-1.el6.x86_64.rpm

然后编辑/etc/init.d/PcapDNSProxyService

Global settings

NAME=Pcap_DNSProxy
PATH=/etc/Pcap_DNSProxy
PROGRAM=/usr/sbin/start-stop-daemon
START_FLAGS=”–start –background –chuid root –exec”
STOP_FLAGS=”–stop –chuid root –exec”
这里修改的是PATH和PROGRAM,默认的PROGRAM是/sbin/start-stop-daemon,但是我们rpm安装的在/usr/sbin/中,在这个脚本里把配置文件设定为和程序同目录,所以都在PATH中

我另外改了下status部分的判断

status)
echo
/bin/ps -C Pcap_DNSProxy
if [ “$?” = “1” ];then
echo -e “nPcap_DNSProxy is not running.”
else
echo -e “nPcap_DNSProxy is running.”
fi
这样就能直接判定程序是否运行了,而不是要你自己看是否有进程活着……

下面为Debian,Debian下就比较方便了。

先后执行:

sudo apt-get install git build-essential cmake -y

sudo apt-get install -y libsodium-dev libpcap-dev libssl-dev flex bison

然后下载依赖库

LibPcap
LibEvent
Libsodium
编译完毕后直接去编译即可。

评论 (0)

Click here to cancel reply.

欢迎您 游客  

近期文章

  • 用于网速测试的下载测速文件合集
  • docker构建SB镜像
  • pterodactl docker install
  • OpenWRT流量实时监控插件
  • docker部署dify

近期评论

No comments to show.

归档

  • 1 月 2026
  • 8 月 2025
  • 5 月 2025
  • 4 月 2025
  • 3 月 2025
  • 2 月 2025
  • 12 月 2024
  • 4 月 2024
  • 10 月 2023
  • 8 月 2023
  • 4 月 2023
  • 3 月 2023
  • 2 月 2023
  • 10 月 2021
  • 5 月 2021
  • 3 月 2021
  • 2 月 2021

分类

  • 数据库
  • 服务器相关
  • 未分类
  • 游戏相关
  • 电脑相关
  • 路由器
Copyright © 2026
smarty_hankin 主题. Designed by hankin
主页
页面
  • 关于
博主
hkthomas 管理员
136 文章 0 评论 18486 浏览
测试
测试