首页 > 其他分享 >简单配置拨号服务器

简单配置拨号服务器

时间:2022-09-29 10:09:58浏览次数:79  
标签:iptables IP 配置 拨号 linux home 服务器 apf zhangy

防人之心不可无。 网上总有些无聊或者有意的人。不多说了。上干货,配置vps apf防小流量ddos。

对于大流量的ddos, 需要机房的硬件防火墙,vps内部可能也扛不住。

1. 安装 DDoS deflate

DDoS deflate的原理是通过netstat命令找出 发出过量连接的单个IP,并使用iptables防火墙将这些IP进行拒绝。由于iptables防火墙拒绝IP的连接远比从Apache层面上来得高效,因此iptables便成了运行在Apache前端的“过滤器”。同样的,DDoS deflate也可以设置采用APF(高级防火墙)进行IP阻止。

​​wget http:​​​​//www​​​​.inetbase.com​​​​/scripts/ddos/install​​​​.sh​​
​​chmod​​​ ​​+x ​​​​install​​​​.sh​​
​​.​​​​/install​​​​.sh​​
主要功能与配置

1、可以设置IP白名单,在 /usr/local/ddos/ignore.ip.list 中设置即可;

2、主要配置文件位于 /usr/local/ddos/ddos.conf ,打开此文件,根据提示进行简单的编辑即可;

3、DDoS deflate可以在阻止某一IP后,隔一段预置的时候自动对其解封;

4、可以在配置文件中设置多长时间检查一次网络连接情况;

5、当阻止IP后,可以设置Email提醒

简单配置一下

FREQ=1 ​​​​#检测的频率为1分钟 ​​
​​NO_OF_CONNECTIONS=100 ​​​​#当单个IP超过100个连接请求时判定为DDOS​​

​​APF_BAN=1 ​​​​#如果打算使用APF阻止IP,则设置为1(需要预先安装APF);如果使用iptables,则设置为0; ​​

​​KILL=1 ​​​​#是否阻止 ​​

​​EMAIL_TO=​​​​"[email protected]"​​​ ​​#接收邮件 ​​

​​BAN_PERIOD=600 ​​​​#阻止时长,10分钟​​

简单配置拨号服务器_配置文件

2. 安装配置apf。

APF(Advanced Policy Firewall)是 Rf-x Networks 出品的Linux环境下的软件防火墙,被大部分Linux服务器管理员所采用,使用iptables的规则,易于理解及使用。

适合对iptables不是很熟悉的人使用,因为它的安装配置比较简单,但是功能还是非常强大的。

脚本安装:

root@linux:​​​​/home/zhangy​​​​# wget http://www.rfxnetworks.com/downloads/apf-current.tar.gz  ​​
​​root@linux:​​​​/home/zhangy​​​​# tar -xvzf apf-current.tar.gz ​​
​​root@linux:​​​​/home/zhangy​​​​# cd apf-9.7-1 ​​
​​root@linux:​​​​/home/zhangy/apf-9​​​​.7-1​​​​# ./install.sh

ubuntu 可以快速安装:

sudo​​​ ​​aptitude ​​​​install​​​ ​​apf-firewall​​

配置:

​vi​​​ ​​/etc/apf/conf​​​​.apf​​往后翻页,找

# Configure inbound (ingress) accepted services. This is an optional​​
​​# feature; services and customized entries may be made directly to an ip's​​
​​# virtual net file located in the vnet/ directory. Format is comma separated​​
​​# and underscore separator for ranges.​​
​​#​​
​​# Example:​​
​​# IG_TCP_CPORTS="21,22,25,53,80,443,110,143,6000_7000"​​
​​# IG_UDP_CPORTS="20,21,53,123"​​
​​# IG_ICMP_TYPES="3,5,11,0,30,8"​​

​​# Common inbound (ingress) TCP ports​​
​​IG_TCP_CPORTS=​​​​"22"​​

 

默认只有22端口开放。 我们先不管。 访问以下80端口的网站试试。 发现竟然可以访问。 为什么规则没有起作用。

继续查看配置文件。 找啊找。

这一行引起了我的注意:

​# Untrusted Network interface(s); all traffic on defined interface will be​

​# subject to all firewall rules. This should be your internet exposed​

​# interfaces. Only one interface is accepted for each value.​

​IFACE_IN=​​​​"eth0"​

突然想到, 会不会是监听端口的问题。

我们知道, 如果是真实服务器或者是 xen虚拟化的vps, 其网卡是 eth*。  例如:

1


​ifconfig​


简单配置拨号服务器_linux_02

​root@linux:​​​​/home/zhangy​​​​# wget http://www.rfxnetworks.com/downloads/apf-current.tar.gz  ​

​root@linux:​​​​/home/zhangy​​​​# tar -xvzf apf-current.tar.gz  ​

​root@linux:​​​​/home/zhangy​​​​# cd apf-9.7-1  ​

​root@linux:​​​​/home/zhangy/apf-9​​​​.7-1​​​​# ./install.sh​

但是, 我这台vps是openvz虚拟化的。 它的网卡一般是 vnet* 的。 比如:

 

简单配置拨号服务器_配置文件_03

 

于是改上面的配置文件:


​​# Untrusted Network interface(s); all traffic on defined interface will be​​
​​# subject to all firewall rules. This should be your internet exposed​​
​​# interfaces. Only one interface is accepted for each value.​​
​​IFACE_IN=​​​​"venet0"​​

重启 apf:

1


​apf -r​


提示说找不到 ip_tables 模块。

ip_tables

apf(4677): {glob} unable to load iptables module (ip_tables), aborting.

简单配置拨号服务器_重启_04

 

大致意思是说, 在ubuntu中, iptables默认被编译进了内核, 而不是以模块方式运行的。apf默认是使用模块方式调用iptables。 所以要修改apf的配置:

SET_MONOKERN="1"

 

然后重启 apf

然后看到一长串的日志:

简单配置拨号服务器_重启_05

 

看样子是成功了。

试一下, 果然80端口不能访问了。

只有22还在。

 

回到配置文件, 我们把端口开放:

1


​vi​​​ ​​/etc/apf/conf​​​​.apf​


找到:

1

2

3

4

5

6

7

8

9

10

11

12


​# Configure inbound (ingress) accepted services. This is an optional​

​# feature; services and customized entries may be made directly to an ip's​

​# virtual net file located in the vnet/ directory. Format is comma separated​

​# and underscore separator for ranges.​

​#​

​# Example:​

​# IG_TCP_CPORTS="21,22,25,53,80,443,110,143,6000_7000"​

​# IG_UDP_CPORTS="20,21,53,123"​

​# IG_ICMP_TYPES="3,5,11,0,30,8"​

 

​# Common inbound (ingress) TCP ports​

​IG_TCP_CPORTS=​​​​"22,80,443"​


 

保存,重启:  apf –r

 

再访问以下,成功了。

 

最后, 关闭apf的调试模式,正式上线:

找到:

1

2

3

4


​# !!! Do not leave set to (1) !!!​

​# When set to enabled; 5 minute cronjob is set to stop the firewall. Set​

​# this off (0) when firewall is determined to be operating as desired.​

​DEVEL_MODE=​​​​"1"​


 

改成 0:

1

2

3

4


​# !!! Do not leave set to (1) !!!​

​# When set to enabled; 5 minute cronjob is set to stop the firewall. Set​

​# this off (0) when firewall is determined to be operating as desired.​

​DEVEL_MODE=​​​​"0"​


 

标签:iptables,IP,配置,拨号,linux,home,服务器,apf,zhangy
From: https://blog.51cto.com/u_15135810/5721690

相关文章

  • 拨号服务器系统后台性能优化实战
    2019年开始,新东方APP团队启动了长达半年以上的稳定性建设工作,为什么稳定性如此重要?因为随着每年30%以上的高速增长,现有的后端服务完全扛不住日益增多的用户带来的高并发,高可......
  • 拨号服务器性能测试
    性能测试1cpu硬件参数cat/proc/cpuinfo我们可以看到CPU的型号、物理CPU个数(显示0)表示只有1个只有1个物理处理器、CPU核心数(cpucores)等参数,至少我们需要比较商家提供的数......
  • Log4net配置与使用
    Log4net的优点:几乎所有的大型应用都会有自己的用于跟踪调试的API。因为一旦程序被部署以后,就不太可能再利用专门的调试工具了。然而一个管理员可能需要有一套强大的日志系......
  • Nacos配置管理
    回到SpringCloud##四、Nacos配置管理Nacos除了可以做注册中心,同样可以做配置管理来使用。1.1.统一配置管理当微服务部署的实例越来越多,达到数十、数百时,逐个修改微服......
  • apache配置多网站多域名
    把以下虚拟机的配置加在httpd.conf文件末尾即可NameVirtualHost121.9.111.111:80##VirtualHostexample:#AlmostanyApachedirectivemaygointoaVirtualHost......
  • 代码优先Fluent API 配置
    EFCore除了用数据注释DataAnnotation对实体类进行配置之外,还提供了FluentAPI的方式对实体类进行配置。FluentAPI优势:1.能够更好的进行职责分离。实体类只负责......
  • ApplicationDbContext配置
    一、appsetting.json声明连接字符串"ConnectionStrings":{"DefaultConnection":"Server=DESKTOP-DABHN6U\\MSSQLSERVER2014;uid=sa;pwd=Lz38275292;database=SP......
  • mac连接服务器和传输文件
    修改用户密码passwdusrname(说明:需要修改的用户名是usrname)创建用户adduseryongyong(说明:用户名是yongyong)  查看容器ipdockerinspect-f'{{.Name}}-{{.Netw......
  • 【从零开始的Linux服务器管理】为服务器添加新用户
    任务背景这是一个非常常见的任务,当有新的用户要使用服务器,作为服务器管理员,都需要为服务器添加新用户,使新用户能够正常使用服务器的各项资源。需要完成的任务包含两项,一......
  • scala读取配置文件内容
    scala读取配置文件内容方法1:默认加载方式,读取./src/main/resources下文件ConfigFactory.load(f),例子(亲测可用):pom.xml中引入<dependency><groupId>com.......