(五)iptables防火墙配置和管理

1.拒绝所有主机ping当前主机

iptables -I INPUT -p icmp -j REJECT

2.本机能够访问别的机器的http服务 但是别的机器无法访问本机

iptables -I INPUT -p tcp --drpot 80 -j REJECT

3.当我们发现有ip恶意攻击我们得时候,我们可以通过对防火墙设定规则来进行控制。所以我们可以添加connlimit模块来实现对最大并发得控制。请写出步骤

使用connlimit扩展模块,可以限制每个IP地址同时链接到server端的链接数量,注意:不用指定IP,其默认就是针对"每个客户端IP",即对单IP的并发连接数限制。
eg:
iptables -I INPUT -p tcp --dport 22 -m connlimit --connlimit-above 2 --connlimit-mask 24 -j REJECT
使用"-m connlimit"指定使用connlimit扩展,使用"--connlimit-above 2"表示限制每个IP的链接数量上限为2,再配合-p tcp --dport 22,即表示限制每个客户端IP的ssh并发链接数量不能高于2。
--connlimit-mask选项,去限制"某类网段"的链接数量,24是掩码,转成点分十进制:255.255.255.0

4.实践题
互联网中的主机:

[root@centos6 ~]$hostname -I
192.168.1.128
[root@centos6 ~]$route -n 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.1.129   0.0.0.0         UG    0      0        0 eth0

防火墙:

[root@centos8 ~]$hostname -I
10.0.0.8 192.168.1.129
[root@centos8 ~]$route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.2        0.0.0.0         UG    100    0        0 eth0
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     101    0        0 eth1
[root@centos8 ~]$cat /proc/sys/net/ipv4/ip_forward
1
# 配置iptables规则
iptables -A FORWARD -s 192.168.1.128 -p tcp --dport 22 -j ACCEPT
iptables -A FORWARD -d 192.168.1.128 -p tcp --sport 22 -j ACCEPT
iptables -A FORWARD -j REJECT

局域网服务器:

[root@centos7 ~]$hostname -I
10.0.0.18
[root@centos7 ~]$route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.8        0.0.0.0         UG    0      0        0 eth0
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 eth0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值